From 5500e46d3cd59292da1a58b6a997e7d260e67ea2 Mon Sep 17 00:00:00 2001 From: Jonathan Wang <31040440+jonathanpwang@users.noreply.github.com> Date: Mon, 18 Sep 2023 08:33:42 -0700 Subject: [PATCH] rename: (coprocessor,leaf) -> (component,shard) --- hashes/zkevm/src/keccak/README.md | 137 ++++++++++-------- .../{coprocessor => component}/circuit/mod.rs | 2 +- .../leaf.rs => component/circuit/shard.rs} | 34 ++--- .../src/keccak/component/circuit/tests/mod.rs | 1 + .../circuit/tests/shard.rs} | 40 ++--- .../{coprocessor => component}/encode.rs | 4 +- .../{coprocessor => component}/ingestion.rs | 4 +- .../keccak/{coprocessor => component}/mod.rs | 8 +- .../{coprocessor => component}/output.rs | 0 .../{coprocessor => component}/param.rs | 0 .../tests/encode.rs | 4 +- .../{coprocessor => component}/tests/mod.rs | 0 .../tests/output.rs | 2 +- .../keccak/coprocessor/circuit/tests/mod.rs | 2 - hashes/zkevm/src/keccak/mod.rs | 4 +- 15 files changed, 129 insertions(+), 113 deletions(-) rename hashes/zkevm/src/keccak/{coprocessor => component}/circuit/mod.rs (61%) rename hashes/zkevm/src/keccak/{coprocessor/circuit/leaf.rs => component/circuit/shard.rs} (95%) create mode 100644 hashes/zkevm/src/keccak/component/circuit/tests/mod.rs rename hashes/zkevm/src/keccak/{coprocessor/circuit/tests/leaf.rs => component/circuit/tests/shard.rs} (76%) rename hashes/zkevm/src/keccak/{coprocessor => component}/encode.rs (98%) rename hashes/zkevm/src/keccak/{coprocessor => component}/ingestion.rs (94%) rename hashes/zkevm/src/keccak/{coprocessor => component}/mod.rs (50%) rename hashes/zkevm/src/keccak/{coprocessor => component}/output.rs (100%) rename hashes/zkevm/src/keccak/{coprocessor => component}/param.rs (100%) rename hashes/zkevm/src/keccak/{coprocessor => component}/tests/encode.rs (98%) rename hashes/zkevm/src/keccak/{coprocessor => component}/tests/mod.rs (100%) rename hashes/zkevm/src/keccak/{coprocessor => component}/tests/output.rs (99%) delete mode 100644 hashes/zkevm/src/keccak/coprocessor/circuit/tests/mod.rs diff --git a/hashes/zkevm/src/keccak/README.md b/hashes/zkevm/src/keccak/README.md index 4785cae1..527d671f 100644 --- a/hashes/zkevm/src/keccak/README.md +++ b/hashes/zkevm/src/keccak/README.md @@ -1,16 +1,22 @@ # ZKEVM Keccak + ## Vanilla + Keccak circuit in vanilla halo2. This implementation starts from [PSE version](https://github.com/privacy-scaling-explorations/zkevm-circuits/tree/main/zkevm-circuits/src/keccak_circuit), then adopts some changes from [this PR](https://github.com/scroll-tech/zkevm-circuits/pull/216) and later updates in PSE version. The major differences is that this version directly represent raw inputs and Keccak results as witnesses, while the original version only has RLCs(random linear combination) of raw inputs and Keccak results. Because this version doesn't need RLCs, it doesn't have the 2nd phase or use challenge APIs. ### Logical Input/Output -Logically the circuit takes an array of bytes as inputs and Keccak results of these bytes as outputs. + +Logically the circuit takes an array of bytes as inputs and Keccak results of these bytes as outputs. `keccak::vanilla::witness::multi_keccak` generates the witnesses of the ciruit for a given input. + ### Background Knowledge + All these items remain consistent across all versions. -- Keccak process a logical input `keccak_f` by `keccak_f`. + +- Keccak process a logical input `keccak_f` by `keccak_f`. - Each `keccak_f` has `NUM_ROUNDS`(24) rounds. - The number of rows of a round(`rows_per_round`) is configurable. Usually less rows means less wasted cells. - Each `keccak_f` takes `(NUM_ROUNDS + 1) * rows_per_round` rows. The last `rows_per_round` rows could be considered as a virtual round for "squeeze". @@ -21,60 +27,67 @@ All these items remain consistent across all versions. - The first round of the circuit is a dummy round, which doesn't crespond to any input. ### Raw inputs -- In this version, we added column `word_value`/`bytes_left` to represent raw inputs. -- `word_value` is meaningful only at the first row of the first `NUM_WORDS_TO_ABSORB`(17) rounds. + +- In this version, we added column `word_value`/`bytes_left` to represent raw inputs. +- `word_value` is meaningful only at the first row of the first `NUM_WORDS_TO_ABSORB`(17) rounds. - `bytes_left` is meaningful only at the first row of each round. - `word_value` equals to the bytes from the raw input in this round's word in little-endian. - `bytes_left` equals to the number of bytes, which haven't been absorbed from the raw input before this round. - More details could be found in comments. ### Keccak Results + - In this version, we added column `hash_lo`/`hash_hi` to represent Keccak results. - `hash_lo`/`hash_hi` of a logical input could be found at the first row of the virtual round of the last `keccak_f`. - `hash_lo` is the low 128 bits of Keccak results. `hash_hi` is the high 128 bits of Keccak results. ### Example + In this version, we care more about the first row of each round(`offset = x * rows_per_round`). So we only show the first row of each round in the following example. Let's say `rows_per_round = 10` and `inputs = [[], [0x89, 0x88, .., 0x01]]`. The corresponding table is: -| row | input idx | round | word_value | bytes_left | is_final | hash_lo | hash_hi | -|--------------|-------------------|-------|----------------------|------------|----------|---------|---------| -| 0 (dummy) | - | - | - | - | false | - | - | -| 10 | 0 | 1 | `0` | 0 | - | - | - | -| ... | 0 | ... | ... | 0 | - | - | - | -| 170 | 0 | 17 | `0` | 0 | - | - | - | -| 180 | 0 | 18 | - | 0 | - | - | - | -| ... | 0 | ... | ... | 0 | - | - | - | -| 250 (squeeze) | 0 | 25 | - | 0 | true | RESULT | RESULT | -| 260 | 1 | 1 | `0x8283848586878889` | 137 | - | - | - | -| 270 | 1 | 2 | `0x7A7B7C7D7E7F8081` | 129 | - | - | - | -| ... | 1 | ... | ... | ... | - | - | - | -| 420 | 1 | 17 | `0x0203040506070809` | 9 | - | - | - | -| 430 | 1 | 18 | - | 1 | - | - | - | -| ... | 1 | ... | ... | 0 | - | - | - | -| 500 (squeeze) | 1 | 25 | - | 0 | false | - | - | -| 510 | 1 | 1 | `0x01` | 1 | - | - | - | -| 520 | 1 | 2 | - | 0 | - | - | - | -| ... | 1 | ... | ... | 0 | - | - | - | -| 750 (squeeze) | 1 | 25 | - | 0 | true | RESULT | RESULT | +| row | input idx | round | word_value | bytes_left | is_final | hash_lo | hash_hi | +| ------------- | --------- | ----- | -------------------- | ---------- | -------- | ------- | ------- | +| 0 (dummy) | - | - | - | - | false | - | - | +| 10 | 0 | 1 | `0` | 0 | - | - | - | +| ... | 0 | ... | ... | 0 | - | - | - | +| 170 | 0 | 17 | `0` | 0 | - | - | - | +| 180 | 0 | 18 | - | 0 | - | - | - | +| ... | 0 | ... | ... | 0 | - | - | - | +| 250 (squeeze) | 0 | 25 | - | 0 | true | RESULT | RESULT | +| 260 | 1 | 1 | `0x8283848586878889` | 137 | - | - | - | +| 270 | 1 | 2 | `0x7A7B7C7D7E7F8081` | 129 | - | - | - | +| ... | 1 | ... | ... | ... | - | - | - | +| 420 | 1 | 17 | `0x0203040506070809` | 9 | - | - | - | +| 430 | 1 | 18 | - | 1 | - | - | - | +| ... | 1 | ... | ... | 0 | - | - | - | +| 500 (squeeze) | 1 | 25 | - | 0 | false | - | - | +| 510 | 1 | 1 | `0x01` | 1 | - | - | - | +| 520 | 1 | 2 | - | 0 | - | - | - | +| ... | 1 | ... | ... | 0 | - | - | - | +| 750 (squeeze) | 1 | 25 | - | 0 | true | RESULT | RESULT | ### Change Details + - Removed column `input_rlc`/`input_len` and related gates. - Removed column `output_rlc` and related gates. - Removed challenges. - Refactored the folder structure to follow [Scroll's repo](https://github.com/scroll-tech/zkevm-circuits/tree/95f82762cfec46140d6866c34a420ee1fc1e27c7/zkevm-circuits/src/keccak_circuit). `mod.rs` and `witness.rs` could be found [here](https://github.com/scroll-tech/zkevm-circuits/blob/develop/zkevm-circuits/src/keccak_circuit.rs). `KeccakTable` could be found [here](https://github.com/scroll-tech/zkevm-circuits/blob/95f82762cfec46140d6866c34a420ee1fc1e27c7/zkevm-circuits/src/table.rs#L1308). -- Imported utilites from [PSE zkevm-circuits repo](https://github.com/privacy-scaling-explorations/zkevm-circuits/blob/588b8b8c55bf639fc5cbf7eae575da922ea7f1fd/zkevm-circuits/src/util/word.rs). +- Imported utilites from [PSE zkevm-circuits repo](https://github.com/privacy-scaling-explorations/zkevm-circuits/blob/588b8b8c55bf639fc5cbf7eae575da922ea7f1fd/zkevm-circuits/src/util/word.rs). + +## Component -## Coprocessor -Keccak coprocessor circuits and utilities based on halo2-lib. +Keccak component circuits and utilities based on halo2-lib. ### Motivation -Move expensive Keccak computation into standalone circuits(**Coprocessor Circuits**) and circuits with actual business logic(**App Circuits**) can read Keccak results from coprocessor circuits. Then we achieve better scalability - the maximum size of a single circuit could be managed and coprocessor/app circuits could be proved in paralle. + +Move expensive Keccak computation into standalone circuits(**Component Circuits**) and circuits with actual business logic(**App Circuits**) can read Keccak results from component circuits. Then we achieve better scalability - the maximum size of a single circuit could be managed and component/app circuits could be proved in paralle. ### Output -Logically a coprocessor circuit outputs 3 columns `lookup_key`, `hash_lo`, `hash_hi` with `capacity` rows, where `capacity` is a configurable parameter and it means the maximum number of keccak_f this circuit can perform. -- `lookup_key` can be cheaply derived from a bytes input. Specs can be found at `keccak::coprocessor::encode::encode_native_input`. Also `keccak::coprocessor::encode` provides some utilities to encode bytes inputs in halo2-lib. +Logically a component circuit outputs 3 columns `lookup_key`, `hash_lo`, `hash_hi` with `capacity` rows, where `capacity` is a configurable parameter and it means the maximum number of keccak_f this circuit can perform. + +- `lookup_key` can be cheaply derived from a bytes input. Specs can be found at `keccak::component::encode::encode_native_input`. Also `keccak::component::encode` provides some utilities to encode bytes inputs in halo2-lib. - `hash_lo`/`hash_hi` are low/high 128 bits of the corresponding Keccak result. There 2 ways to publish circuit outputs: @@ -82,46 +95,50 @@ There 2 ways to publish circuit outputs: - Publish all these 3 columns as 3 public instance columns. - Publish the commitment of all these 3 columns as a single public instance. -Developers can choose either way according to their needs. Specs of these 2 ways can be found at `keccak::coprocessor::circuit::leaf::KeccakCoprocessorLeafCircuit::publish_outputs`. +Developers can choose either way according to their needs. Specs of these 2 ways can be found at `keccak::component::circuit::shard::KeccakComponentShardCircuit::publish_outputs`. -`keccak::coprocessor::output` provides utilities to compute coprocessor circuit outputs for given inputs. App circuits could use these utilities to load Keccak results before witness generation of coprocessor circuits. +`keccak::component::output` provides utilities to compute component circuit outputs for given inputs. App circuits could use these utilities to load Keccak results before witness generation of component circuits. ### Lookup Key Encode -For easier understanding specs at `keccak::coprocessor::encode::encode_native_input`, here we provide an example of encoding `[0x89, 0x88, .., 0x01]`(137 bytes): + +For easier understanding specs at `keccak::component::encode::encode_native_input`, here we provide an example of encoding `[0x89, 0x88, .., 0x01]`(137 bytes): | keccak_f| round | word | witness | Note | |---------|-------|------|---------| ---- | -| 0 | 1 | `0x8283848586878889` | - | | -| 0 | 2 | `0x7A7B7C7D7E7F8081` | `0x7A7B7C7D7E7F808182838485868788890000000000000089` | [length, word[0], word[1]] | -| 0 | 3 | `0x7273747576777879` | - | | -| 0 | 4 | `0x6A6B6C6D6E6F7071` | - | | -| 0 | 5 | `0x6263646566676869` | `0x62636465666768696A6B6C6D6E6F70717273747576777879` | [word[2], word[3], word[4]] | -| ... | ... | ... | ... | ... | -| 0 | 15 | `0x1213141516171819` | - | | -| 0 | 16 | `0x0A0B0C0D0E0F1011` | - | | -| 0 | 17 | `0x0203040506070809` | `0x02030405060708090A0B0C0D0E0F10111213141516171819` | [word[15], word[16], word[17]] | -| 1 | 1 | `0x0000000000000001` | - | | -| 1 | 2 | `0x0000000000000000` | `0x000000000000000000000000000000010000000000000000` | [0, word[0], word[1]] | -| 1 | 3 | `0x0000000000000000` | - | | -| 1 | 4 | `0x0000000000000000` | - | | -| 1 | 5 | `0x0000000000000000` | `0x000000000000000000000000000000000000000000000000` | [word[2], word[3], word[4]] | -| ... | ... | ... | ... | ... | -| 1 | 15 | `0x0000000000000000` | - | | -| 1 | 16 | `0x0000000000000000` | - | | -| 1 | 17 | `0x0000000000000000` | `0x000000000000000000000000000000000000000000000000` | [word[15], word[16], word[17]] | +| 0 | 1 | `0x8283848586878889` | - | | +| 0 | 2 | `0x7A7B7C7D7E7F8081` | `0x7A7B7C7D7E7F808182838485868788890000000000000089` | [length, word[0], word[1]] | +| 0 | 3 | `0x7273747576777879` | - | | +| 0 | 4 | `0x6A6B6C6D6E6F7071` | - | | +| 0 | 5 | `0x6263646566676869` | `0x62636465666768696A6B6C6D6E6F70717273747576777879` | [word[2], word[3], word[4]] | +| ... | ... | ... | ... | ... | +| 0 | 15 | `0x1213141516171819` | - | | +| 0 | 16 | `0x0A0B0C0D0E0F1011` | - | | +| 0 | 17 | `0x0203040506070809` | `0x02030405060708090A0B0C0D0E0F10111213141516171819` | [word[15], word[16], word[17]] | +| 1 | 1 | `0x0000000000000001` | - | | +| 1 | 2 | `0x0000000000000000` | `0x000000000000000000000000000000010000000000000000` | [0, word[0], word[1]] | +| 1 | 3 | `0x0000000000000000` | - | | +| 1 | 4 | `0x0000000000000000` | - | | +| 1 | 5 | `0x0000000000000000` | `0x000000000000000000000000000000000000000000000000` | [word[2], word[3], word[4]] | +| ... | ... | ... | ... | ... | +| 1 | 15 | `0x0000000000000000` | - | | +| 1 | 16 | `0x0000000000000000` | - | | +| 1 | 17 | `0x0000000000000000` | `0x000000000000000000000000000000000000000000000000` | [word[15], word[16], word[17]] | The raw input is transformed into `payload = [0x7A7B7C7D7E7F808182838485868788890000000000000089, 0x62636465666768696A6B6C6D6E6F70717273747576777879, ... , 0x02030405060708090A0B0C0D0E0F10111213141516171819, 0x000000000000000000000000000000010000000000000000, 0x000000000000000000000000000000000000000000000000, ... , 0x000000000000000000000000000000000000000000000000]`. 2 keccak_fs, 6 witnesses each keecak_f, 12 witnesses in total. Finally the lookup key will be `Poseidon(payload)`. -### Leaf Circuit -Implementation: `keccak::coprocessor::circuit::leaf::KeccakCoprocessorLeafCircuit` -- Leaf circuits are the circuits that actually perform Keccak computation. -- Logically leaf circuits take an array of bytes as inputs. -- Leaf circuits follow the coprocessor output format above. -- Leaf circuits have a configurable parameter `capacity`, which is the maximum number of keccak_f this circuit can perform. -- Leaf circuits' outputs have Keccak results of all logical inputs. Outputs are padded into `capacity` rows with Keccak results of "". Paddings might be inserted between Keccak results of logical inputs. +### Shard Circuit + +Implementation: `keccak::component::circuit::shard::KeccakComponentShardCircuit` + +- Shard circuits are the circuits that actually perform Keccak computation. +- Logically shard circuits take an array of bytes as inputs. +- Shard circuits follow the component output format above. +- Shard circuits have a configurable parameter `capacity`, which is the maximum number of keccak_f this circuit can perform. +- Shard circuits' outputs have Keccak results of all logical inputs. Outputs are padded into `capacity` rows with Keccak results of "". Paddings might be inserted between Keccak results of logical inputs. ### Aggregation Circuit -Aggregation circuits aggregate Keccak results of leaf circuits and smaller aggregation circuits. Aggregation circuits can bring better scalability. -Implementation is TODO. \ No newline at end of file +Aggregation circuits aggregate Keccak results of shard circuits and smaller aggregation circuits. Aggregation circuits can bring better scalability. + +Implementation is TODO. diff --git a/hashes/zkevm/src/keccak/coprocessor/circuit/mod.rs b/hashes/zkevm/src/keccak/component/circuit/mod.rs similarity index 61% rename from hashes/zkevm/src/keccak/coprocessor/circuit/mod.rs rename to hashes/zkevm/src/keccak/component/circuit/mod.rs index 6a66fc13..27f33642 100644 --- a/hashes/zkevm/src/keccak/coprocessor/circuit/mod.rs +++ b/hashes/zkevm/src/keccak/component/circuit/mod.rs @@ -1,3 +1,3 @@ -pub mod leaf; +pub mod shard; #[cfg(test)] mod tests; diff --git a/hashes/zkevm/src/keccak/coprocessor/circuit/leaf.rs b/hashes/zkevm/src/keccak/component/circuit/shard.rs similarity index 95% rename from hashes/zkevm/src/keccak/coprocessor/circuit/leaf.rs rename to hashes/zkevm/src/keccak/component/circuit/shard.rs index 7d310382..f818f4d6 100644 --- a/hashes/zkevm/src/keccak/coprocessor/circuit/leaf.rs +++ b/hashes/zkevm/src/keccak/component/circuit/shard.rs @@ -2,7 +2,7 @@ use std::cell::RefCell; use crate::{ keccak::{ - coprocessor::{ + component::{ encode::{ get_words_to_witness_multipliers, num_poseidon_absorb_per_keccak_f, num_word_per_witness, @@ -38,23 +38,23 @@ use halo2_base::{ }; use itertools::Itertools; -/// Keccak Coprocessor Leaf Circuit +/// Keccak Component Shard Circuit #[derive(Getters)] -pub struct KeccakCoprocessorLeafCircuit { +pub struct KeccakComponentShardCircuit { inputs: Vec>, /// Parameters of this circuit. The same parameters always construct the same circuit. #[getset(get = "pub")] - params: KeccakCoprocessorLeafCircuitParams, + params: KeccakComponentShardCircuitParams, base_circuit_builder: RefCell>, hasher: RefCell>, gate_chip: GateChip, } -/// Parameters of KeccakCoprocessorLeafCircuit. +/// Parameters of KeccakComponentCircuit. #[derive(Default, Clone, CopyGetters)] -pub struct KeccakCoprocessorLeafCircuitParams { +pub struct KeccakComponentShardCircuitParams { /// This circuit has 2^k rows. #[getset(get_copy = "pub")] k: usize, @@ -74,8 +74,8 @@ pub struct KeccakCoprocessorLeafCircuitParams { pub base_circuit_params: BaseCircuitParams, } -impl KeccakCoprocessorLeafCircuitParams { - /// Create a new KeccakCoprocessorLeafCircuitParams. +impl KeccakComponentShardCircuitParams { + /// Create a new KeccakComponentShardCircuitParams. pub fn new( k: usize, num_unusable_row: usize, @@ -109,17 +109,17 @@ impl KeccakCoprocessorLeafCircuitParams { } } -/// Circuit::Config for Keccak Coprocessor Leaf Circuit. +/// Circuit::Config for Keccak Component Shard Circuit. #[derive(Clone)] -pub struct KeccakCoprocessorLeafConfig { +pub struct KeccakComponentShardConfig { pub base_circuit_config: BaseConfig, pub keccak_circuit_config: KeccakCircuitConfig, } -impl Circuit for KeccakCoprocessorLeafCircuit { - type Config = KeccakCoprocessorLeafConfig; +impl Circuit for KeccakComponentShardCircuit { + type Config = KeccakComponentShardConfig; type FloorPlanner = SimpleFloorPlanner; - type Params = KeccakCoprocessorLeafCircuitParams; + type Params = KeccakComponentShardCircuitParams; fn params(&self) -> Self::Params { self.params.clone() @@ -212,11 +212,11 @@ impl LoadedKeccakF { } } -impl KeccakCoprocessorLeafCircuit { - /// Create a new KeccakCoprocessorLeafCircuit. +impl KeccakComponentShardCircuit { + /// Create a new KeccakComponentShardCircuit. pub fn new( inputs: Vec>, - params: KeccakCoprocessorLeafCircuitParams, + params: KeccakComponentShardCircuitParams, witness_gen_only: bool, ) -> Self { let input_size = inputs.iter().map(|input| get_num_keccak_f(input.len())).sum::(); @@ -250,7 +250,7 @@ impl KeccakCoprocessorLeafCircuit { /// Simulate witness generation of the base circuit to determine BaseCircuitParams because the number of columns /// of the base circuit can only be known after witness generation. pub fn calculate_base_circuit_params( - params: &KeccakCoprocessorLeafCircuitParams, + params: &KeccakComponentShardCircuitParams, ) -> BaseCircuitParams { // Create a simulation circuit to calculate base circuit parameters. let simulation_circuit = Self::new(vec![], params.clone(), false); diff --git a/hashes/zkevm/src/keccak/component/circuit/tests/mod.rs b/hashes/zkevm/src/keccak/component/circuit/tests/mod.rs new file mode 100644 index 00000000..c77c1a0c --- /dev/null +++ b/hashes/zkevm/src/keccak/component/circuit/tests/mod.rs @@ -0,0 +1 @@ +pub mod shard; diff --git a/hashes/zkevm/src/keccak/coprocessor/circuit/tests/leaf.rs b/hashes/zkevm/src/keccak/component/circuit/tests/shard.rs similarity index 76% rename from hashes/zkevm/src/keccak/coprocessor/circuit/tests/leaf.rs rename to hashes/zkevm/src/keccak/component/circuit/tests/shard.rs index a7b45552..17726327 100644 --- a/hashes/zkevm/src/keccak/coprocessor/circuit/tests/leaf.rs +++ b/hashes/zkevm/src/keccak/component/circuit/tests/shard.rs @@ -5,8 +5,8 @@ use crate::{ halo2curves::bn256::Fr, plonk::{keygen_pk, keygen_vk}, }, - keccak::coprocessor::{ - circuit::leaf::{KeccakCoprocessorLeafCircuit, KeccakCoprocessorLeafCircuitParams}, + keccak::component::{ + circuit::shard::{KeccakComponentShardCircuit, KeccakComponentShardCircuitParams}, output::{calculate_circuit_outputs_commit, multi_inputs_to_circuit_outputs}, }, }; @@ -19,7 +19,7 @@ use itertools::Itertools; use rand_core::OsRng; #[test] -fn test_mock_leaf_circuit_raw_outputs() { +fn test_mock_shard_circuit_raw_outputs() { let k: usize = 18; let num_unusable_row: usize = 109; let capacity: usize = 10; @@ -35,11 +35,11 @@ fn test_mock_leaf_circuit_raw_outputs() { ]; let mut params = - KeccakCoprocessorLeafCircuitParams::new(k, num_unusable_row, capacity, publish_raw_outputs); + KeccakComponentShardCircuitParams::new(k, num_unusable_row, capacity, publish_raw_outputs); let base_circuit_params = - KeccakCoprocessorLeafCircuit::::calculate_base_circuit_params(¶ms); + KeccakComponentShardCircuit::::calculate_base_circuit_params(¶ms); params.base_circuit_params = base_circuit_params; - let circuit = KeccakCoprocessorLeafCircuit::::new(inputs.clone(), params.clone(), false); + let circuit = KeccakComponentShardCircuit::::new(inputs.clone(), params.clone(), false); let circuit_outputs = multi_inputs_to_circuit_outputs::(&inputs, params.capacity()); let instances = vec![ @@ -53,7 +53,7 @@ fn test_mock_leaf_circuit_raw_outputs() { } #[test] -fn test_prove_leaf_circuit_raw_outputs() { +fn test_prove_shard_circuit_raw_outputs() { let _ = env_logger::builder().is_test(true).try_init(); let k: usize = 18; @@ -63,11 +63,11 @@ fn test_prove_leaf_circuit_raw_outputs() { let inputs = vec![]; let mut circuit_params = - KeccakCoprocessorLeafCircuitParams::new(k, num_unusable_row, capacity, publish_raw_outputs); + KeccakComponentShardCircuitParams::new(k, num_unusable_row, capacity, publish_raw_outputs); let base_circuit_params = - KeccakCoprocessorLeafCircuit::::calculate_base_circuit_params(&circuit_params); + KeccakComponentShardCircuit::::calculate_base_circuit_params(&circuit_params); circuit_params.base_circuit_params = base_circuit_params; - let circuit = KeccakCoprocessorLeafCircuit::::new(inputs, circuit_params.clone(), false); + let circuit = KeccakComponentShardCircuit::::new(inputs, circuit_params.clone(), false); let params = ParamsKZG::::setup(k as u32, OsRng); @@ -90,7 +90,7 @@ fn test_prove_leaf_circuit_raw_outputs() { ]; let break_points = circuit.base_circuit_break_points(); - let circuit = KeccakCoprocessorLeafCircuit::::new(inputs, circuit_params, true); + let circuit = KeccakComponentShardCircuit::::new(inputs, circuit_params, true); circuit.set_base_circuit_break_points(break_points); let proof = gen_proof_with_instances( @@ -109,7 +109,7 @@ fn test_prove_leaf_circuit_raw_outputs() { } #[test] -fn test_mock_leaf_circuit_commit() { +fn test_mock_shard_circuit_commit() { let k: usize = 18; let num_unusable_row: usize = 109; let capacity: usize = 10; @@ -125,11 +125,11 @@ fn test_mock_leaf_circuit_commit() { ]; let mut params = - KeccakCoprocessorLeafCircuitParams::new(k, num_unusable_row, capacity, publish_raw_outputs); + KeccakComponentShardCircuitParams::new(k, num_unusable_row, capacity, publish_raw_outputs); let base_circuit_params = - KeccakCoprocessorLeafCircuit::::calculate_base_circuit_params(¶ms); + KeccakComponentShardCircuit::::calculate_base_circuit_params(¶ms); params.base_circuit_params = base_circuit_params; - let circuit = KeccakCoprocessorLeafCircuit::::new(inputs.clone(), params.clone(), false); + let circuit = KeccakComponentShardCircuit::::new(inputs.clone(), params.clone(), false); let circuit_outputs = multi_inputs_to_circuit_outputs::(&inputs, params.capacity()); let instances = vec![vec![calculate_circuit_outputs_commit(&circuit_outputs)]]; @@ -139,7 +139,7 @@ fn test_mock_leaf_circuit_commit() { } #[test] -fn test_prove_leaf_circuit_commit() { +fn test_prove_shard_circuit_commit() { let _ = env_logger::builder().is_test(true).try_init(); let k: usize = 18; @@ -149,11 +149,11 @@ fn test_prove_leaf_circuit_commit() { let inputs = vec![]; let mut circuit_params = - KeccakCoprocessorLeafCircuitParams::new(k, num_unusable_row, capacity, publish_raw_outputs); + KeccakComponentShardCircuitParams::new(k, num_unusable_row, capacity, publish_raw_outputs); let base_circuit_params = - KeccakCoprocessorLeafCircuit::::calculate_base_circuit_params(&circuit_params); + KeccakComponentShardCircuit::::calculate_base_circuit_params(&circuit_params); circuit_params.base_circuit_params = base_circuit_params; - let circuit = KeccakCoprocessorLeafCircuit::::new(inputs, circuit_params.clone(), false); + let circuit = KeccakComponentShardCircuit::::new(inputs, circuit_params.clone(), false); let params = ParamsKZG::::setup(k as u32, OsRng); @@ -171,7 +171,7 @@ fn test_prove_leaf_circuit_commit() { let break_points = circuit.base_circuit_break_points(); let circuit = - KeccakCoprocessorLeafCircuit::::new(inputs.clone(), circuit_params.clone(), true); + KeccakComponentShardCircuit::::new(inputs.clone(), circuit_params.clone(), true); circuit.set_base_circuit_break_points(break_points); let circuit_outputs = multi_inputs_to_circuit_outputs::(&inputs, circuit_params.capacity()); diff --git a/hashes/zkevm/src/keccak/coprocessor/encode.rs b/hashes/zkevm/src/keccak/component/encode.rs similarity index 98% rename from hashes/zkevm/src/keccak/coprocessor/encode.rs rename to hashes/zkevm/src/keccak/component/encode.rs index febb8883..33230bee 100644 --- a/hashes/zkevm/src/keccak/coprocessor/encode.rs +++ b/hashes/zkevm/src/keccak/component/encode.rs @@ -17,10 +17,10 @@ use crate::{ use super::param::*; -// TODO: Abstract this module into a trait for all coprocessor circuits. +// TODO: Abstract this module into a trait for all component circuits. /// Module to encode raw inputs into lookup keys for looking up keccak results. The encoding is -/// designed to be efficient in coprocessor circuits. +/// designed to be efficient in component circuits. /// Encode a native input bytes into its corresponding lookup key. This function can be considered as the spec of the encoding. pub fn encode_native_input(bytes: &[u8]) -> F { diff --git a/hashes/zkevm/src/keccak/coprocessor/ingestion.rs b/hashes/zkevm/src/keccak/component/ingestion.rs similarity index 94% rename from hashes/zkevm/src/keccak/coprocessor/ingestion.rs rename to hashes/zkevm/src/keccak/component/ingestion.rs index 12674b16..cc0b2c3f 100644 --- a/hashes/zkevm/src/keccak/coprocessor/ingestion.rs +++ b/hashes/zkevm/src/keccak/component/ingestion.rs @@ -3,7 +3,7 @@ use ethers_core::{types::H256, utils::keccak256}; use crate::keccak::vanilla::param::NUM_BYTES_TO_ABSORB; /// Fixed length format for one keccak_f. -/// This closely matches [zkevm_hashes::keccak::coprocessor::circuit::leaf::LoadedKeccakF]. +/// This closely matches [crate::keccak::component::circuit::shard::LoadedKeccakF]. #[derive(Clone, Debug)] pub struct KeccakIngestionFormat { pub bytes_per_keccak_f: [u8; NUM_BYTES_TO_ABSORB], @@ -39,7 +39,7 @@ impl KeccakIngestionFormat { /// We split each input into `KeccakIngestionFormat` chunks, one for each keccak_f needed to compute `keccak(input)`. /// We then resize so there are exactly `capacity` total chunks. /// -/// Very similar to [zkevm_hashes::keccak::coprocessor::encode::encode_native_input] except we do not do the +/// Very similar to [crate::keccak::component::encode::encode_native_input] except we do not do the /// encoding part (that will be done in circuit, not natively). /// /// Returns `Err(true_capacity)` if `true_capacity > capacity`, where `true_capacity` is the number of keccak_f needed diff --git a/hashes/zkevm/src/keccak/coprocessor/mod.rs b/hashes/zkevm/src/keccak/component/mod.rs similarity index 50% rename from hashes/zkevm/src/keccak/coprocessor/mod.rs rename to hashes/zkevm/src/keccak/component/mod.rs index f4b68455..13bbd303 100644 --- a/hashes/zkevm/src/keccak/coprocessor/mod.rs +++ b/hashes/zkevm/src/keccak/component/mod.rs @@ -1,12 +1,12 @@ -/// Module of Keccak coprocessor circuit. +/// Module of Keccak component circuit(s). pub mod circuit; -/// Module of encoding raw inputs to coprocessor circuit lookup keys. +/// Module of encoding raw inputs to component circuit lookup keys. pub mod encode; /// Module for Rust native processing of input bytes into resized fixed length format to match vanilla circuit LoadedKeccakF pub mod ingestion; -/// Module of Keccak coprocessor circuit output. +/// Module of Keccak component circuit output. pub mod output; -/// Module of Keccak coprocessor circuit constant parameters. +/// Module of Keccak component circuit constant parameters. pub mod param; #[cfg(test)] mod tests; diff --git a/hashes/zkevm/src/keccak/coprocessor/output.rs b/hashes/zkevm/src/keccak/component/output.rs similarity index 100% rename from hashes/zkevm/src/keccak/coprocessor/output.rs rename to hashes/zkevm/src/keccak/component/output.rs diff --git a/hashes/zkevm/src/keccak/coprocessor/param.rs b/hashes/zkevm/src/keccak/component/param.rs similarity index 100% rename from hashes/zkevm/src/keccak/coprocessor/param.rs rename to hashes/zkevm/src/keccak/component/param.rs diff --git a/hashes/zkevm/src/keccak/coprocessor/tests/encode.rs b/hashes/zkevm/src/keccak/component/tests/encode.rs similarity index 98% rename from hashes/zkevm/src/keccak/coprocessor/tests/encode.rs rename to hashes/zkevm/src/keccak/component/tests/encode.rs index 761a4e9a..df576c66 100644 --- a/hashes/zkevm/src/keccak/coprocessor/tests/encode.rs +++ b/hashes/zkevm/src/keccak/component/tests/encode.rs @@ -8,8 +8,8 @@ use halo2_base::{ }; use itertools::Itertools; -use crate::keccak::coprocessor::{ - circuit::leaf::create_hasher, +use crate::keccak::component::{ + circuit::shard::create_hasher, encode::{encode_fix_len_bytes_vec, encode_native_input, encode_var_len_bytes_vec}, }; diff --git a/hashes/zkevm/src/keccak/coprocessor/tests/mod.rs b/hashes/zkevm/src/keccak/component/tests/mod.rs similarity index 100% rename from hashes/zkevm/src/keccak/coprocessor/tests/mod.rs rename to hashes/zkevm/src/keccak/component/tests/mod.rs diff --git a/hashes/zkevm/src/keccak/coprocessor/tests/output.rs b/hashes/zkevm/src/keccak/component/tests/output.rs similarity index 99% rename from hashes/zkevm/src/keccak/coprocessor/tests/output.rs rename to hashes/zkevm/src/keccak/component/tests/output.rs index c72c518c..c63aa352 100644 --- a/hashes/zkevm/src/keccak/coprocessor/tests/output.rs +++ b/hashes/zkevm/src/keccak/component/tests/output.rs @@ -1,4 +1,4 @@ -use crate::keccak::coprocessor::output::{ +use crate::keccak::component::output::{ dummy_circuit_output, input_to_circuit_outputs, multi_inputs_to_circuit_outputs, KeccakCircuitOutput, }; diff --git a/hashes/zkevm/src/keccak/coprocessor/circuit/tests/mod.rs b/hashes/zkevm/src/keccak/coprocessor/circuit/tests/mod.rs deleted file mode 100644 index 4d6a7f45..00000000 --- a/hashes/zkevm/src/keccak/coprocessor/circuit/tests/mod.rs +++ /dev/null @@ -1,2 +0,0 @@ -#[cfg(test)] -pub mod leaf; diff --git a/hashes/zkevm/src/keccak/mod.rs b/hashes/zkevm/src/keccak/mod.rs index 58480989..dd9a660b 100644 --- a/hashes/zkevm/src/keccak/mod.rs +++ b/hashes/zkevm/src/keccak/mod.rs @@ -1,4 +1,4 @@ -/// Module for coprocessor circuits. -pub mod coprocessor; +/// Module for component circuits. +pub mod component; /// Module for Keccak circuits in vanilla halo2. pub mod vanilla;