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

Commit

Permalink
MAX_COPY_ROWS
Browse files Browse the repository at this point in the history
  • Loading branch information
pinkiebell committed Jan 19, 2023
1 parent 7ff4ed6 commit ecfd85f
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 15 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions common/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ pub struct CircuitConfig {
pub max_calldata: usize,
pub max_bytecode: usize,
pub max_rws: usize,
pub max_copy_rows: usize,
pub min_k: usize,
pub pad_to: usize,
pub min_k_aggregation: usize,
Expand Down
2 changes: 2 additions & 0 deletions prover/src/circuit_autogen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ macro_rules! match_circuit_params {
max_rws: 476052,
min_k: 19,
pad_to: 476052,
max_copy_rows: 1,
min_k_aggregation: 26,
keccak_padding: 336000,
};
Expand All @@ -23,6 +24,7 @@ macro_rules! match_circuit_params {
max_calldata: 69750,
max_bytecode: 139500,
max_rws: 3161966,
max_copy_rows: 1,
min_k: 22,
pad_to: 3161966,
min_k_aggregation: 26,
Expand Down
2 changes: 2 additions & 0 deletions prover/src/circuit_witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl CircuitWitness {
max_calldata: circuit_config.max_calldata,
max_bytecode: circuit_config.max_bytecode,
max_rws: circuit_config.max_rws,
max_copy_rows: circuit_config.max_copy_rows,
keccak_padding: Some(circuit_config.keccak_padding),
};
let empty_data = GethData {
Expand Down Expand Up @@ -84,6 +85,7 @@ impl CircuitWitness {
max_calldata: circuit_config.max_calldata,
max_bytecode: circuit_config.max_bytecode,
max_rws: circuit_config.max_rws,
max_copy_rows: circuit_config.max_copy_rows,
keccak_padding: Some(circuit_config.keccak_padding),
};
let builder = BuilderClient::new(geth_client, circuit_params).await?;
Expand Down
13 changes: 11 additions & 2 deletions prover/src/circuits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ pub fn gen_super_circuit<
const MAX_TXS: usize,
const MAX_CALLDATA: usize,
const MAX_RWS: usize,
const MAX_COPY_ROWS: usize,
RNG: Rng,
>(
witness: &CircuitWitness,
mut _rng: RNG,
) -> Result<SuperCircuit<Fr, MAX_TXS, MAX_CALLDATA, MAX_RWS>, String> {
) -> Result<SuperCircuit<Fr, MAX_TXS, MAX_CALLDATA, MAX_RWS, MAX_COPY_ROWS>, String> {
let block = witness.evm_witness();

let evm_circuit = EvmCircuit::new_from_block(&block);
Expand All @@ -33,7 +34,7 @@ pub fn gen_super_circuit<
let copy_circuit = CopyCircuit::new_from_block(&block);
let exp_circuit = ExpCircuit::new_from_block(&block);
let keccak_circuit = KeccakCircuit::new_from_block(&block);
let circuit = SuperCircuit::<_, MAX_TXS, MAX_CALLDATA, MAX_RWS> {
let circuit = SuperCircuit::<_, MAX_TXS, MAX_CALLDATA, MAX_RWS, MAX_COPY_ROWS> {
evm_circuit,
state_circuit,
tx_circuit,
Expand All @@ -52,6 +53,7 @@ pub fn gen_pi_circuit<
const MAX_TXS: usize,
const MAX_CALLDATA: usize,
const MAX_RWS: usize,
const MAX_COPY_ROWS: usize,
RNG: Rng,
>(
witness: &CircuitWitness,
Expand All @@ -68,6 +70,7 @@ pub fn gen_evm_circuit<
const MAX_TXS: usize,
const MAX_CALLDATA: usize,
const MAX_RWS: usize,
const MAX_COPY_ROWS: usize,
RNG: Rng,
>(
witness: &CircuitWitness,
Expand All @@ -82,6 +85,7 @@ pub fn gen_state_circuit<
const MAX_TXS: usize,
const MAX_CALLDATA: usize,
const MAX_RWS: usize,
const MAX_COPY_ROWS: usize,
RNG: Rng,
>(
witness: &CircuitWitness,
Expand All @@ -96,6 +100,7 @@ pub fn gen_tx_circuit<
const MAX_TXS: usize,
const MAX_CALLDATA: usize,
const MAX_RWS: usize,
const MAX_COPY_ROWS: usize,
RNG: Rng,
>(
witness: &CircuitWitness,
Expand All @@ -110,6 +115,7 @@ pub fn gen_bytecode_circuit<
const MAX_TXS: usize,
const MAX_CALLDATA: usize,
const MAX_RWS: usize,
const MAX_COPY_ROWS: usize,
RNG: Rng,
>(
witness: &CircuitWitness,
Expand All @@ -124,6 +130,7 @@ pub fn gen_copy_circuit<
const MAX_TXS: usize,
const MAX_CALLDATA: usize,
const MAX_RWS: usize,
const MAX_COPY_ROWS: usize,
RNG: Rng,
>(
witness: &CircuitWitness,
Expand All @@ -138,6 +145,7 @@ pub fn gen_exp_circuit<
const MAX_TXS: usize,
const MAX_CALLDATA: usize,
const MAX_RWS: usize,
const MAX_COPY_ROWS: usize,
RNG: Rng,
>(
witness: &CircuitWitness,
Expand All @@ -152,6 +160,7 @@ pub fn gen_keccak_circuit<
const MAX_TXS: usize,
const MAX_CALLDATA: usize,
const MAX_RWS: usize,
const MAX_COPY_ROWS: usize,
RNG: Rng,
>(
witness: &CircuitWitness,
Expand Down
2 changes: 2 additions & 0 deletions prover/src/shared_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ macro_rules! gen_proof {
{ CIRCUIT_CONFIG.max_txs },
{ CIRCUIT_CONFIG.max_calldata },
{ CIRCUIT_CONFIG.max_rws },
{ CIRCUIT_CONFIG.max_copy_rows },
_,
>(&witness, fixed_rng())?;
circuit_proof.k = CIRCUIT_CONFIG.min_k as u8;
Expand All @@ -104,6 +105,7 @@ macro_rules! gen_proof {
{ CIRCUIT_CONFIG.max_txs },
{ CIRCUIT_CONFIG.max_calldata },
{ CIRCUIT_CONFIG.max_rws },
{ CIRCUIT_CONFIG.max_copy_rows },
_,
>(&witness, fixed_rng())?;
// generate and cache the prover key
Expand Down
23 changes: 18 additions & 5 deletions prover/tests/autogen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,19 @@ fn run_assembly<
const MAX_CALLDATA: usize,
const MAX_BYTECODE: usize,
const MAX_RWS: usize,
const MAX_COPY_ROWS: usize,
>(
witness: CircuitWitness,
) -> Result<usize, String> {
let circuit = gen_super_circuit::<MAX_TXS, MAX_CALLDATA, MAX_RWS, _>(&witness, fixed_rng())
.expect("gen_static_circuit");
let circuit = gen_super_circuit::<MAX_TXS, MAX_CALLDATA, MAX_RWS, MAX_COPY_ROWS, _>(
&witness,
fixed_rng(),
)
.expect("gen_static_circuit");

let mut cs = ConstraintSystem::default();
let config = SuperCircuit::<Fr, MAX_TXS, MAX_CALLDATA, MAX_RWS>::configure(&mut cs);
let config =
SuperCircuit::<Fr, MAX_TXS, MAX_CALLDATA, MAX_RWS, MAX_COPY_ROWS>::configure(&mut cs);
let mut assembly = Assembly::default();
let constants = cs.constants();
SimpleFloorPlanner::synthesize(&mut assembly, &circuit, config, constants.to_vec())
Expand All @@ -199,6 +204,10 @@ macro_rules! estimate {
// - Add support for querying the most expensive opcode here.
const MAX_RWS: usize = (64 * MAX_TXS) + ((TX_GAS_LIMIT * 1133) / 100);
const KECCAK_WORD_GAS: usize = 6;
const COPY_GAS: usize = 3;
// TODO: doesn't account for instruction + memory expansion
const MAX_COPY_BYTES: usize = TX_GAS_LIMIT / COPY_GAS;
const MAX_COPY_ROWS: usize = (MAX_COPY_BYTES * 2) + 2;

let bytecode = $BYTECODE_FN(TX_GAS_LIMIT);
let history_hashes = vec![Word::one(); 256];
Expand All @@ -210,6 +219,7 @@ macro_rules! estimate {
max_calldata: MAX_CALLDATA,
max_bytecode: MAX_BYTECODE,
max_rws: MAX_RWS,
max_copy_rows: MAX_COPY_ROWS,
min_k: 0,
pad_to: 0,
min_k_aggregation: 0,
Expand Down Expand Up @@ -257,6 +267,7 @@ macro_rules! estimate {
max_calldata: circuit_config.max_calldata,
max_bytecode: circuit_config.max_bytecode,
max_rws: circuit_config.max_rws,
max_copy_rows: circuit_config.max_copy_rows,
keccak_padding: Some(circuit_config.keccak_padding),
};
let mut builder =
Expand Down Expand Up @@ -292,8 +303,10 @@ macro_rules! estimate {
circuit_config.pad_to = MAX_RWS;

let highest_row =
run_assembly::<MAX_TXS, MAX_CALLDATA, MAX_BYTECODE, MAX_RWS>(circuit_witness)
.unwrap();
run_assembly::<MAX_TXS, MAX_CALLDATA, MAX_BYTECODE, MAX_RWS, MAX_COPY_ROWS>(
circuit_witness,
)
.unwrap();
let log2_ceil = |n| u32::BITS - (n as u32).leading_zeros() - (n & (n - 1) == 0) as u32;
let k = log2_ceil(highest_row) as usize;
let remaining_rows = (1 << k) - highest_row;
Expand Down
1 change: 1 addition & 0 deletions prover/tests/verifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ macro_rules! gen_match {
{ CIRCUIT_CONFIG.max_txs },
{ CIRCUIT_CONFIG.max_calldata },
{ CIRCUIT_CONFIG.max_rws },
{ CIRCUIT_CONFIG.max_copy_rows },
_,
>(&witness, fixed_rng())
.expect("gen_static_circuit");
Expand Down

0 comments on commit ecfd85f

Please sign in to comment.