Skip to content

Commit c56bde5

Browse files
authored
Merge pull request #15450 from MinaProtocol/fix/lookup-gate-range-check
Fixup lookup gate with range-check table
2 parents 9d1cd89 + c116e19 commit c56bde5

File tree

5 files changed

+114
-9
lines changed

5 files changed

+114
-9
lines changed

src/lib/crypto/snarky_tests/snarky_tests.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -606,9 +606,9 @@ module Protocol_circuits = struct
606606
Genesis_constants.(Proof_level.Full, Constraint_constants.compiled)
607607

608608
let print_hash print expected digest : unit =
609-
if print then Format.printf "expected:\n%s\n\n" expected ;
610-
Format.printf "obtained:\n%s\n" digest ;
611-
()
609+
if print then (
610+
Format.printf "expected:\n%s\n" expected ;
611+
Format.printf "obtained:\n%s\n" digest )
612612

613613
let blockchain () : unit =
614614
let expected = "0e1896d5c5840089da3304799c01efd8" in
@@ -627,7 +627,7 @@ module Protocol_circuits = struct
627627

628628
let transaction () : unit =
629629
let expected1 = "b8879f677f622a1d86648030701f43e1" in
630-
let expected2 = "c9251dbcc565e8e18d15ca96d7908925" in
630+
let expected2 = "6955d1ff31efa774b69a6b932ce9f165" in
631631
let digest =
632632
Transaction_snark.constraint_system_digests ~constraint_constants ()
633633
in
@@ -643,10 +643,10 @@ module Protocol_circuits = struct
643643
let digest2 = Core.Md5.to_hex hash2 in
644644

645645
let check = String.(digest1 = expected1) in
646-
print_hash check expected1 digest1 ;
646+
print_hash (not check) expected1 digest1 ;
647647
assert check ;
648648
let check = String.(digest2 = expected2) in
649-
print_hash check expected2 digest2 ;
649+
print_hash (not check) expected2 digest2 ;
650650
assert check ;
651651
()
652652

src/lib/pickles/test/optional_custom_gates/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(tests
2-
(names test_fix_domains pickles_test_optional_custom_gates)
2+
(names test_fix_domains pickles_test_optional_custom_gates lookup_range_check)
33
(libraries
44
;; opam libraries
55
alcotest
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
open Core_kernel
2+
open Pickles_types
3+
open Pickles.Impls.Step
4+
5+
let () = Pickles.Backend.Tick.Keypair.set_urs_info []
6+
7+
let () = Pickles.Backend.Tock.Keypair.set_urs_info []
8+
9+
let add_constraint c = assert_ { basic = c; annotation = None }
10+
11+
let add_plonk_constraint c =
12+
add_constraint
13+
(Kimchi_backend_common.Plonk_constraint_system.Plonk_constraint.T c)
14+
15+
let fresh_int i = exists Field.typ ~compute:(fun () -> Field.Constant.of_int i)
16+
17+
let range_check0 () =
18+
add_plonk_constraint
19+
(RangeCheck0
20+
{ v0 = fresh_int 0
21+
; v0p0 = fresh_int 0
22+
; v0p1 = fresh_int 0
23+
; v0p2 = fresh_int 0
24+
; v0p3 = fresh_int 0
25+
; v0p4 = fresh_int 0
26+
; v0p5 = fresh_int 0
27+
; v0c0 = fresh_int 0
28+
; v0c1 = fresh_int 0
29+
; v0c2 = fresh_int 0
30+
; v0c3 = fresh_int 0
31+
; v0c4 = fresh_int 0
32+
; v0c5 = fresh_int 0
33+
; v0c6 = fresh_int 0
34+
; v0c7 = fresh_int 0
35+
; (* Coefficients *)
36+
compact = Field.Constant.zero
37+
} )
38+
39+
let range_check_in_lookup_gate () =
40+
add_plonk_constraint
41+
(Lookup
42+
{ w0 = (* Range check table *) fresh_int 1
43+
; w1 = fresh_int 1
44+
; w2 = fresh_int 0
45+
; w3 = fresh_int 2
46+
; w4 = fresh_int 0
47+
; w5 = fresh_int ((1 lsl 12) - 1)
48+
; w6 = fresh_int 0
49+
} )
50+
51+
let constraint_constants =
52+
{ Snark_keys_header.Constraint_constants.sub_windows_per_window = 0
53+
; ledger_depth = 0
54+
; work_delay = 0
55+
; block_window_duration_ms = 0
56+
; transaction_capacity = Log_2 0
57+
; pending_coinbase_depth = 0
58+
; coinbase_amount = Unsigned.UInt64.of_int 0
59+
; supercharged_coinbase_factor = 0
60+
; account_creation_fee = Unsigned.UInt64.of_int 0
61+
; fork = None
62+
}
63+
64+
let test_range_check_lookup () =
65+
let _tag, _cache_handle, (module Proof), Pickles.Provers.[ prove ] =
66+
Pickles.compile ~public_input:(Pickles.Inductive_rule.Input Typ.unit)
67+
~auxiliary_typ:Typ.unit
68+
~branches:(module Nat.N1)
69+
~max_proofs_verified:(module Nat.N0)
70+
~name:"lookup range-check"
71+
~constraint_constants (* TODO(mrmr1993): This was misguided.. Delete. *)
72+
~choices:(fun ~self:_ ->
73+
[ { identifier = "main"
74+
; prevs = []
75+
; main =
76+
(fun _ ->
77+
range_check0 () ;
78+
range_check_in_lookup_gate () ;
79+
{ previous_proof_statements = []
80+
; public_output = ()
81+
; auxiliary_output = ()
82+
} )
83+
; feature_flags =
84+
Plonk_types.Features.
85+
{ none_bool with range_check0 = true; lookup = true }
86+
}
87+
] )
88+
()
89+
in
90+
let public_input, (), proof =
91+
Async.Thread_safe.block_on_async_exn (fun () -> prove ())
92+
in
93+
Or_error.ok_exn
94+
(Async.Thread_safe.block_on_async_exn (fun () ->
95+
Proof.verify [ (public_input, proof) ] ) )
96+
97+
let () =
98+
let open Alcotest in
99+
run "Test range-check in lookup gate"
100+
[ ( "range check in lookup gate"
101+
, [ ( "prove range-check lookup in lookup gate"
102+
, `Quick
103+
, test_range_check_lookup )
104+
] )
105+
]

src/lib/snarky

0 commit comments

Comments
 (0)