@@ -10,6 +10,7 @@ use circuit_verifier::verify::{CircuitConfig, verify_circuit};
1010use circuits:: blake:: { blake, blake_g_gate, m31_to_u32, triple_xor} ;
1111use circuits:: context:: Var ;
1212use circuits:: eval;
13+ use circuits:: finalize_constants:: finalize_constants;
1314use circuits:: ivalue:: { IValue , qm31_from_u32s} ;
1415use circuits:: ops:: { output, permute} ;
1516use circuits:: { context:: Context , ops:: guess} ;
@@ -21,6 +22,7 @@ use stwo::core::channel::Blake2sM31Channel;
2122use stwo:: core:: channel:: Channel ;
2223use stwo:: core:: fields:: qm31:: QM31 ;
2324use stwo:: core:: pcs:: { CommitmentSchemeVerifier , PcsConfig } ;
25+ use stwo:: core:: vcs:: blake2_hash:: Blake2sHash ;
2426use stwo:: core:: vcs_lifted:: blake2_merkle:: Blake2sM31MerkleChannel ;
2527use stwo:: core:: vcs_lifted:: blake2_merkle:: Blake2sM31MerkleHasher ;
2628// Not a power of 2 so that we can test component padding.
@@ -247,6 +249,7 @@ fn stwo_verify(
247249#[ test]
248250fn test_prove_and_stark_verify_blake_gate_context ( ) {
249251 let mut blake_gate_context = build_blake_gate_context ( ) ;
252+ finalize_constants ( & mut blake_gate_context) ;
250253 blake_gate_context. finalize_guessed_vars ( ) ;
251254 blake_gate_context. validate_circuit ( ) ;
252255
@@ -264,6 +267,7 @@ fn test_prove_and_stark_verify_blake_gate_context() {
264267#[ test]
265268fn test_prove_and_stark_verify_permutation_context ( ) {
266269 let mut permutation_context = build_permutation_context ( ) ;
270+ finalize_constants ( & mut permutation_context) ;
267271 permutation_context. finalize_guessed_vars ( ) ;
268272 permutation_context. validate_circuit ( ) ;
269273
@@ -281,6 +285,7 @@ fn test_prove_and_stark_verify_permutation_context() {
281285#[ test]
282286fn test_prove_and_stark_verify_fibonacci_context ( ) {
283287 let mut fibonacci_context = build_fibonacci_context ( ) ;
288+ finalize_constants ( & mut fibonacci_context) ;
284289 fibonacci_context. finalize_guessed_vars ( ) ;
285290 fibonacci_context. validate_circuit ( ) ;
286291
@@ -298,6 +303,7 @@ fn test_prove_and_stark_verify_fibonacci_context() {
298303#[ test]
299304fn test_prove_and_stark_verify_triple_xor_context ( ) {
300305 let mut triple_xor_context = build_triple_xor_context ( ) ;
306+ finalize_constants ( & mut triple_xor_context) ;
301307 triple_xor_context. finalize_guessed_vars ( ) ;
302308 triple_xor_context. validate_circuit ( ) ;
303309
@@ -315,6 +321,7 @@ fn test_prove_and_stark_verify_triple_xor_context() {
315321#[ test]
316322fn test_prove_and_stark_verify_m31_to_u32_context ( ) {
317323 let mut m31_to_u32_context = build_m31_to_u32_context ( ) ;
324+ finalize_constants ( & mut m31_to_u32_context) ;
318325 m31_to_u32_context. finalize_guessed_vars ( ) ;
319326 m31_to_u32_context. validate_circuit ( ) ;
320327
@@ -332,6 +339,7 @@ fn test_prove_and_stark_verify_m31_to_u32_context() {
332339#[ test]
333340fn test_prove_and_stark_verify_blake_g_gate_context ( ) {
334341 let mut blake_g_gate_context = build_blake_g_gate_context ( ) ;
342+ finalize_constants ( & mut blake_g_gate_context) ;
335343 blake_g_gate_context. finalize_guessed_vars ( ) ;
336344 blake_g_gate_context. validate_circuit ( ) ;
337345
@@ -374,12 +382,10 @@ fn circuit_verify(
374382 verify_circuit ( circuit_config, proof, public_data) . unwrap ( ) ;
375383}
376384
377- const TRIPLE_XOR_CIRCUIT_PREPROCESSED_ROOT : [ u32 ; 8 ] =
378- [ 383878560 , 777803796 , 83194896 , 1011084203 , 160550306 , 637440927 , 339198671 , 1031359971 ] ;
379-
380385#[ test]
381386fn test_prove_and_circuit_verify_triple_xor_context ( ) {
382387 let mut triple_xor_context = build_triple_xor_context ( ) ;
388+ finalize_constants ( & mut triple_xor_context) ;
383389 triple_xor_context. finalize_guessed_vars ( ) ;
384390 triple_xor_context. validate_circuit ( ) ;
385391
@@ -391,15 +397,23 @@ fn test_prove_and_circuit_verify_triple_xor_context() {
391397 PcsConfig :: default ( ) ,
392398 )
393399 . unwrap ( ) ;
394- circuit_verify ( circuit_proof, & preprocessed_circuit, TRIPLE_XOR_CIRCUIT_PREPROCESSED_ROOT ) ;
400+ let preprocessed_root = preprocessed_root_from_proof ( & circuit_proof) ;
401+ expect ! [ "[1171063850, 1111600624, 1633001715, 1807620201, 319861310, 456396523, 1450019685, 1107101120]" ]
402+ . assert_eq ( & format ! ( "{preprocessed_root:?}" ) ) ;
403+ circuit_verify ( circuit_proof, & preprocessed_circuit, preprocessed_root) ;
395404}
396405
397- const FIBONACCI_CIRCUIT_PREPROCESSED_ROOT : [ u32 ; 8 ] =
398- [ 938280935 , 1980664971 , 866203874 , 1147299749 , 1683668505 , 390015812 , 137596665 , 365486364 ] ;
406+ /// Extract the preprocessed-trace Merkle root (`commitments[0]`) from a `CircuitProof` as
407+ /// `[u32; 8]`, matching the layout `HashValue<QM31>` consumes via `From<[u32; 8]>`.
408+ fn preprocessed_root_from_proof ( circuit_proof : & CircuitProof < Blake2sM31MerkleHasher > ) -> [ u32 ; 8 ] {
409+ let hash: Blake2sHash = circuit_proof. stark_proof . proof . commitments [ 0 ] ;
410+ std:: array:: from_fn ( |i| u32:: from_le_bytes ( hash. 0 [ i * 4 ..( i + 1 ) * 4 ] . try_into ( ) . unwrap ( ) ) )
411+ }
399412
400413#[ test]
401414fn test_prove_and_circuit_verify_fibonacci_context ( ) {
402415 let mut fibonacci_context = build_fibonacci_context ( ) ;
416+ finalize_constants ( & mut fibonacci_context) ;
403417 fibonacci_context. finalize_guessed_vars ( ) ;
404418 fibonacci_context. validate_circuit ( ) ;
405419
@@ -411,15 +425,16 @@ fn test_prove_and_circuit_verify_fibonacci_context() {
411425 PcsConfig :: default ( ) ,
412426 )
413427 . unwrap ( ) ;
414- circuit_verify ( circuit_proof, & preprocessed_circuit, FIBONACCI_CIRCUIT_PREPROCESSED_ROOT ) ;
428+ let preprocessed_root = preprocessed_root_from_proof ( & circuit_proof) ;
429+ expect ! [ "[1652958260, 1473705547, 1322148911, 426200657, 1375192488, 2052166177, 2061891994, 1346989032]" ]
430+ . assert_eq ( & format ! ( "{preprocessed_root:?}" ) ) ;
431+ circuit_verify ( circuit_proof, & preprocessed_circuit, preprocessed_root) ;
415432}
416433
417- const M31_TO_U32_CIRCUIT_PREPROCESSED_ROOT : [ u32 ; 8 ] =
418- [ 119960690 , 584326386 , 331600676 , 1678406228 , 411117252 , 2142234173 , 1676458105 , 924266087 ] ;
419-
420434#[ test]
421435fn test_prove_and_circuit_verify_m31_to_u32_context ( ) {
422436 let mut m31_to_u32_context = build_m31_to_u32_context ( ) ;
437+ finalize_constants ( & mut m31_to_u32_context) ;
423438 m31_to_u32_context. finalize_guessed_vars ( ) ;
424439 m31_to_u32_context. validate_circuit ( ) ;
425440
@@ -431,15 +446,18 @@ fn test_prove_and_circuit_verify_m31_to_u32_context() {
431446 PcsConfig :: default ( ) ,
432447 )
433448 . unwrap ( ) ;
434- circuit_verify ( circuit_proof, & preprocessed_circuit, M31_TO_U32_CIRCUIT_PREPROCESSED_ROOT ) ;
449+ let preprocessed_root = preprocessed_root_from_proof ( & circuit_proof) ;
450+ expect ! [
451+ "[938872239, 1375737105, 1191518666, 1663828004, 7943535, 657469305, 191549109, 752041387]"
452+ ]
453+ . assert_eq ( & format ! ( "{preprocessed_root:?}" ) ) ;
454+ circuit_verify ( circuit_proof, & preprocessed_circuit, preprocessed_root) ;
435455}
436456
437- const BLAKE_G_GATE_CIRCUIT_PREPROCESSED_ROOT : [ u32 ; 8 ] =
438- [ 1547637094 , 1628188007 , 1109367239 , 1655363258 , 1038162931 , 368611637 , 1915980358 , 1225437881 ] ;
439-
440457#[ test]
441458fn test_prove_and_circuit_verify_blake_g_gate_context ( ) {
442459 let mut blake_g_gate_context = build_blake_g_gate_context ( ) ;
460+ finalize_constants ( & mut blake_g_gate_context) ;
443461 blake_g_gate_context. finalize_guessed_vars ( ) ;
444462 blake_g_gate_context. validate_circuit ( ) ;
445463
@@ -451,7 +469,10 @@ fn test_prove_and_circuit_verify_blake_g_gate_context() {
451469 PcsConfig :: default ( ) ,
452470 )
453471 . unwrap ( ) ;
454- circuit_verify ( circuit_proof, & preprocessed_circuit, BLAKE_G_GATE_CIRCUIT_PREPROCESSED_ROOT ) ;
472+ let preprocessed_root = preprocessed_root_from_proof ( & circuit_proof) ;
473+ expect ! [ "[1600972583, 323912908, 1627322779, 821304140, 535689503, 707220338, 1484882728, 1361575593]" ]
474+ . assert_eq ( & format ! ( "{preprocessed_root:?}" ) ) ;
475+ circuit_verify ( circuit_proof, & preprocessed_circuit, preprocessed_root) ;
455476}
456477
457478#[ test]
0 commit comments