Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
219b303
Add circuit for RETURNDATASIZE opcode
xiaodino Aug 22, 2022
dce1366
Update tests
xiaodino Aug 25, 2022
3a1d151
update last call info in return (#2)
smtmfft Aug 27, 2022
d162713
Update tests
xiaodino Aug 27, 2022
f3d78c4
Merge branch 'xiaodino/returndatasize' of github.com:xiaodino/zkevm-c…
xiaodino Aug 27, 2022
d8891b7
Update tests
xiaodino Aug 27, 2022
69080e1
Update format in zkevm-circuits/src/evm_circuit/execution.rs
xiaodino Aug 27, 2022
fde42c3
Change unwrap to expect in returndatasize.rs
xiaodino Aug 27, 2022
aed1d7d
Add circuit for RETURNDATASIZE opcode
xiaodino Aug 22, 2022
012cea4
Update tests
xiaodino Aug 25, 2022
136fad9
update last call info in return (#2)
smtmfft Aug 27, 2022
c0b8872
Update tests
xiaodino Aug 27, 2022
2955c3d
Update tests
xiaodino Aug 27, 2022
7a03cb4
Update format in zkevm-circuits/src/evm_circuit/execution.rs
xiaodino Aug 27, 2022
fbdaa0e
Change unwrap to expect in returndatasize.rs
xiaodino Aug 27, 2022
c4f4237
according to RETURN spec, callee info update happens only in case C, …
smtmfft Aug 29, 2022
3dda80d
Merge branch 'xiaodino/returndatasize' of github.com:xiaodino/zkevm-c…
xiaodino Aug 29, 2022
6f7766c
Fix the issues with rustfmt
xiaodino Aug 29, 2022
0ee04d2
Fix merge conflicts
xiaodino Aug 29, 2022
eb35689
Merge branch 'main' into xiaodino/returndatasize
xiaodino Aug 29, 2022
fddfaa7
Update
xiaodino Aug 30, 2022
25371f6
Merge branch 'xiaodino/returndatasize' of github.com:xiaodino/zkevm-c…
xiaodino Aug 30, 2022
0dc902b
Add tests
xiaodino Aug 30, 2022
bfccd63
Merge branch 'main' into xiaodino/returndatasize
roynalnaruto Aug 31, 2022
2591c14
Merge branch 'main' into xiaodino/returndatasize
roynalnaruto Aug 31, 2022
dfdf1a7
Merge branch 'main' into xiaodino/returndatasize
CPerezz Sep 2, 2022
2267a2b
Merge branch 'main' into xiaodino/returndatasize
roynalnaruto Sep 2, 2022
45869a6
Merge branch 'main' into xiaodino/returndatasize
roynalnaruto Sep 3, 2022
72094ed
Merge branch 'main' into xiaodino/returndatasize
CPerezz Sep 6, 2022
f6e55be
Resolve conflicts
xiaodino Sep 8, 2022
34711d2
Merge branch 'xiaodino/returndatasize' of github.com:xiaodino/zkevm-c…
xiaodino Sep 8, 2022
56cff65
Resolve merge conflicts
xiaodino Sep 8, 2022
444009b
Merge branch 'main' into xiaodino/returndatasize
roynalnaruto Sep 12, 2022
700b07a
Merge branch 'main' into xiaodino/returndatasize
xiaodino Sep 12, 2022
2d057a0
Update bus-mapping return.rs, use N_BYTES_U64 for return_data_size an…
xiaodino Sep 12, 2022
3e8f1f0
Merge branch 'xiaodino/returndatasize' of github.com:xiaodino/zkevm-c…
xiaodino Sep 12, 2022
c0d6421
Merge branch 'main' into xiaodino/returndatasize
z2trillion Sep 23, 2022
3b5841f
Merge branch 'main' into xiaodino/returndatasize
roynalnaruto Sep 24, 2022
6b9becc
Merge branch 'main' into xiaodino/returndatasize
roynalnaruto Oct 4, 2022
18cdb29
Revert changes in bus-mapping return.rs
xiaodino Oct 28, 2022
595847b
Merge branch 'xiaodino/returndatasize' of github.com:xiaodino/zkevm-c…
xiaodino Oct 28, 2022
6696a1b
Revert change in bus-mapping return
xiaodino Oct 28, 2022
0f035a1
Merge branch 'main' into xiaodino/returndatasize
adria0 Oct 28, 2022
f5ac803
Merge branch 'main' into xiaodino/returndatasize
xiaodino Oct 29, 2022
db9e3d4
Update bus-mapping returndatasize_tests
xiaodino Oct 29, 2022
06f7b69
Merge branch 'xiaodino/returndatasize' of github.com:xiaodino/zkevm-c…
xiaodino Oct 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bus-mapping/src/evm/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ mod number;
mod origin;
mod r#return;
mod returndatacopy;
mod returndatasize;
mod selfbalance;
mod sha3;
mod sload;
Expand Down Expand Up @@ -76,6 +77,7 @@ use mstore::Mstore;
use origin::Origin;
use r#return::Return;
use returndatacopy::Returndatacopy;
use returndatasize::Returndatasize;
use selfbalance::Selfbalance;
use sload::Sload;
use sstore::Sstore;
Expand Down Expand Up @@ -161,7 +163,7 @@ fn fn_gen_associated_ops(opcode_id: &OpcodeId) -> FnGenAssociatedOps {
OpcodeId::CODESIZE => Codesize::gen_associated_ops,
OpcodeId::EXTCODESIZE => Extcodesize::gen_associated_ops,
OpcodeId::EXTCODECOPY => Extcodecopy::gen_associated_ops,
OpcodeId::RETURNDATASIZE => StackOnlyOpcode::<0, 1>::gen_associated_ops,
OpcodeId::RETURNDATASIZE => Returndatasize::gen_associated_ops,
OpcodeId::RETURNDATACOPY => Returndatacopy::gen_associated_ops,
OpcodeId::EXTCODEHASH => Extcodehash::gen_associated_ops,
OpcodeId::BLOCKHASH => StackOnlyOpcode::<1, 1>::gen_associated_ops,
Expand Down
163 changes: 163 additions & 0 deletions bus-mapping/src/evm/opcodes/returndatasize.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
use crate::{
circuit_input_builder::{CircuitInputStateRef, ExecStep},
operation::CallContextField,
Error,
};

use eth_types::GethExecStep;

use super::Opcode;

#[derive(Clone, Copy, Debug)]
pub(crate) struct Returndatasize;

impl Opcode for Returndatasize {
fn gen_associated_ops(
state: &mut CircuitInputStateRef,
geth_steps: &[GethExecStep],
) -> Result<Vec<ExecStep>, Error> {
let geth_step = &geth_steps[0];
let mut exec_step = state.new_step(geth_step)?;
let value = geth_steps[1].stack.last()?;
state.call_context_read(
&mut exec_step,
state.call()?.call_id,
CallContextField::LastCalleeReturnDataLength,
value,
);

state.stack_write(
&mut exec_step,
geth_step.stack.last_filled().map(|a| a - 1),
value,
)?;

Ok(vec![exec_step])
}
}

#[cfg(test)]
mod returndatasize_tests {
use crate::circuit_input_builder::CircuitsParams;
use crate::{
circuit_input_builder::ExecState,
mock::BlockData,
operation::{CallContextField, CallContextOp, StackOp, RW},
};
use eth_types::{
bytecode,
evm_types::{OpcodeId, StackAddress},
geth_types::GethData,
word, Word,
};
use mock::test_ctx::{helpers::*, TestContext};
use pretty_assertions::assert_eq;

#[test]
fn test_ok() {
let return_data_size = 0x20;

// // deployed contract
// PUSH1 0x20
// PUSH1 0
// PUSH1 0
// CALLDATACOPY
// PUSH1 0x20
// PUSH1 0
// RETURN
//
// bytecode: 0x6020600060003760206000F3
//
// // constructor
// PUSH12 0x6020600060003760206000F3
// PUSH1 0
// MSTORE
// PUSH1 0xC
// PUSH1 0x14
// RETURN
//
// bytecode: 0x6B6020600060003760206000F3600052600C6014F3
let code = bytecode! {
PUSH21(word!("6B6020600060003760206000F3600052600C6014F3"))
PUSH1(0)
MSTORE

PUSH1 (0x15)
PUSH1 (0xB)
PUSH1 (0)
CREATE

PUSH1 (0x20)
PUSH1 (0x20)
PUSH1 (0x20)
PUSH1 (0)
PUSH1 (0)
DUP6
PUSH2 (0xFFFF)
CALL

RETURNDATASIZE

STOP
};
// Get the execution steps from the external tracer
let block: GethData = TestContext::<2, 1>::new(
None,
account_0_code_account_1_no_code(code),
tx_from_1_to_0,
|block, _tx| block.number(0xcafeu64),
Comment thread
CPerezz marked this conversation as resolved.
)
.unwrap()
.into();

let mut builder = BlockData::new_from_geth_data_with_params(
block.clone(),
CircuitsParams {
max_rws: 512,
..Default::default()
},
)
.new_circuit_input_builder();
builder
.handle_block(&block.eth_block, &block.geth_traces)
.unwrap();

let step = builder.block.txs()[0]
.steps()
.iter()
.find(|step| step.exec_state == ExecState::Op(OpcodeId::RETURNDATASIZE))
.unwrap();

let call_id = builder.block.txs()[0].calls()[0].call_id;
assert_eq!(
{
let operation =
&builder.block.container.call_context[step.bus_mapping_instance[0].as_usize()];
(operation.rw(), operation.op())
},
(
RW::READ,
&CallContextOp {
call_id,
field: CallContextField::LastCalleeReturnDataLength,
value: Word::from(return_data_size),
}
)
);
assert_eq!(
{
let operation =
&builder.block.container.stack[step.bus_mapping_instance[1].as_usize()];
(operation.rw(), operation.op())
},
(
RW::WRITE,
&StackOp::new(
call_id,
StackAddress::from(1021),
Word::from(return_data_size)
)
)
);
}
}
6 changes: 4 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ mod pc;
mod pop;
mod push;
mod r#return;
mod returndatasize;
mod sdiv_smod;
mod selfbalance;
mod sha3;
Expand Down Expand Up @@ -123,6 +124,7 @@ use pc::PcGadget;
use pop::PopGadget;
use push::PushGadget;
use r#return::ReturnGadget;
use returndatasize::ReturnDataSizeGadget;
use sdiv_smod::SignedDivModGadget;
use selfbalance::SelfbalanceGadget;
use shl_shr::ShlShrGadget;
Expand Down Expand Up @@ -220,7 +222,7 @@ pub(crate) struct ExecutionConfig<F> {
sar_gadget: DummyGadget<F, 2, 1, { ExecutionState::SAR }>,
extcodesize_gadget: DummyGadget<F, 1, 1, { ExecutionState::EXTCODESIZE }>,
extcodecopy_gadget: DummyGadget<F, 4, 0, { ExecutionState::EXTCODECOPY }>,
returndatasize_gadget: DummyGadget<F, 0, 1, { ExecutionState::RETURNDATASIZE }>,
returndatasize_gadget: ReturnDataSizeGadget<F>,
returndatacopy_gadget: DummyGadget<F, 3, 0, { ExecutionState::RETURNDATACOPY }>,
create_gadget: DummyGadget<F, 3, 1, { ExecutionState::CREATE }>,
callcode_gadget: DummyGadget<F, 7, 1, { ExecutionState::CALLCODE }>,
Expand Down Expand Up @@ -980,6 +982,7 @@ impl<F: Field> ExecutionConfig<F> {
ExecutionState::POP => assign_exec_step!(self.pop_gadget),
ExecutionState::PUSH => assign_exec_step!(self.push_gadget),
ExecutionState::RETURN => assign_exec_step!(self.return_gadget),
ExecutionState::RETURNDATASIZE => assign_exec_step!(self.returndatasize_gadget),
ExecutionState::SCMP => assign_exec_step!(self.signed_comparator_gadget),
ExecutionState::SDIV_SMOD => assign_exec_step!(self.sdiv_smod_gadget),
ExecutionState::BLOCKCTXU64 => assign_exec_step!(self.block_ctx_u64_gadget),
Expand All @@ -993,7 +996,6 @@ impl<F: Field> ExecutionConfig<F> {
ExecutionState::SAR => assign_exec_step!(self.sar_gadget),
ExecutionState::EXTCODESIZE => assign_exec_step!(self.extcodesize_gadget),
ExecutionState::EXTCODECOPY => assign_exec_step!(self.extcodecopy_gadget),
ExecutionState::RETURNDATASIZE => assign_exec_step!(self.returndatasize_gadget),
ExecutionState::RETURNDATACOPY => assign_exec_step!(self.returndatacopy_gadget),
ExecutionState::CREATE => assign_exec_step!(self.create_gadget),
ExecutionState::CALLCODE => assign_exec_step!(self.callcode_gadget),
Expand Down
Loading