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

Commit

Permalink
more test: verify all chunks individually correctness correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
hero78119 committed Feb 22, 2024
1 parent 46d5437 commit 03d00ec
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 28 deletions.
20 changes: 13 additions & 7 deletions bus-mapping/src/circuit_input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,6 @@ impl<'a, C: CircuitsParams> CircuitInputBuilder<C> {
next_copy_index: usize,
last_call: Option<Call>,
) {
println!("commit_chunk_ctx");
self.chunk_ctx.end_rwc = self.block_ctx.rwc.0;
self.chunk_ctx.end_tx_index = next_tx_index;
self.chunk_ctx.end_copy_index = next_copy_index;
Expand Down Expand Up @@ -627,6 +626,11 @@ impl<'a, C: CircuitsParams> CircuitInputBuilder<C> {
self.chunks[self.chunk_ctx.idx].padding = Some(padding);
}

/// Get the i-th mutable chunk
pub fn get_chunk_mut(&mut self, i: usize) -> &mut Chunk {
self.chunks.get_mut(i).expect("Chunk does not exist")
}

/// Get the i-th chunk
pub fn get_chunk(&self, i: usize) -> Chunk {
self.chunks.get(i).expect("Chunk does not exist").clone()
Expand Down Expand Up @@ -707,21 +711,23 @@ impl CircuitInputBuilder<FixedCParams> {

let last_copy = self.block.copy_events.len();

// We fill dummy virtual steps: BeginChunk,EndChunk for all lefted empty chunks
// TODO figure out and resolve generic param type and move fixed_param set inside
// commit_chunk_ctx After fixed, then we can set fixed_param on all chunks
(0..self.circuits_params.total_chunks()).for_each(|idx| {
self.get_chunk_mut(idx).fixed_param = self.circuits_params;
});

// We fill dummy virtual steps: BeginChunk,EndChunk for redundant chunks
let last_process_chunk_id = self.chunk_ctx.idx;
(last_process_chunk_id..self.circuits_params.total_chunks()).try_for_each(|idx| {
// TODO figure out and resolve generic param type and move fixed_param set inside
// commit_chunk_ctx After fixed, then we can set fixed_param on all chunks
self.cur_chunk_mut().fixed_param = self.circuits_params;

if idx == self.circuits_params.total_chunks() - 1 {
self.set_end_block()?;
self.commit_chunk_ctx(
false,
eth_block.transactions.len(),
last_copy,
last_call.clone(),
);
self.set_end_block()?;
} else {
// it doent matter what step was put to set_end_chunk/set_begin_chunk on no-used
// chunks before end_block. Just need to make sure it's step lookup is consistency.
Expand Down
60 changes: 39 additions & 21 deletions zkevm-circuits/src/evm_circuit/execution/end_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ mod test {
}

#[test]
fn test_intermediate_single_chunk() {
fn test_all_chunks_ok() {
let bytecode = bytecode! {
PUSH1(0x0) // retLength
PUSH1(0x0) // retOffset
Expand Down Expand Up @@ -168,29 +168,47 @@ mod test {
}

#[test]
fn test_intermediate_single_chunk_fixed() {
fn test_all_chunks_fixed() {
let bytecode = bytecode! {
PUSH1(0x0) // retLength
PUSH1(0x0) // retOffset
PUSH1(0x0) // argsLength
PUSH1(0x0) // argsOffset
PUSH1(0x0) // value
PUSH32(0x10_0000) // addr
PUSH32(0x10_0000) // gas
CALL
PUSH2(0xaa)
GAS
STOP
};
CircuitTestBuilder::new_from_test_ctx(
TestContext::<2, 1>::simple_ctx_with_bytecode(bytecode).unwrap(),
let addr_a = address!("0x000000000000000000000000000000000000AAAA");
let addr_b = address!("0x000000000000000000000000000000000000BBBB");
let test_ctx = TestContext::<2, 2>::new(
None,
|accs| {
accs[0]
.address(addr_b)
.balance(Word::from(1u64 << 20))
.code(bytecode);
accs[1].address(addr_a).balance(Word::from(1u64 << 20));
},
|mut txs, accs| {
txs[0]
.from(accs[1].address)
.to(accs[0].address)
.gas(Word::from(1_000_000u64));
txs[1]
.from(accs[1].address)
.to(accs[0].address)
.gas(Word::from(1_000_000u64));
},
|block, _tx| block.number(0xcafeu64),
)
.params({
FixedCParams {
total_chunks: 2,
max_rws: 60,
..Default::default()
}
})
.run_chunk(1);
.unwrap();
(0..6).for_each(|chunk_id| {
CircuitTestBuilder::new_from_test_ctx(test_ctx.clone())
.params({
FixedCParams {
total_chunks: 6,
max_rws: 64,
max_txs: 2,
..Default::default()
}
})
.run_chunk(chunk_id);
});
}

#[test]
Expand Down

0 comments on commit 03d00ec

Please sign in to comment.