Skip to content

Commit

Permalink
ROM Tables (LLC, MLC, MOC) and Bitstring Accumulation Table (#1222)
Browse files Browse the repository at this point in the history
* feat: add ROM tables for fse code to value (sequence section)

* fix: handle probability=0 case (fse)

* todo: prob=-1 case not sure how to handle

* feat: bitstring accumulation table
  • Loading branch information
roynalnaruto authored Apr 22, 2024
1 parent 0022835 commit 6b6f8d3
Show file tree
Hide file tree
Showing 6 changed files with 745 additions and 65 deletions.
26 changes: 23 additions & 3 deletions aggregator/src/aggregation/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ use zkevm_circuits::{
util::Challenges,
};

use crate::aggregation::decoder::witgen::N_BLOCK_HEADER_BYTES;

use self::tables::{LiteralsHeaderTable, RomTagTable};
use self::{
tables::{
BitstringAccumulationTable, LiteralLengthCodes, LiteralsHeaderTable, MatchLengthCodes,
MatchOffsetCodes, RomSequenceCodes, RomTagTable,
},
witgen::N_BLOCK_HEADER_BYTES,
};

#[derive(Clone, Debug)]
pub struct DecoderConfig {
Expand Down Expand Up @@ -63,8 +67,16 @@ pub struct DecoderConfig {
range16: RangeTable<16>,
/// Helper table for decoding the regenerated size from LiteralsHeader.
literals_header_table: LiteralsHeaderTable,
/// Helper table for decoding bitstreams.
bitstring_accumulation_table: BitstringAccumulationTable,
/// ROM table for validating tag transition.
rom_tag_table: RomTagTable,
/// ROM table for Literal Length Codes.
rom_llc_table: RomSequenceCodes<LiteralLengthCodes>,
/// ROM table for Match Length Codes.
rom_mlc_table: RomSequenceCodes<MatchLengthCodes>,
/// ROM table for Match Offset Codes.
rom_moc_table: RomSequenceCodes<MatchOffsetCodes>,
}

#[derive(Clone, Debug)]
Expand Down Expand Up @@ -339,9 +351,13 @@ impl DecoderConfig {
) -> Self {
// Fixed tables
let rom_tag_table = RomTagTable::construct(meta);
let rom_llc_table = RomSequenceCodes::<LiteralLengthCodes>::construct(meta);
let rom_mlc_table = RomSequenceCodes::<MatchLengthCodes>::construct(meta);
let rom_moc_table = RomSequenceCodes::<MatchOffsetCodes>::construct(meta);

// Helper tables
let literals_header_table = LiteralsHeaderTable::configure(meta, range8, range16);
let bitstring_accumulation_table = BitstringAccumulationTable::configure(meta);

// Peripheral configs
let tag_config = TagConfig::configure(meta);
Expand Down Expand Up @@ -372,7 +388,11 @@ impl DecoderConfig {
range8,
range16,
literals_header_table,
bitstring_accumulation_table,
rom_tag_table,
rom_llc_table,
rom_mlc_table,
rom_moc_table,
};

macro_rules! is_tag {
Expand Down
12 changes: 12 additions & 0 deletions aggregator/src/aggregation/decoder/tables.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
/// Since bitstrings to decode can be spanned over more than one byte from the encoded bytes, we
/// construct a table to accumulate the binary values of the byte-unaligned bitstrings for decoding
/// convenience.
mod bitstring_accumulation;
pub use bitstring_accumulation::BitstringAccumulationTable;

/// Decode the regenerated size from the literals header.
mod literals_header;
pub use literals_header::LiteralsHeaderTable;

/// The fixed code to Baseline/NumBits for Literal Length.
mod rom_sequence_codes;
pub use rom_sequence_codes::{
LiteralLengthCodes, MatchLengthCodes, MatchOffsetCodes, RomSequenceCodes,
};

/// Validate the following tag given the tag currently being processed.
mod rom_tag;
pub use rom_tag::RomTagTable;
Loading

0 comments on commit 6b6f8d3

Please sign in to comment.