Skip to content

Commit 77c51cf

Browse files
committed
we dont need the is_emit column (replace with different logic)
1 parent 557fd67 commit 77c51cf

File tree

1 file changed

+9
-48
lines changed

1 file changed

+9
-48
lines changed

zkevm-circuits/src/decompression_circuit.rs

+9-48
Original file line numberDiff line numberDiff line change
@@ -284,24 +284,14 @@ impl<F: Field> BitstreamDecoder<F> {
284284
/// Fields related to application of the FSE table.
285285
#[derive(Clone, Debug)]
286286
pub struct FseDecoder {
287-
/// Boolean that is set if a symbol is emitted on this row. When we apply an FSE table to an
288-
/// incoming bitstream, we skip the first leading 0s and a sentinel bits. This can be 8 bits as
289-
/// well, meaning that an entire byte is skipped. After skipping these bits, we read AL number
290-
/// of bits to know our the first state to start from.
291-
///
292-
/// The ``is_emit`` column can never be set on the first row of the HuffmanCode tag, as the
293-
/// first row is either:
294-
/// - 7 leading 0s and a sentinel bit OR
295-
/// - leading 0s, sentinel and reading AL bits to find the first state.
296-
is_emit: Column<Advice>,
297-
/// Number of symbols we have emitted.
298-
num_emitted: Column<Advice>,
299287
/// The FSE state we are at.
300288
state: Column<Advice>,
301289
/// The baseline value at ``state``.
302290
baseline: Column<Advice>,
303291
/// The symbol emitted while transitioning from ``state`` to a new state.
304292
symbol: Column<Advice>,
293+
/// Number of symbols we have emitted.
294+
num_emitted: Column<Advice>,
305295
/// An accumulator that keeps a count of the number of states assigned for each symbol,
306296
/// including the symbol that is decoded on the current row.
307297
n_acc: Column<Advice>,
@@ -486,11 +476,10 @@ impl<F: Field> SubCircuitConfig<F> for DecompressionCircuitConfig<F> {
486476
}
487477
};
488478
let fse_decoder = FseDecoder {
489-
is_emit: meta.advice_column(),
490-
num_emitted: meta.advice_column(),
491479
state: meta.advice_column(),
492480
baseline: meta.advice_column(),
493481
symbol: meta.advice_column(),
482+
num_emitted: meta.advice_column(),
494483
n_acc: meta.advice_column(),
495484
};
496485
let lstream = meta.advice_column();
@@ -2007,19 +1996,6 @@ impl<F: Field> SubCircuitConfig<F> for DecompressionCircuitConfig<F> {
20071996
// the bitstream to find the initial state in the FSE table.
20081997
// - Only from the third row onwards, do we start emitting symbols (weights).
20091998

2010-
cb.require_zero(
2011-
"is_emit == false on the first row",
2012-
meta.query_advice(fse_decoder.is_emit, Rotation::cur()),
2013-
);
2014-
cb.require_zero(
2015-
"is_emit == false on the second row",
2016-
meta.query_advice(fse_decoder.is_emit, Rotation::next()),
2017-
);
2018-
cb.require_equal(
2019-
"is_emit == true from the third row onwards",
2020-
meta.query_advice(fse_decoder.is_emit, Rotation(2)),
2021-
1.expr(),
2022-
);
20231999
cb.require_zero(
20242000
"num_emitted starts at 0 from the second row",
20252001
meta.query_advice(fse_decoder.num_emitted, Rotation::next()),
@@ -2059,24 +2035,6 @@ impl<F: Field> SubCircuitConfig<F> for DecompressionCircuitConfig<F> {
20592035
]))
20602036
},
20612037
);
2062-
meta.create_gate(
2063-
"DecompressionCircuit: ZstdBlockHuffmanCode (other rows)",
2064-
|meta| {
2065-
let mut cb = BaseConstraintBuilder::default();
2066-
2067-
cb.require_boolean(
2068-
"is_emit only transitions from 0 -> 1",
2069-
meta.query_advice(fse_decoder.is_emit, Rotation::cur())
2070-
- meta.query_advice(fse_decoder.is_emit, Rotation::prev()),
2071-
);
2072-
2073-
cb.gate(and::expr([
2074-
meta.query_fixed(q_enable, Rotation::cur()),
2075-
meta.query_advice(tag_gadget.is_huffman_code, Rotation::cur()),
2076-
not::expr(meta.query_advice(tag_gadget.is_tag_change, Rotation::cur())),
2077-
]))
2078-
},
2079-
);
20802038
meta.create_gate(
20812039
"DecompressionCircuit: ZstdBlockHuffmanCode (wherever we emit a symbol)",
20822040
|meta| {
@@ -2103,7 +2061,8 @@ impl<F: Field> SubCircuitConfig<F> for DecompressionCircuitConfig<F> {
21032061
cb.gate(and::expr([
21042062
meta.query_fixed(q_enable, Rotation::cur()),
21052063
meta.query_advice(tag_gadget.is_huffman_code, Rotation::cur()),
2106-
meta.query_advice(fse_decoder.is_emit, Rotation::cur()),
2064+
not::expr(meta.query_advice(tag_gadget.is_tag_change, Rotation::cur())),
2065+
not::expr(meta.query_advice(tag_gadget.is_tag_change, Rotation::prev())),
21072066
]))
21082067
},
21092068
);
@@ -2263,7 +2222,8 @@ impl<F: Field> SubCircuitConfig<F> for DecompressionCircuitConfig<F> {
22632222
let condition = and::expr([
22642223
meta.query_fixed(q_enable, Rotation::cur()),
22652224
meta.query_advice(tag_gadget.is_huffman_code, Rotation::cur()),
2266-
meta.query_advice(fse_decoder.is_emit, Rotation::cur()),
2225+
not::expr(meta.query_advice(tag_gadget.is_tag_change, Rotation::cur())),
2226+
not::expr(meta.query_advice(tag_gadget.is_tag_change, Rotation::prev())),
22672227
]);
22682228
let start = meta.query_advice(bitstream_decoder.bit_index_start, Rotation::cur());
22692229
let end = meta.query_advice(bitstream_decoder.bit_index_end, Rotation::cur());
@@ -2288,7 +2248,8 @@ impl<F: Field> SubCircuitConfig<F> for DecompressionCircuitConfig<F> {
22882248
let condition = and::expr([
22892249
meta.query_fixed(q_enable, Rotation::cur()),
22902250
meta.query_advice(tag_gadget.is_huffman_code, Rotation::cur()),
2291-
meta.query_advice(fse_decoder.is_emit, Rotation::cur()),
2251+
not::expr(meta.query_advice(tag_gadget.is_tag_change, Rotation::cur())),
2252+
not::expr(meta.query_advice(tag_gadget.is_tag_change, Rotation::prev())),
22922253
]);
22932254
[
22942255
meta.query_advice(huffman_tree_config.huffman_tree_idx, Rotation::cur()),

0 commit comments

Comments
 (0)