@@ -181,10 +181,6 @@ pub(crate) fn shake256_xof(tag: [u8; 8], inputs: &[&[u8]]) -> impl XofReader + u
181181const POSEIDON2_WIDTH : usize = 12 ;
182182/// Rate in field elements (8 → 64 bytes per absorb).
183183const POSEIDON2_RATE : usize = 8 ;
184- /// Bytes per rate block. Retained only because the test-only
185- /// `legacy_hash_arith` cross-check uses it.
186- #[ cfg( test) ]
187- const POSEIDON2_RATE_BYTES : usize = POSEIDON2_RATE * 8 ;
188184
189185/// The shared Poseidon2-Goldilocks-12 permutation, constructed once on first
190186/// use and reused for every H_VC invocation.
@@ -375,91 +371,6 @@ mod tests {
375371 assert_ne ! ( hash_vc_node( & l, & r) , hash_vc_node( & r, & l) ) ;
376372 }
377373
378- /// Hand-rolled replay of the pre-Slice-B `hash(Family::Arith, JV_WHIR, …)`
379- /// sponge framing: length-prefixed input bytes, `10*` padding, rate-8
380- /// absorb, then a single permutation per rate block. Used by the
381- /// cross-check tests below to prove the H_VC switch actually changed
382- /// the absorb pattern; survives the Task-4 removal of `Family::Arith`
383- /// because it inlines the logic.
384- fn legacy_hash_arith ( tag : [ u8 ; 8 ] , inputs : & [ & [ u8 ] ] ) -> [ u8 ; 32 ] {
385- let total = 8 + inputs. iter ( ) . map ( |x| 8 + x. len ( ) ) . sum :: < usize > ( ) ;
386- let mut buf = Vec :: with_capacity ( total) ;
387- buf. extend_from_slice ( & tag) ;
388- for input in inputs {
389- buf. extend_from_slice ( & ( input. len ( ) as u64 ) . to_le_bytes ( ) ) ;
390- buf. extend_from_slice ( input) ;
391- }
392-
393- let padded_len = {
394- let raw = buf. len ( ) + 1 ;
395- if raw. is_multiple_of ( POSEIDON2_RATE_BYTES ) {
396- raw
397- } else {
398- raw + ( POSEIDON2_RATE_BYTES - raw % POSEIDON2_RATE_BYTES )
399- }
400- } ;
401- let mut padded = vec ! [ 0u8 ; padded_len] ;
402- padded[ ..buf. len ( ) ] . copy_from_slice ( & buf) ;
403- padded[ buf. len ( ) ] = 0x01 ;
404-
405- let perm = default_goldilocks_poseidon2_12 ( ) ;
406- let mut state = [ Goldilocks :: ZERO ; POSEIDON2_WIDTH ] ;
407- for chunk in padded. chunks_exact ( POSEIDON2_RATE_BYTES ) {
408- for ( i, elem_bytes) in chunk. chunks_exact ( 8 ) . enumerate ( ) {
409- state[ i] += bytes_to_goldilocks ( elem_bytes) ;
410- }
411- perm. permute_mut ( & mut state) ;
412- }
413-
414- let mut out = [ 0u8 ; 32 ] ;
415- for ( i, elem) in state[ ..4 ] . iter ( ) . enumerate ( ) {
416- out[ i * 8 ..( i + 1 ) * 8 ] . copy_from_slice ( & elem. as_canonical_u64 ( ) . to_le_bytes ( ) ) ;
417- }
418- out
419- }
420-
421- #[ test]
422- fn hash_vc_leaf_differs_from_legacy_sponge ( ) {
423- // Pin the spec/impl invariant: the new H_VC absorb pattern (no len
424- // prefix, no 10* pad, leaf-IV in capacity) MUST produce different
425- // bytes than the legacy hash(Family::Arith, JV_WHIR, &[leaf_buf]).
426- use crate :: field:: Goldilocks4 ;
427- let leaf: Vec < Goldilocks4 > = ( 1u64 ..=4 )
428- . map ( |n| {
429- Goldilocks4 :: new ( [
430- Goldilocks :: new ( n) ,
431- Goldilocks :: new ( n + 100 ) ,
432- Goldilocks :: new ( n + 200 ) ,
433- Goldilocks :: new ( n + 300 ) ,
434- ] )
435- } )
436- . collect ( ) ;
437- let new_out = hash_vc_leaf ( & leaf) ;
438-
439- let mut leaf_buf = Vec :: with_capacity ( leaf. len ( ) * 32 ) ;
440- for s in & leaf {
441- leaf_buf. extend_from_slice ( & s. to_bytes ( ) ) ;
442- }
443- let legacy_out = legacy_hash_arith ( JV_WHIR , & [ & leaf_buf] ) ;
444-
445- assert_ne ! (
446- new_out, legacy_out,
447- "H_VC^leaf must differ from legacy sponge framing"
448- ) ;
449- }
450-
451- #[ test]
452- fn hash_vc_node_differs_from_legacy_sponge ( ) {
453- let left = [ 0x11u8 ; 32 ] ;
454- let right = [ 0x22u8 ; 32 ] ;
455- let new_out = hash_vc_node ( & left, & right) ;
456- let legacy_out = legacy_hash_arith ( JV_WHIR , & [ & left, & right] ) ;
457- assert_ne ! (
458- new_out, legacy_out,
459- "H_VC^node must differ from legacy sponge framing"
460- ) ;
461- }
462-
463374 #[ test]
464375 fn hash_vc_leaf_and_node_are_domain_separated ( ) {
465376 // A 2-G4 leaf has 8 base-field limbs of input, same total absorbed
0 commit comments