Skip to content

Commit b90fe9c

Browse files
Feat/zstd witgen compressed block (#1092)
* reconsolidate messy code on working branch * correct huffman header processing * correct jump table * huffman code direct representation * reserve huffman header decoding * jump table correction * correct jump table type * delimitation of bitstream for accumulation witness * Finish decoding bitstreams * Add lstream decoding witness rows * Add witness rows for huffman bitstream decoding * remove constant from merge * Restore default witness value for correction * Remove decoded from FSE Huffman * correct jump table witness * Modify direct rep * correct fse witness * adjust test * Verify FSE interleaved decoding * tag fix * Remove accuracy log from auxiliary table * Consolidate huffman weights subroutine into one tag * correct size format parsing * add huffman code routine for recovering bitstring * remove imports * Add bitstream decoding test * complete unit test coverage of literal decoding * remove direct representation of huffman code * correct witness generation * Correct witness values * Correct idx incremental block * Correct tag next * Correct tag_idx * Correct tag value accumulator * Correct huffman data byte offset * Correct witness values * Remove import * Correct comments on decoding constants * Introduce tag_rlc * Correct multiplier for tag * Clean up and consolidate working example circuit assignment test * Assignment correction * Add column assignments * Organize constraint blocks * Recover constraints * Recover constraints * Add tag change assignment * Recover constraints * Recover constraints * Recover constraints * Recover constraints * Recover constraints * Recover constraints * Recover constraints * Recover constraints * Recover constraints * Adjust constraint blocks * Reassign comparator * Recover constraints * Recover constraints * Recover constraints * Correct Constraints * Correct constraints * Correct constraints * Annotate test data * Resolve merge issues * Examine constraints * Assign lstream config * Recover constraints * Recover constraints * Recover constraints * Add more bitstream witnesses * Recover constraints * Recover constraints * Remove comments * Correct tag_rlc_acc constraint and assignment * Correct tag_rlc constraints and assignment * Correct tag_rlc constraint and assignments: * Recover constraints * Adjust huffman code idx * Revert "Adjust huffman code idx" This reverts commit d8b5107. * Correct byte delimitation in the test * Recover constraints * Recover constraints * Assign block gadget * Recover constraints * Recover constraints * Recover constraints * Recover constraints * Correct tag value acc again * Recover constraints * Correct decoding constraints * Correct assignment for fcs * Rand power correction * Correct constraints * Correct fcs * Correct block header * Correct tag lookup * Recover constraint * Recover constraint * Recover constraints * Recover constraint * Correct lookup * Correct witness values * Bitstream decoder idx transition fix * Correct FSE processing * Cover fse section in bitstream transition * Correct Value RLC * format * Add FSE decoding * Add more assignments * Complete witness fix * Correct size calculation * Correct bit boundary assignment * Correct FSE counting * Correct FSE transition * Correct accuracy log bit reading * Recover constraints * Recover constraints * Recover constraints * Recover constraints * Assign into bitstream accumulation for spanned * Recover lookups * Construct contained bitstreams * Recdover lookups * Recover lookups * Remove debug flags * Correct n_acc for FSE * LiteralHeader decomposition * Add dummy row * Restore state * FSE initial condition * Remove debug flags * Correct constraint * Assign fse table * Recover lookup * Recover lookup * Recover lookup * Recover lookup * Add comments * Recover constraint * Remove debug flag * assignment to LiteralsHeaderTable * introduce is_nil for bitstream_decoder that is set when no bits are read * todo: debug * Add comment * Remove comment * Correct bit boundaries reconstruction * Adjust constraints * Correct bitstring accumulation constraints * Fix fse table lookup * Add conditions to fix lookups * Remove debug flag * Correct branch assignment * Remove debug flag * Organize constraints * fmt * fmt again * literals header lookup fix * clippy * clippy * clippy * Clippy * clippy * decoded literals table | refactor tables module --------- Co-authored-by: Rohit Narurkar <[email protected]> Co-authored-by: Rohit Narurkar <[email protected]>
1 parent 77c51cf commit b90fe9c

18 files changed

+5657
-2809
lines changed

zkevm-circuits/src/decompression_circuit.rs

+960-538
Large diffs are not rendered by default.

zkevm-circuits/src/decompression_circuit/dev.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use crate::{
1010
},
1111
table::{
1212
decompression::{
13-
BitstringAccumulationTable, FseTable, HuffmanCodesTable, LiteralsHeaderTable,
13+
BitstringAccumulationTable, DecodedLiteralsTable, FseTable, HuffmanCodesTable,
14+
LiteralsHeaderTable,
1415
},
1516
BitwiseOpTable, KeccakTable, Pow2Table, PowOfRandTable, RangeTable,
1617
},
@@ -19,6 +20,7 @@ use crate::{
1920

2021
impl<F: Field> Circuit<F> for DecompressionCircuit<F> {
2122
type Config = (DecompressionCircuitConfig<F>, Challenges);
23+
2224
type FloorPlanner = SimpleFloorPlanner;
2325
#[cfg(feature = "circuit-params")]
2426
type Params = ();
@@ -51,6 +53,8 @@ impl<F: Field> Circuit<F> for DecompressionCircuit<F> {
5153
range16,
5254
range64,
5355
);
56+
let decoded_literals_table =
57+
DecodedLiteralsTable::construct(meta, challenge_exprs.clone(), range256);
5458

5559
let config = DecompressionCircuitConfig::new(
5660
meta,
@@ -60,7 +64,12 @@ impl<F: Field> Circuit<F> for DecompressionCircuit<F> {
6064
huffman_codes_table,
6165
bs_acc_table,
6266
literals_header_table,
67+
decoded_literals_table,
68+
bitwise_op_table,
69+
range4,
6370
range8,
71+
range16,
72+
range64,
6473
range128,
6574
range256,
6675
pow2_table,
@@ -78,6 +87,20 @@ impl<F: Field> Circuit<F> for DecompressionCircuit<F> {
7887
mut layouter: impl Layouter<F>,
7988
) -> Result<(), Error> {
8089
let challenges = &config.1.values(&layouter);
90+
91+
config.0.bitwise_op_table.load(&mut layouter)?;
92+
config.0.range4.load(&mut layouter)?;
93+
config.0.range8.load(&mut layouter)?;
94+
config.0.range16.load(&mut layouter)?;
95+
config.0.range64.load(&mut layouter)?;
96+
config.0.range128.load(&mut layouter)?;
97+
config.0.range256.load(&mut layouter)?;
98+
config.0.tag_rom_table.load(&mut layouter)?;
99+
config.0.pow_rand_table.assign(&mut layouter, challenges)?;
100+
config.0.block_type_rom_table.load(&mut layouter)?;
101+
config.0.pow2_table.load(&mut layouter)?;
102+
config.0.literals_header_rom_table.load(&mut layouter)?;
103+
81104
self.synthesize_sub(&config.0, challenges, &mut layouter)
82105
}
83106
}

zkevm-circuits/src/decompression_circuit/test.rs

+72-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#[test]
22
fn test_basic() {
3-
use halo2_proofs::{dev::MockProver, halo2curves::bn256::Fr};
4-
53
use crate::decompression_circuit::DecompressionCircuit;
4+
use halo2_proofs::{dev::MockProver, halo2curves::bn256::Fr};
65

76
let circuit = DecompressionCircuit::<Fr>::default();
87
let mock_prover = MockProver::run(17, &circuit, vec![]);
@@ -14,3 +13,74 @@ fn test_basic() {
1413

1514
mock_prover.assert_satisfied_par();
1615
}
16+
17+
#[test]
18+
fn test_work_example_decompression() {
19+
use crate::decompression_circuit::DecompressionCircuit;
20+
use halo2_proofs::{dev::MockProver, halo2curves::bn256::Fr};
21+
22+
let compressed: Vec<u8> = vec![
23+
// 0x28, 0xb5, 0x2f, 0xfd, // magic numbers are removed
24+
0x60, // Originally 0x64. unset the checksum bit.
25+
0xae, 0x02, // FrameContentSize
26+
0x0d, 0x11, 0x00, // BlockHeader
27+
0x76, 0x62, 0x5e, // ZstdBlockLiteralsHeader
28+
0x23, 0x30, 0x6f, 0x9b, 0x03, // ZstdBlockFseCode
29+
// ZstdBlockHuffmanCode
30+
0x7d, 0xc7, 0x16, 0x0b, 0xbe, 0xc8, 0xf2, 0xd0, 0x22, 0x4b, 0x6b, 0xbc, 0x54, 0x5d, 0xa9,
31+
0xd4, 0x93, 0xef, 0xc4, 0x54, 0x96, 0xb2, 0xe2, 0xa8, 0xa8, 0x24, 0x1c, 0x54, 0x40, 0x29,
32+
0x01, // ZstdBlockJumpTable
33+
0x55, 0x00, 0x57, 0x00, 0x51, 0x00, // LStream1
34+
0xcc, 0x51, 0x73, 0x3a, 0x85, 0x9e, 0xf7, 0x59, 0xfc, 0xc5, 0xca, 0x6a, 0x7a, 0xd9, 0x82,
35+
0x9c, 0x65, 0xc5, 0x45, 0x92, 0xe3, 0x0d, 0xf3, 0xef, 0x71, 0xee, 0xdc, 0xd5, 0xa2, 0xe3,
36+
0x48, 0xad, 0xa3, 0xbc, 0x41, 0x7a, 0x3c, 0xaa, 0xd6, 0xeb, 0xd0, 0x77, 0xea, 0xdc, 0x5d,
37+
0x41, 0x06, 0x50, 0x1c, 0x49, 0x0f, 0x07, 0x10, 0x05, 0x88, 0x84, 0x94, 0x02, 0xfc, 0x3c,
38+
0xe3, 0x60, 0x25, 0xc0, 0xcb, 0x0c, 0xb8, 0xa9, 0x73, 0xbc, 0x13, 0x77, 0xc6, 0xe2, 0x20,
39+
0xed, 0x17, 0x7b, 0x12, 0xdc, 0x24, 0x5a, 0xdf, 0xb4, 0x21, // LStream2
40+
0x9a, 0xcb, 0x8f, 0xc7, 0x58, 0x54, 0x11, 0xa9, 0xf1, 0x47, 0x82, 0x9b, 0xba, 0x60, 0xb4,
41+
0x92, 0x28, 0x0e, 0xfb, 0x8b, 0x1e, 0x92, 0x23, 0x6a, 0xcf, 0xbf, 0xe5, 0x45, 0xb5, 0x7e,
42+
0xeb, 0x81, 0xf1, 0x78, 0x4b, 0xad, 0x17, 0x4d, 0x81, 0x9f, 0xbc, 0x67, 0xa7, 0x56, 0xee,
43+
0xb4, 0xd9, 0xe1, 0x95, 0x21, 0x66, 0x0c, 0x95, 0x83, 0x27, 0xde, 0xac, 0x37, 0x20, 0x91,
44+
0x22, 0x07, 0x0b, 0x91, 0x86, 0x94, 0x1a, 0x7b, 0xf6, 0x4c, 0xb0, 0xc0, 0xe8, 0x2e, 0x49,
45+
0x65, 0xd6, 0x34, 0x63, 0x0c, 0x88, 0x9b, 0x1c, 0x48, 0xca, 0x2b, 0x34,
46+
// LStream3
47+
0xa9, 0x6b, 0x99, 0x3b, 0xee, 0x13, 0x3b, 0x7c, 0x93, 0x0b, 0xf7, 0x0d, 0x49, 0x69, 0x18,
48+
0x57, 0xbe, 0x3b, 0x64, 0x45, 0x1d, 0x92, 0x63, 0x7f, 0xe8, 0xf9, 0xa1, 0x19, 0x7b, 0x7b,
49+
0x6e, 0xd8, 0xa3, 0x90, 0x23, 0x82, 0xf4, 0xa7, 0xce, 0xc8, 0xf8, 0x90, 0x15, 0xb3, 0x14,
50+
0xf4, 0x40, 0xe7, 0x02, 0x78, 0xd3, 0x17, 0x71, 0x23, 0xb1, 0x19, 0xad, 0x6b, 0x49, 0xae,
51+
0x13, 0xa4, 0x75, 0x38, 0x51, 0x47, 0x89, 0x67, 0xb0, 0x39, 0xb4, 0x53, 0x86, 0xa4, 0xac,
52+
0xaa, 0xa3, 0x34, 0x89, 0xca, 0x2e, // LStream4
53+
0xe9, 0xc1, 0xfe, 0xf2, 0x51, 0xc6, 0x51, 0x73, 0xaa, 0xf7, 0x9d, 0x2d, 0xed, 0xd9, 0xb7,
54+
0x4a, 0xb2, 0xb2, 0x61, 0xe4, 0xef, 0x98, 0xf7, 0xc5, 0xef, 0x51, 0x9b, 0xd8, 0xdc, 0x60,
55+
0x6c, 0x41, 0x76, 0xaf, 0x78, 0x1a, 0x62, 0xb5, 0x4c, 0x1e, 0x21, 0x39, 0x9a, 0x5f, 0xac,
56+
0x9d, 0xe0, 0x62, 0xe8, 0xe9, 0x2f, 0x2f, 0x48, 0x02, 0x8d, 0x53, 0xc8, 0x91, 0xf2, 0x1a,
57+
0xd2, 0x7c, 0x0a, 0x7c, 0x48, 0xbf, 0xda, 0xa9, 0xe3, 0x38, 0xda, 0x34, 0xce, 0x76, 0xa9,
58+
0xda, 0x15, 0x91, 0xde, 0x21, 0xf5, 0x55, // Sequence Section
59+
0x46, 0xa8, 0x21, 0x9d, 0x51, 0xcc, 0x18, 0x42, 0x44, 0x81, 0x8c, 0x94, 0xb4, 0x50, 0x1e,
60+
0x20, 0x42, 0x82, 0x98, 0xc2, 0x3b, 0x10, 0x48, 0xec, 0xa6, 0x39, 0x63, 0x13, 0xa7, 0x01,
61+
0x94, 0x40, 0xff, 0x88, 0x0f, 0x98, 0x07, 0x4a, 0x46, 0x38, 0x05, 0xa9, 0xcb, 0xf6, 0xc8,
62+
0x21, 0x59, 0xaa, 0x38, 0x45, 0xbf, 0x5c, 0xf8, 0x55, 0x9e, 0x9f, 0x04, 0xed, 0xc8, 0x03,
63+
0x42, 0x2a, 0x4b, 0xf6, 0x78, 0x7e, 0x23, 0x67, 0x15, 0xa2, 0x79, 0x29, 0xf4, 0x9b, 0x7e,
64+
0x00, 0xbc, 0x2f, 0x46, 0x96, 0x99, 0xea, 0xf1, 0xee, 0x1c, 0x6e, 0x06, 0x9c, 0xdb, 0xe4,
65+
0x8c, 0xc2, 0x05, 0xf7, 0x54, 0x51, 0x84, 0xc0, 0x33, 0x02, 0x01, 0xb1, 0x8c, 0x80, 0xdc,
66+
0x99, 0x8f, 0xcb, 0x46, 0xff, 0xd1, 0x25, 0xb5, 0xb6, 0x3a, 0xf3, 0x25, 0xbe, 0x85, 0x50,
67+
0x84, 0xf5, 0x86, 0x5a, 0x71, 0xf7, 0xbd, 0xa1, 0x4c, 0x52, 0x4f, 0x20, 0xa3, 0x61, 0x23,
68+
0x77, 0x12, 0xd3, 0xb1, 0x58, 0x75, 0x22, 0x01, 0x12, 0x70, 0xec, 0x14, 0x91, 0xf9, 0x85,
69+
0x61, 0xd5, 0x7e, 0x98, 0x84, 0xc9, 0x76, 0x84, 0xbc, 0xb8, 0xfe, 0x4e, 0x53, 0xa5, 0x06,
70+
0x82, 0x14, 0x95, 0x51,
71+
];
72+
73+
let decompression_circuit = DecompressionCircuit::<Fr> {
74+
compressed_frames: vec![compressed],
75+
_data: Default::default(),
76+
};
77+
78+
let mock_prover = MockProver::run(18, &decompression_circuit, vec![]);
79+
80+
let mock_prover = mock_prover.unwrap();
81+
if let Err(errors) = mock_prover.verify_par() {
82+
log::debug!("errors.len() = {}", errors.len());
83+
}
84+
85+
mock_prover.assert_satisfied_par();
86+
}

0 commit comments

Comments
 (0)