Skip to content

Commit 73ecbc5

Browse files
authored
Pedersen hash to curve (#99)
* Adds a simplified version of Pedersen hash, following https://research.anoma.net/t/revised-zkvm-strategy/546/27 * Reformats the Juvix sources for the CI to pass
1 parent a2b2a04 commit 73ecbc5

File tree

8 files changed

+55
-40
lines changed

8 files changed

+55
-40
lines changed

Stdlib/Cairo/Pedersen.juvix

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module Stdlib.Cairo.Pedersen;
2+
3+
import Stdlib.Data.Field open using {Field};
4+
import
5+
Stdlib.Cairo.Ec as Ec;
6+
7+
module ConstantPoints;
8+
P0 : Ec.Point :=
9+
Ec.mkPoint
10+
2089986280348253421170679821480865132823066470938446095505822317253594081284
11+
1713931329540660377023406109199410414810705867260802078187082345529207694986;
12+
13+
P1 : Ec.Point :=
14+
Ec.mkPoint
15+
996781205833008774514500082376783249102396023663454813447423147977397232763
16+
1668503676786377725805489344771023921079126552019160156920634619255970485781;
17+
18+
P2 : Ec.Point :=
19+
Ec.mkPoint
20+
2251563274489750535117886426533222435294046428347329203627021249169616184184
21+
1798716007562728905295480679789526322175868328062420237419143593021674992973;
22+
end;
23+
24+
pedersenHashToCurve (x y : Field) : Ec.Point :=
25+
let
26+
open ConstantPoints;
27+
open Ec.Operators;
28+
in P0 + x * P1 + y * P2;

Stdlib/Data/Int/Base.juvix

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ nonNeg : Int -> Bool
2929
--- Subtraction for ;Nat;s.
3030
builtin int-sub-nat
3131
intSubNat (n m : Nat) : Int :=
32-
case sub n m of {
32+
case sub n m of
3333
| zero := ofNat (Nat.sub m n)
34-
| suc k := negSuc k
35-
};
34+
| suc k := negSuc k;
3635

3736
syntax operator + additive;
3837

Stdlib/Data/List.juvix

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,10 @@ ordListI {A} {{Ord A}} : Ord (List A) :=
3232
| nil _ := LT
3333
| _ nil := GT
3434
| (x :: xs) (y :: ys) :=
35-
case Ord.cmp x y of {
35+
case Ord.cmp x y of
3636
| LT := LT
3737
| GT := GT
38-
| EQ := go xs ys
39-
};
38+
| EQ := go xs ys;
4039
in mkOrd go;
4140

4241
instance

Stdlib/Data/List/Base.juvix

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ splitAt {A} : Nat → List A → List A × List A
8787
| zero xs := nil, xs
8888
| (suc zero) (x :: xs) := x :: nil, xs
8989
| (suc m) (x :: xs) :=
90-
case splitAt m xs of {l1, l2 := x :: l1, l2};
90+
case splitAt m xs of l1, l2 := x :: l1, l2;
9191

9292
--- 𝒪(𝓃 + 𝓂). Merges two lists according the given ordering.
9393
terminating
@@ -104,9 +104,8 @@ merge {A} {{Ord A}} : List A → List A → List A
104104
partition {A} (f : A → Bool) : List A → List A × List A
105105
| nil := nil, nil
106106
| (x :: xs) :=
107-
case partition f xs of {
108-
l1, l2 := if (f x) (x :: l1, l2) (l1, x :: l2)
109-
};
107+
case partition f xs of
108+
l1, l2 := if (f x) (x :: l1, l2) (l1, x :: l2);
110109

111110
syntax operator ++ cons;
112111

@@ -204,9 +203,8 @@ quickSort {A} {{Ord A}} : List A → List A :=
204203
| nil := nil
205204
| xs@(_ :: nil) := xs
206205
| (x :: xs) :=
207-
case partition (isGT ∘ Ord.cmp x) xs of {
208-
l1, l2 := go l1 ++ x :: go l2
209-
};
206+
case partition (isGT ∘ Ord.cmp x) xs of
207+
l1, l2 := go l1 ++ x :: go l2;
210208
in go;
211209

212210
--- 𝒪(𝓃) Filters out every ;nothing; from a ;List;.

Stdlib/Data/Product.juvix

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ ordProductI {A B} : {{Ord A}} -> {{Ord B}} -> Ord (A × B)
1818
| {{mkOrd cmp-a}} {{mkOrd cmp-b}} :=
1919
mkOrd
2020
λ {(a1, b1) (a2, b2) :=
21-
case cmp-a a1 a2 of {
21+
case cmp-a a1 a2 of
2222
| LT := LT
2323
| GT := GT
24-
| EQ := cmp-b b1 b2
25-
}};
24+
| EQ := cmp-b b1 b2};
2625

2726
instance
2827
showProductI

Stdlib/Trait/Ord.juvix

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,20 @@ syntax operator <= comparison;
3939
--- Returns ;true; iff the first element is less than or equal to the second.
4040
{-# inline: always #-}
4141
<= {A} {{Ord A}} (x y : A) : Bool :=
42-
case Ord.cmp x y of {
42+
case Ord.cmp x y of
4343
| EQ := true
4444
| LT := true
45-
| GT := false
46-
};
45+
| GT := false;
4746

4847
syntax operator < comparison;
4948

5049
--- Returns ;true; iff the first element is less than the second.
5150
{-# inline: always #-}
5251
< {A} {{Ord A}} (x y : A) : Bool :=
53-
case Ord.cmp x y of {
52+
case Ord.cmp x y of
5453
| EQ := false
5554
| LT := true
56-
| GT := false
57-
};
55+
| GT := false;
5856

5957
syntax operator > comparison;
6058

Stdlib/Trait/Ord/Eq.juvix

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,9 @@ fromOrdToEq {A} {{Ord A}} : Eq.Eq A := Eq.mkEq (==);
1010
syntax operator == comparison;
1111

1212
== {A} {{Ord A}} (x y : A) : Bool :=
13-
case Ord.cmp x y of {
13+
case Ord.cmp x y of
1414
| EQ := true
15-
| _ := false
16-
};
15+
| _ := false;
1716

1817
syntax operator /= comparison;
1918

test/Test.juvix

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,28 @@ prop-tailLengthOneLess : List Int -> Bool
2323

2424
prop-splitAtRecombine : Nat -> List Int -> Bool
2525
| n xs :=
26-
case splitAt n xs of {
27-
lhs, rhs := eqListInt xs (lhs ++ rhs)
28-
};
26+
case splitAt n xs of
27+
lhs, rhs := eqListInt xs (lhs ++ rhs);
2928

3029
prop-splitAtLength : Nat -> List Int -> Bool
3130
| n xs :=
3231
case
3332
splitAt n (xs ++ replicate (sub n (length xs)) (ofNat 0))
34-
of {
33+
of
3534
lhs, rhs :=
36-
length lhs == n && length rhs == sub (length xs) n
37-
};
35+
length lhs == n && length rhs == sub (length xs) n;
3836
-- Make sure the list has length at least n
3937

4038
prop-mergeSumLengths : List Int -> List Int -> Bool
4139
| xs ys := length xs + length ys == length (merge xs ys);
4240

4341
prop-partition : List Int -> (Int -> Bool) -> Bool
4442
| xs p :=
45-
case partition p xs of {
43+
case partition p xs of
4644
lhs, rhs :=
4745
all p lhs
4846
&& not (any p rhs)
49-
&& eqListInt (sortInt xs) (sortInt (lhs ++ rhs))
50-
};
47+
&& eqListInt (sortInt xs) (sortInt (lhs ++ rhs));
5148

5249
prop-distributive : Int -> Int -> (Int -> Int) -> Bool
5350
| a b f := f (a + b) == f a + f b;
@@ -119,15 +116,13 @@ prop-transposeMatrixDimensions : List (List Int) -> Bool
119116
let
120117
txs : List (List Int) := transpose xs;
121118
checkTxsRowXsCol : Bool :=
122-
case xs of {
119+
case xs of
123120
| x :: _ := length txs == length x
124-
| _ := null txs
125-
};
121+
| _ := null txs;
126122
checkXsRowTxsCol : Bool :=
127-
case txs of {
123+
case txs of
128124
| tx :: _ := length xs == length tx
129-
| _ := null xs
130-
};
125+
| _ := null xs;
131126
in checkTxsRowXsCol && checkXsRowTxsCol;
132127

133128
sortTest : String -> (List Int -> List Int) -> QC.Test

0 commit comments

Comments
 (0)