Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
[word lo/hi] pi circuit replace rand/rlc by keccak hash (#1345)
Browse files Browse the repository at this point in the history
### Description

replace rand/rlc by pure keccak hashing

### Issue Link
-
#1344
-
#1383

### Type of change

- [x] Breaking change (fix or feature that would cause existing
functionality to not work as expected)

### Contents

- replace rpi rand/rlc logic by pure hashing 
- simplify public input into just 2 fields: digest[0:16] as `hi`, and
digest[16:32] as `lo`, while `digest = Keccak(<public data>)`
- adopt word-lo-hi

nitpick
- prefix table column annotation with table name for better debugging


### Rationale

[_design decisions and extended information_]

### How Has This Been Tested?

[_explanation_]
  • Loading branch information
hero78119 committed Jun 30, 2023
1 parent a3e4e3e commit dd8e246
Show file tree
Hide file tree
Showing 15 changed files with 1,441 additions and 937 deletions.
2 changes: 2 additions & 0 deletions bus-mapping/src/circuit_input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ impl<'a> CircuitInputBuilder {
let geth_trace = &geth_traces[tx_index];
self.handle_tx(tx, geth_trace, tx_index + 1 == eth_block.transactions.len())?;
}
// set eth_block
self.block.eth_block = eth_block.clone();
self.set_value_ops_call_context_rwc_eor();
self.set_end_block();
Ok(())
Expand Down
13 changes: 2 additions & 11 deletions circuit-benchmarks/src/pi_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod tests {
use ark_std::{end_timer, start_timer};
use eth_types::Word;
use halo2_proofs::{
arithmetic::Field,
halo2curves::bn256::{Bn256, Fr, G1Affine},
plonk::{create_proof, keygen_pk, keygen_vk, verify_proof},
poly::{
Expand All @@ -20,13 +19,9 @@ mod tests {
},
};
use rand::SeedableRng;
use rand_chacha::ChaCha20Rng;
use rand_xorshift::XorShiftRng;
use std::env::var;
use zkevm_circuits::{
pi_circuit::{PiCircuit, PublicData},
util::SubCircuit,
};
use zkevm_circuits::{instance::PublicData, pi_circuit::PiCircuit, util::SubCircuit};

#[cfg_attr(not(feature = "benches"), ignore)]
#[test]
Expand All @@ -45,12 +40,8 @@ mod tests {
.parse()
.expect("Cannot parse DEGREE env var as u32");

let mut rng = ChaCha20Rng::seed_from_u64(2);
let randomness = Fr::random(&mut rng);
let rand_rpi = Fr::random(&mut rng);
let public_data = generate_publicdata(MAX_TXS);
let circuit =
PiCircuit::<Fr>::new(MAX_TXS, MAX_CALLDATA, randomness, rand_rpi, public_data);
let circuit = PiCircuit::<Fr>::new(MAX_TXS, MAX_CALLDATA, public_data);
let public_inputs = circuit.instance();
let instance: Vec<&[Fr]> = public_inputs.iter().map(|input| &input[..]).collect();
let instances = &[&instance[..]];
Expand Down
1 change: 1 addition & 0 deletions integration-tests/run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh
set -e
set -o xtrace

ARG_DEFAULT_SUDO=
ARG_DEFAULT_STEPS="setup gendata tests cleanup"
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/src/integration_test_circuits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const MAX_EVM_ROWS: usize = 10000;
/// MAX_EXP_STEPS
const MAX_EXP_STEPS: usize = 1000;

const MAX_KECCAK_ROWS: usize = 15000;
const MAX_KECCAK_ROWS: usize = 38000;

const CIRCUITS_PARAMS: CircuitsParams = CircuitsParams {
max_rws: MAX_RWS,
Expand Down
45 changes: 45 additions & 0 deletions zkevm-circuits/src/evm_circuit/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,51 @@ pub(crate) const N_BYTES_GAS: usize = N_BYTES_U64;
// Number of bytes that will be used for call data's size.
pub(crate) const N_BYTES_CALLDATASIZE: usize = N_BYTES_U64;

// Number of bytes that will be used for block values
pub(crate) const N_BYTES_COINBASE: usize = N_BYTES_ACCOUNT_ADDRESS;
pub(crate) const N_BYTES_GAS_LIMIT: usize = N_BYTES_U64;
pub(crate) const N_BYTES_NUMBER: usize = N_BYTES_U64;
pub(crate) const N_BYTES_TIMESTAMP: usize = N_BYTES_U64;
pub(crate) const N_BYTES_DIFFICULTY: usize = N_BYTES_WORD;
pub(crate) const N_BYTES_BASE_FEE: usize = N_BYTES_WORD;
pub(crate) const N_BYTES_CHAIN_ID: usize = N_BYTES_U64;
pub(crate) const N_BYTES_PREV_HASH: usize = 256 * N_BYTES_WORD;

pub(crate) const N_BYTES_BLOCK: usize = N_BYTES_COINBASE
+ N_BYTES_GAS_LIMIT
+ N_BYTES_NUMBER
+ N_BYTES_TIMESTAMP
+ N_BYTES_DIFFICULTY
+ N_BYTES_BASE_FEE
+ N_BYTES_CHAIN_ID
+ N_BYTES_PREV_HASH;

pub(crate) const N_BYTES_EXTRA_VALUE: usize = N_BYTES_WORD // block hash
+ N_BYTES_WORD // state root
+ N_BYTES_WORD; // prev state root

// Number of bytes that will be used for tx values
pub(crate) const N_BYTES_TX_NONCE: usize = N_BYTES_U64;
pub(crate) const N_BYTES_TX_GAS_LIMIT: usize = N_BYTES_U64; // gas limit type is U256, different with gas U64
pub(crate) const N_BYTES_TX_GASPRICE: usize = N_BYTES_WORD;
pub(crate) const N_BYTES_TX_FROM: usize = N_BYTES_ACCOUNT_ADDRESS;
pub(crate) const N_BYTES_TX_TO: usize = N_BYTES_ACCOUNT_ADDRESS;
pub(crate) const N_BYTES_TX_IS_CREATE: usize = N_BYTES_U64;
pub(crate) const N_BYTES_TX_VALUE: usize = N_BYTES_WORD;
pub(crate) const N_BYTES_TX_CALLDATA_LEN: usize = N_BYTES_CALLDATASIZE;
pub(crate) const N_BYTES_TX_CALLDATA_GASCOST: usize = N_BYTES_U64;
pub(crate) const N_BYTES_TX_TXSIGNHASH: usize = N_BYTES_WORD;
pub(crate) const N_BYTES_TX: usize = N_BYTES_TX_NONCE
+ N_BYTES_TX_GAS_LIMIT
+ N_BYTES_TX_GASPRICE
+ N_BYTES_TX_FROM
+ N_BYTES_TX_TO
+ N_BYTES_TX_IS_CREATE
+ N_BYTES_TX_VALUE
+ N_BYTES_TX_CALLDATA_LEN
+ N_BYTES_TX_CALLDATA_GASCOST
+ N_BYTES_TX_TXSIGNHASH;

lazy_static::lazy_static! {
// Step slot height in evm circuit
pub(crate) static ref EXECUTION_STATE_HEIGHT_MAP : HashMap<ExecutionState, usize> = get_step_height_map();
Expand Down
Loading

0 comments on commit dd8e246

Please sign in to comment.