@@ -1044,20 +1044,21 @@ mod test {
10441044 // Test cbor_size_upper_bound() accuracy
10451045 let estimated_size = nonced_verification_data. cbor_size_upper_bound ( ) ;
10461046
1047- // Compare with actual CBOR serialization of the inner VerificationData
1048- let actual_serialized = cbor_serialize ( & verification_data) . unwrap ( ) ;
1049- let actual_size = actual_serialized. len ( ) ;
1050-
1051- // Also test serializing the NoncedVerificationData
1047+ // Compare with actual CBOR serialization of the full NoncedVerificationData
10521048 let actual_nonced_serialized = cbor_serialize ( & nonced_verification_data) . unwrap ( ) ;
10531049 let actual_nonced_size = actual_nonced_serialized. len ( ) ;
10541050
1055- // Verify CBOR encodes binary data efficiently (with serde_bytes fix)
1051+ // Also test the inner VerificationData for additional validation
1052+ let actual_inner_serialized = cbor_serialize ( & verification_data) . unwrap ( ) ;
1053+ let actual_inner_size = actual_inner_serialized. len ( ) ;
1054+
1055+ // Verify CBOR encodes binary data efficiently (with serde_bytes fix), this misses some overhead but the proof is big enough as to not matter
1056+
10561057 let raw_total = verification_data. proof . len ( )
10571058 + verification_data. vm_program_code . as_ref ( ) . unwrap ( ) . len ( )
10581059 + verification_data. pub_input . as_ref ( ) . unwrap ( ) . len ( ) ;
10591060
1060- let cbor_efficiency_ratio = actual_size as f64 / raw_total as f64 ;
1061+ let cbor_efficiency_ratio = actual_inner_size as f64 / raw_total as f64 ;
10611062
10621063 // With serde_bytes, CBOR should be very efficient (close to 1.0x)
10631064 assert ! (
@@ -1066,29 +1067,22 @@ mod test {
10661067 cbor_efficiency_ratio
10671068 ) ;
10681069
1069- // Verify CBOR uses byte strings, not arrays
1070- let proof_cbor = cbor_serialize ( & verification_data. proof ) . unwrap ( ) ;
1071- let first_byte = proof_cbor[ 0 ] ;
1072- let major_type = ( first_byte >> 5 ) & 0x07 ;
1073-
1074- assert_eq ! (
1075- major_type, 2 ,
1076- "Proof should be encoded as CBOR byte string (major type 2), got {}" ,
1077- major_type
1078- ) ;
1070+ // Verify CBOR uses byte strings, not arrays by checking the whole struct efficiency
1071+ // If serde_bytes is working, the struct should be encoded efficiently
1072+ // (Individual Vec<u8> serialization bypasses struct annotations)
10791073
10801074 // The estimation should be an upper bound
10811075 assert ! (
1082- estimated_size >= actual_size ,
1076+ estimated_size >= actual_nonced_size ,
10831077 "cbor_size_upper_bound() should be an upper bound. Estimated: {}, Actual: {}" ,
10841078 estimated_size,
1085- actual_size
1079+ actual_nonced_size
10861080 ) ;
10871081
10881082 // The estimation should also be reasonable (not wildly over-estimated)
1089- let estimation_overhead = estimated_size as f64 / actual_size as f64 ;
1083+ let estimation_overhead = estimated_size as f64 / actual_nonced_size as f64 ;
10901084 assert ! (
1091- estimation_overhead < 2.0 ,
1085+ estimation_overhead < 1.1 ,
10921086 "Estimation should be reasonable, not wildly over-estimated. Overhead: {:.3}x" ,
10931087 estimation_overhead
10941088 ) ;
0 commit comments