Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/lib/crypto/snarky_tests/snarky_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -606,9 +606,9 @@ module Protocol_circuits = struct
Genesis_constants.(Proof_level.Full, Constraint_constants.compiled)

let print_hash print expected digest : unit =
if print then Format.printf "expected:\n%s\n\n" expected ;
Format.printf "obtained:\n%s\n" digest ;
()
if print then (
Format.printf "expected:\n%s\n" expected ;
Format.printf "obtained:\n%s\n" digest )

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

let transaction () : unit =
let expected1 = "b8879f677f622a1d86648030701f43e1" in
let expected2 = "c9251dbcc565e8e18d15ca96d7908925" in
let expected2 = "6955d1ff31efa774b69a6b932ce9f165" in
let digest =
Transaction_snark.constraint_system_digests ~constraint_constants ()
in
Expand All @@ -643,10 +643,10 @@ module Protocol_circuits = struct
let digest2 = Core.Md5.to_hex hash2 in

let check = String.(digest1 = expected1) in
print_hash check expected1 digest1 ;
print_hash (not check) expected1 digest1 ;
assert check ;
let check = String.(digest2 = expected2) in
print_hash check expected2 digest2 ;
print_hash (not check) expected2 digest2 ;
assert check ;
()

Expand Down
2 changes: 1 addition & 1 deletion src/lib/pickles/test/optional_custom_gates/dune
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(tests
(names test_fix_domains pickles_test_optional_custom_gates)
(names test_fix_domains pickles_test_optional_custom_gates lookup_range_check)
(libraries
;; opam libraries
alcotest
Expand Down
105 changes: 105 additions & 0 deletions src/lib/pickles/test/optional_custom_gates/lookup_range_check.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
open Core_kernel
open Pickles_types
open Pickles.Impls.Step

let () = Pickles.Backend.Tick.Keypair.set_urs_info []

let () = Pickles.Backend.Tock.Keypair.set_urs_info []

let add_constraint c = assert_ { basic = c; annotation = None }

let add_plonk_constraint c =
add_constraint
(Kimchi_backend_common.Plonk_constraint_system.Plonk_constraint.T c)

let fresh_int i = exists Field.typ ~compute:(fun () -> Field.Constant.of_int i)

let range_check0 () =
add_plonk_constraint
(RangeCheck0
{ v0 = fresh_int 0
; v0p0 = fresh_int 0
; v0p1 = fresh_int 0
; v0p2 = fresh_int 0
; v0p3 = fresh_int 0
; v0p4 = fresh_int 0
; v0p5 = fresh_int 0
; v0c0 = fresh_int 0
; v0c1 = fresh_int 0
; v0c2 = fresh_int 0
; v0c3 = fresh_int 0
; v0c4 = fresh_int 0
; v0c5 = fresh_int 0
; v0c6 = fresh_int 0
; v0c7 = fresh_int 0
; (* Coefficients *)
compact = Field.Constant.zero
} )

let range_check_in_lookup_gate () =
add_plonk_constraint
(Lookup
{ w0 = (* Range check table *) fresh_int 1
; w1 = fresh_int 1
; w2 = fresh_int 0
; w3 = fresh_int 2
; w4 = fresh_int 0
; w5 = fresh_int ((1 lsl 12) - 1)
; w6 = fresh_int 0
} )

let constraint_constants =
{ Snark_keys_header.Constraint_constants.sub_windows_per_window = 0
; ledger_depth = 0
; work_delay = 0
; block_window_duration_ms = 0
; transaction_capacity = Log_2 0
; pending_coinbase_depth = 0
; coinbase_amount = Unsigned.UInt64.of_int 0
; supercharged_coinbase_factor = 0
; account_creation_fee = Unsigned.UInt64.of_int 0
; fork = None
}

let test_range_check_lookup () =
let _tag, _cache_handle, (module Proof), Pickles.Provers.[ prove ] =
Pickles.compile ~public_input:(Pickles.Inductive_rule.Input Typ.unit)
~auxiliary_typ:Typ.unit
~branches:(module Nat.N1)
~max_proofs_verified:(module Nat.N0)
~name:"lookup range-check"
~constraint_constants (* TODO(mrmr1993): This was misguided.. Delete. *)
~choices:(fun ~self:_ ->
[ { identifier = "main"
; prevs = []
; main =
(fun _ ->
range_check0 () ;
range_check_in_lookup_gate () ;
{ previous_proof_statements = []
; public_output = ()
; auxiliary_output = ()
} )
; feature_flags =
Plonk_types.Features.
{ none_bool with range_check0 = true; lookup = true }
}
] )
()
in
let public_input, (), proof =
Async.Thread_safe.block_on_async_exn (fun () -> prove ())
in
Or_error.ok_exn
(Async.Thread_safe.block_on_async_exn (fun () ->
Proof.verify [ (public_input, proof) ] ) )

let () =
let open Alcotest in
run "Test range-check in lookup gate"
[ ( "range check in lookup gate"
, [ ( "prove range-check lookup in lookup gate"
, `Quick
, test_range_check_lookup )
] )
]
2 changes: 1 addition & 1 deletion src/lib/snarky
Submodule snarky updated 0 files