Skip to content

Commit 7617394

Browse files
authored
opt: dedup inputs for keccak circuit (privacy-scaling-explorations#1672)
### Description this is a minor PR to remove duplicate entries for keccak circuit. ### Issue Link [_link issue here_] ### Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update
1 parent 3bf9bc2 commit 7617394

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

bus-mapping/src/circuit_input_builder.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ pub use execution::{
3535
pub use input_state_ref::CircuitInputStateRef;
3636
use itertools::Itertools;
3737
use log::warn;
38-
use std::{collections::HashMap, ops::Deref};
38+
use std::{
39+
collections::{HashMap, HashSet},
40+
ops::Deref,
41+
};
3942
pub use transaction::{Transaction, TransactionContext};
4043
pub use withdrawal::{Withdrawal, WithdrawalContext};
4144

@@ -455,19 +458,23 @@ impl CircuitInputBuilder<DynamicCParams> {
455458
/// Return all the keccak inputs used during the processing of the current
456459
/// block.
457460
pub fn keccak_inputs(block: &Block, code_db: &CodeDB) -> Result<Vec<Vec<u8>>, Error> {
458-
let mut keccak_inputs = Vec::new();
461+
let mut keccak_inputs: HashSet<Vec<u8>> = HashSet::new();
459462
// Tx Circuit
460463
let txs: Vec<geth_types::Transaction> = block.txs.iter().map(|tx| tx.deref().clone()).collect();
461-
keccak_inputs.extend_from_slice(&keccak_inputs_tx_circuit(&txs, block.chain_id.as_u64())?);
464+
for input in keccak_inputs_tx_circuit(&txs, block.chain_id.as_u64())? {
465+
keccak_inputs.insert(input);
466+
}
462467
// Bytecode Circuit
463468
for bytecode in code_db.clone().into_iter() {
464-
keccak_inputs.push(bytecode.code());
469+
keccak_inputs.insert(bytecode.code());
465470
}
466471
// EVM Circuit
467-
keccak_inputs.extend_from_slice(&block.sha3_inputs);
472+
for input in &block.sha3_inputs {
473+
keccak_inputs.insert(input.clone());
474+
}
468475
// MPT Circuit
469476
// TODO https://github.com/privacy-scaling-explorations/zkevm-circuits/issues/696
470-
Ok(keccak_inputs)
477+
Ok(keccak_inputs.into_iter().collect_vec())
471478
}
472479

473480
/// Generate the keccak inputs required by the SignVerify Chip from the

0 commit comments

Comments
 (0)