Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

e2e erc20 transfer proving #127

Closed
wants to merge 105 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
28d3504
fixed clippy and fmt
SwordArt0820 Jan 18, 2022
0486113
fixed clippy and fmt
SwordArt0820 Jan 18, 2022
fb352e6
fixed fmt
SwordArt0820 Jan 18, 2022
800081e
fixed permission for run.sh
SwordArt0820 Jan 18, 2022
f8ee9e2
fixed some issue.
SwordArt0820 Jan 22, 2022
67cb9b9
fixed some issue.
SwordArt0820 Jan 22, 2022
061f1a5
add some text.
SwordArt0820 Jan 22, 2022
13894f9
fixed text issue.
SwordArt0820 Jan 22, 2022
b502e32
shl refactor completed.
AprilLier1504 Jan 22, 2022
f535f70
fixed some issues.
AprilLier1504 Jan 22, 2022
4caa177
Merge remote-tracking branch 'origin/main' into shl_opcode
lispc Feb 9, 2022
29397c2
Merge remote-tracking branch 'origin/main' into shr_new
lispc Feb 9, 2022
52b6206
fix
lispc Feb 9, 2022
0fb9164
fix
lispc Feb 9, 2022
f3548ca
Merge branch 'main' into shr_new
lispc Mar 4, 2022
12a9c23
fix all
lispc Mar 4, 2022
2d67c60
fixed some issue.
SwordArt0820 Jan 22, 2022
841425a
fixed clippy and fmt
SwordArt0820 Jan 18, 2022
e9a57f6
fixed clippy and fmt
SwordArt0820 Jan 18, 2022
2b0b9b4
fixed fmt
SwordArt0820 Jan 18, 2022
03fd7e4
fixed permission for run.sh
SwordArt0820 Jan 18, 2022
cfe8b37
fixed issues and merge main.
SwordArt0820 Mar 9, 2022
63f5107
add some notes
SwordArt0820 Mar 9, 2022
9db111e
fixed clippy.
SwordArt0820 Mar 9, 2022
141e96b
Merge branch 'main' into shr_new
lispc Mar 18, 2022
fbd7133
Merge remote-tracking branch 'scroll/main' into shr_new
lispc Mar 21, 2022
82298a2
lint
lispc Mar 21, 2022
b9ce566
squash
lispc Mar 21, 2022
8464f76
Add circuit ISZERO.
silathdiir Mar 21, 2022
cc2e7c7
Merge remote-tracking branch 'origin/main' into feat/op-is-zero
silathdiir Mar 21, 2022
aaad29d
fix
0xmountaintop Mar 22, 2022
1ce3837
feat: bus-mapping impl for calldataload opcode
roynalnaruto Mar 23, 2022
74dfac5
tests: add tests for calldataload using bus-mapping
roynalnaruto Mar 23, 2022
9bd3342
use scroll/feat/busmapping-calldataload
lispc Mar 23, 2022
40dbb8f
Merge remote-tracking branch 'scroll/feat/busmapping-calldataload' in…
lispc Mar 23, 2022
62ea89c
Merge remote-tracking branch 'upstream/main' into feat/op-is-zero
silathdiir Mar 25, 2022
00a66ba
Merge remote-tracking branch 'origin/main' into feat/a_small_target
lispc Mar 25, 2022
7ebc3d8
sstore&sload bus-mapping done! with random multi getter/setter contra…
lispc Mar 25, 2022
86a6ce3
fix
lispc Mar 25, 2022
89c3893
Merge remote-tracking branch 'origin/main' into shr_new
lispc Mar 25, 2022
3c48cb1
Merge branch 'shr_new' into feat/a_small_target
lispc Mar 25, 2022
776d748
Add OpenZeppelin ERC20 transfers integration test
ed255 Mar 23, 2022
c7c6484
Merge branch 'main' into feat/busmapping-calldataload
roynalnaruto Mar 27, 2022
a34d97b
Merge remote-tracking branch 'origin/feature/integration-test-openzep…
lispc Mar 28, 2022
dc13699
fix build
lispc Mar 28, 2022
cb9e122
add dummpy op
lispc Mar 28, 2022
47ae3c3
Merge remote-tracking branch 'scroll/feat/op-is-zero' into feat/e2e_c…
lispc Mar 28, 2022
5d29d25
fix
lispc Mar 29, 2022
1ccc1c6
fix
lispc Mar 29, 2022
8b3a625
fix
lispc Mar 29, 2022
87db38e
prover cmd
lispc Mar 29, 2022
32019d8
.
lispc Mar 29, 2022
97e4821
Merge remote-tracking branch 'origin/main' into feat/e2e_call_erc20
lispc Mar 30, 2022
d38ddab
simplify sstore refund
lispc Mar 31, 2022
f440f77
Merge remote-tracking branch 'origin/main' into feat/e2e_call_erc20
lispc Mar 31, 2022
6a2e0b3
Merge remote-tracking branch 'origin/main' into feat/busmapping-calld…
lispc Mar 31, 2022
b2f80fa
fix
lispc Mar 31, 2022
c9a3296
remove some comments
lispc Mar 31, 2022
9456fc5
Merge remote-tracking branch 'scroll/feat/busmapping-calldataload' in…
lispc Mar 31, 2022
fe2cc6e
lint
lispc Mar 31, 2022
b7b83af
lint
lispc Mar 31, 2022
b60acb2
fix revert
lispc Apr 1, 2022
6e5ccd8
remove boilerplate in bus mapping tests
lispc Apr 1, 2022
1c924fd
clean and ready for PR
lispc Apr 1, 2022
e47613b
pick
lispc Apr 1, 2022
1079392
change geth to nightly in integration-tests
lispc Apr 1, 2022
a891164
Merge remote-tracking branch 'origin/main' into feat/sstore_busmapping
lispc Apr 1, 2022
cc52cde
Merge remote-tracking branch 'origin/main' into feat/e2e_call_erc20
lispc Apr 1, 2022
078992b
fix conflict
lispc Apr 1, 2022
ad23f67
clea
lispc Apr 1, 2022
3419920
Merge remote-tracking branch 'origin/main' into feat/sstore_busmapping
lispc Apr 4, 2022
2077c0e
fix conflict
lispc Apr 4, 2022
2ba341d
minor
lispc Apr 4, 2022
c03ac9c
Merge branch 'main' into feat/sstore_busmapping
lispc Apr 5, 2022
11534d4
fix conflict
lispc Apr 5, 2022
6778b3a
Merge branch 'main' into feat/sstore_busmapping
lispc Apr 5, 2022
51ebd65
Merge branch 'feat/sstore_busmapping' into feat/e2e_call_erc20
lispc Apr 5, 2022
70308c6
fixing
lispc Apr 5, 2022
6945a25
Merge remote-tracking branch 'origin/main' into shr_new
lispc Apr 5, 2022
8825859
fix conflict
lispc Apr 5, 2022
1ff0c82
fix conflict
lispc Apr 5, 2022
709a393
fix conflict
lispc Apr 5, 2022
8adf82e
Merge branch 'shr_new' into feat/e2e_call_erc20
lispc Apr 5, 2022
4b85091
fix conflict
lispc Apr 5, 2022
0337ff8
.
lispc Apr 5, 2022
27bcc23
add busmapping for sstore and rewrite tests
lispc Apr 7, 2022
7ecb049
tests pass
lispc Apr 7, 2022
c44228d
tests pass
lispc Apr 7, 2022
46e7c78
fix
lispc Apr 7, 2022
ef48eb1
Merge remote-tracking branch 'origin/main' into shr_new
lispc Apr 7, 2022
7e9e70f
migrate sload tests to bus-mapping
lispc Apr 7, 2022
f7f6ae4
lint
lispc Apr 7, 2022
8c8dfbe
Merge remote-tracking branch 'scroll/shl_opcode' into shr_new
lispc Apr 7, 2022
81de62d
fix
lispc Apr 7, 2022
680b145
fix
lispc Apr 7, 2022
1b0db6c
fix shl
lispc Apr 7, 2022
8af9c62
fix revert
lispc Apr 7, 2022
c8bb0de
Merge branch 'feat/sstore_busmapping' into feat/e2e_call_erc20
lispc Apr 7, 2022
fb4e0e4
Merge remote-tracking branch 'scroll/shl_shr_new' into feat/e2e_call_…
lispc Apr 7, 2022
0caa2f4
sync
lispc Apr 7, 2022
09a2eac
dummpy code copy
lispc Apr 7, 2022
0ed63f6
minor
lispc Apr 7, 2022
dc688ec
no need to apply read op
lispc Apr 7, 2022
7fbc3ee
Merge branch 'feat/sstore_busmapping' into feat/e2e_call_erc20
lispc Apr 7, 2022
dc1ebc7
fix merge
lispc Apr 7, 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: 4 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ test: ## Run tests for all the workspace members
test_benches: ## Compiles the benchmarks
@cargo test --verbose --release --all-features -p circuit-benchmarks --no-run

test-doc:
@cargo test --release --all --all-features --doc

test-all: fmt doc clippy test_benches test ## Run all the CI checks locally (in your actual toolchain)

evm_bench: ## Run Evm Circuit benchmarks
Expand Down
1 change: 1 addition & 0 deletions bus-mapping/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ serde_json = "1.0.66"
[dev-dependencies]
mock = { path = "../mock" }
pretty_assertions = "1.0.0"
rand = "0.8"
tokio = { version = "1.13", features = ["macros"] }
url = "2.2.2"
65 changes: 34 additions & 31 deletions bus-mapping/src/circuit_input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ pub struct ExecStep {
/// overflow", this value will **not** be the actual Gas cost of the
/// step.
pub gas_cost: GasCost,
/// Accumulated gas refund
pub gas_refund: Gas,
/// Call index within the [`Transaction`]
pub call_index: usize,
/// The global counter when this step was executed.
Expand Down Expand Up @@ -204,6 +206,7 @@ impl ExecStep {
memory_size: step.memory.0.len(),
gas_left: step.gas,
gas_cost: step.gas_cost,
gas_refund: Gas(0),
call_index,
rwc,
reversible_write_counter,
Expand All @@ -223,6 +226,7 @@ impl Default for ExecStep {
memory_size: 0,
gas_left: Gas(0),
gas_cost: GasCost(0),
gas_refund: Gas(0),
call_index: 0,
rwc: RWCounter(0),
reversible_write_counter: 0,
Expand Down Expand Up @@ -805,6 +809,9 @@ impl<'a> CircuitInputStateRef<'a> {
rw: RW,
op: T,
) -> Result<(), Error> {
if matches!(rw, RW::WRITE) {
self.apply_op(&op.clone().into_enum());
}
let op_ref = self.block.container.insert(Operation::new_reversible(
self.block_ctx.rwc.inc_pre(),
rw,
Expand Down Expand Up @@ -1076,38 +1083,29 @@ impl<'a> CircuitInputStateRef<'a> {
}
}

/// Apply reverted op to state and push to container.
fn apply_reverted_op(&mut self, op: OpEnum) -> OperationRef {
match op {
/// Apply op to state.
fn apply_op(&mut self, op: &OpEnum) {
match &op {
OpEnum::Storage(op) => {
let (_, account) = self.sdb.get_storage_mut(&op.address, &op.key);
*account = op.value;
self.block.container.insert(Operation::new(
self.block_ctx.rwc.inc_pre(),
RW::WRITE,
op,
))
self.sdb.set_storage(&op.address, &op.key, &op.value);
}
OpEnum::TxAccessListAccount(op) => {
if !op.value {
if !op.value_prev && op.value {
self.sdb.add_account_to_access_list(op.address);
}
if op.value_prev && !op.value {
self.sdb.remove_account_from_access_list(&op.address);
}
self.block.container.insert(Operation::new(
self.block_ctx.rwc.inc_pre(),
RW::WRITE,
op,
))
}
OpEnum::TxAccessListAccountStorage(op) => {
if !op.value {
if !op.value_prev && op.value {
self.sdb
.add_account_storage_to_access_list((op.address, op.key));
}
if op.value_prev && !op.value {
self.sdb
.remove_account_storage_from_access_list(&(op.address, op.key));
}
self.block.container.insert(Operation::new(
self.block_ctx.rwc.inc_pre(),
RW::WRITE,
op,
))
}
OpEnum::Account(op) => {
let (_, account) = self.sdb.get_account_mut(&op.address);
Expand All @@ -1118,16 +1116,13 @@ impl<'a> CircuitInputStateRef<'a> {
account.code_hash = op.value.to_be_bytes().into();
}
}
self.block.container.insert(Operation::new(
self.block_ctx.rwc.inc_pre(),
RW::WRITE,
op,
))
}
OpEnum::TxRefund(_) => unimplemented!(),
OpEnum::TxRefund(op) => {
self.sdb.set_refund(op.value);
}
OpEnum::AccountDestructed(_) => unimplemented!(),
_ => unreachable!(),
}
};
}

/// Handle a reversion group
Expand All @@ -1141,7 +1136,13 @@ impl<'a> CircuitInputStateRef<'a> {
// Apply reversions
for (step_index, op_ref) in reversion_group.op_refs.into_iter().rev() {
if let Some(op) = self.get_rev_op_by_ref(&op_ref) {
let rev_op_ref = self.apply_reverted_op(op);
self.apply_op(&op);
let rev_op_ref = self.block.container.insert_op_enum(
self.block_ctx.rwc.inc_pre(),
RW::WRITE,
false,
op,
);
self.tx.steps[step_index]
.bus_mapping_instance
.push(rev_op_ref);
Expand Down Expand Up @@ -1473,6 +1474,7 @@ impl<'a> CircuitInputBuilder {

for (index, geth_step) in geth_trace.struct_logs.iter().enumerate() {
let mut state_ref = self.state_ref(&mut tx, &mut tx_ctx);
log::trace!("handle {}th opcode {:?} ", index, geth_step.op);
let exec_steps = gen_associated_ops(
&geth_step.op,
&mut state_ref,
Expand All @@ -1488,8 +1490,8 @@ impl<'a> CircuitInputBuilder {
let end_tx_step = gen_end_tx_ops(&mut self.state_ref(&mut tx, &mut tx_ctx))?;
tx.steps.push(end_tx_step);

self.sdb.commit_tx();
self.block.txs.push(tx);
self.sdb.clear_access_list_and_refund();

Ok(())
}
Expand Down Expand Up @@ -2004,6 +2006,7 @@ mod tracer_tests {
&GethExecTrace {
gas: Gas(0),
failed: false,
return_value: "".to_owned(),
struct_logs: vec![geth_step.clone()],
},
false,
Expand Down
15 changes: 11 additions & 4 deletions bus-mapping/src/evm/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ use eth_types::{
use keccak256::EMPTY_HASH;
use log::warn;

#[cfg(test)]
mod test_util;

mod call;
mod calldatacopy;
mod calldataload;
mod calldatasize;
mod caller;
mod callvalue;
Expand All @@ -30,12 +34,14 @@ mod number;
mod origin;
mod selfbalance;
mod sload;
mod sstore;
mod stackonlyop;
mod stop;
mod swap;

use call::Call;
use calldatacopy::Calldatacopy;
use calldataload::Calldataload;
use calldatasize::Calldatasize;
use caller::Caller;
use callvalue::Callvalue;
Expand All @@ -47,6 +53,7 @@ use mstore::Mstore;
use origin::Origin;
use selfbalance::Selfbalance;
use sload::Sload;
use sstore::Sstore;
use stackonlyop::StackOnlyOpcode;
use stop::Stop;
use swap::Swap;
Expand Down Expand Up @@ -106,14 +113,14 @@ fn fn_gen_associated_ops(opcode_id: &OpcodeId) -> FnGenAssociatedOps {
OpcodeId::SHL => StackOnlyOpcode::<2, 1>::gen_associated_ops,
OpcodeId::SHR => StackOnlyOpcode::<2, 1>::gen_associated_ops,
OpcodeId::SAR => StackOnlyOpcode::<2, 1>::gen_associated_ops,
// OpcodeId::SHA3 => {},
OpcodeId::SHA3 => StackOnlyOpcode::<2, 1>::gen_associated_ops,
// OpcodeId::ADDRESS => {},
// OpcodeId::BALANCE => {},
OpcodeId::ORIGIN => Origin::gen_associated_ops,
OpcodeId::CALLER => Caller::gen_associated_ops,
OpcodeId::CALLVALUE => Callvalue::gen_associated_ops,
OpcodeId::CALLDATASIZE => Calldatasize::gen_associated_ops,
OpcodeId::CALLDATALOAD => StackOnlyOpcode::<1, 1>::gen_associated_ops,
OpcodeId::CALLDATALOAD => Calldataload::gen_associated_ops,
OpcodeId::CALLDATACOPY => Calldatacopy::gen_associated_ops,
// OpcodeId::CODESIZE => {},
// OpcodeId::CODECOPY => {},
Expand All @@ -137,7 +144,7 @@ fn fn_gen_associated_ops(opcode_id: &OpcodeId) -> FnGenAssociatedOps {
OpcodeId::MSTORE => Mstore::<false>::gen_associated_ops,
OpcodeId::MSTORE8 => Mstore::<true>::gen_associated_ops,
OpcodeId::SLOAD => Sload::gen_associated_ops,
// OpcodeId::SSTORE => {},
OpcodeId::SSTORE => Sstore::gen_associated_ops,
OpcodeId::JUMP => StackOnlyOpcode::<1, 0>::gen_associated_ops,
OpcodeId::JUMPI => StackOnlyOpcode::<2, 0>::gen_associated_ops,
OpcodeId::PC => StackOnlyOpcode::<0, 1>::gen_associated_ops,
Expand Down Expand Up @@ -211,7 +218,7 @@ fn fn_gen_associated_ops(opcode_id: &OpcodeId) -> FnGenAssociatedOps {
// OpcodeId::LOG0 => {},
// OpcodeId::LOG1 => {},
// OpcodeId::LOG2 => {},
// OpcodeId::LOG3 => {},
OpcodeId::LOG3 => StackOnlyOpcode::<5, 0>::gen_associated_ops,
// OpcodeId::LOG4 => {},
// OpcodeId::CREATE => {},
OpcodeId::CALL => Call::gen_associated_ops,
Expand Down
35 changes: 7 additions & 28 deletions bus-mapping/src/evm/opcodes/calldatacopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,18 +158,15 @@ fn gen_memory_copy_steps(
#[cfg(test)]
mod calldatacopy_tests {
use crate::{
circuit_input_builder::ExecState,
mock::BlockData,
evm::opcodes::test_util::TestCase,
operation::{CallContextField, CallContextOp, StackOp, RW},
};
use eth_types::{
bytecode,
evm_types::{OpcodeId, StackAddress},
geth_types::GethData,
Word,
};

use mock::test_ctx::{helpers::*, TestContext};
use pretty_assertions::assert_eq;

#[test]
Expand All @@ -182,30 +179,13 @@ mod calldatacopy_tests {
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),
)
.unwrap()
.into();

let mut builder = BlockData::new_from_geth_data(block.clone()).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::CALLDATACOPY))
.unwrap();
let test = TestCase::new_from_bytecode(code);
let step = test.step_witness(OpcodeId::CALLDATACOPY, 0);
let call_id = test.tx_witness().calls()[0].call_id;

assert_eq!(
[0, 1, 2]
.map(|idx| &builder.block.container.stack[step.bus_mapping_instance[idx].as_usize()])
.map(|idx| &step.rws.stack[idx])
.map(|operation| (operation.rw(), operation.op())),
[
(
Expand All @@ -225,14 +205,13 @@ mod calldatacopy_tests {

assert_eq!(
{
let operation =
&builder.block.container.call_context[step.bus_mapping_instance[3].as_usize()];
let operation = &step.rws.call_context[0];
(operation.rw(), operation.op())
},
(
RW::READ,
&CallContextOp {
call_id: builder.block.txs()[0].calls()[0].call_id,
call_id,
field: CallContextField::TxId,
value: Word::from(1),
}
Expand Down
Loading