Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 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
89c3893
Merge remote-tracking branch 'origin/main' into shr_new
lispc Mar 25, 2022
6945a25
Merge remote-tracking branch 'origin/main' into shr_new
lispc Apr 5, 2022
8825859
fix conflict
lispc Apr 5, 2022
ef48eb1
Merge remote-tracking branch 'origin/main' into shr_new
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
aba5031
feat: implement STOP
han0110 Apr 2, 2022
b11beab
feat: fully implement STOP with support of index code out of range
han0110 Apr 14, 2022
86e7dfa
refactor: use less gas for call_gadget_recursive to speedup testing
han0110 Apr 14, 2022
80395e9
feat: enable first and last step ExecutionState cehck
han0110 Apr 14, 2022
e20ff81
Merge remote-tracking branch 'origin/main' into shl_shr_new
silathdiir Apr 28, 2022
1f6b71c
Refactor StateCircuit + add lexicographic ordering constraints
Apr 5, 2022
91b597c
Implement first_access method and fix stack change constraint
Apr 5, 2022
9e02cf7
Cleanup and comment out failing constraint
Apr 5, 2022
c229538
Fix failing tests by correctly getting limbs in be order in lexicogra…
Apr 5, 2022
cd33700
fix clippy
Apr 7, 2022
2463564
Rename test files for clippy
Apr 7, 2022
6691a40
Cleanup benchmarks
Apr 7, 2022
79b13a4
fix build
Apr 7, 2022
8705dc9
Assign diff_inverse correctly
Apr 7, 2022
70e89df
Fix instance function and convert it to a method
Apr 11, 2022
de263c3
Fix storage_key_be_limbs method
Apr 11, 2022
336970e
Add degree test
Apr 11, 2022
7ecf7e4
Have StateCircuit use Vec<Rw> instead of RwMap
Apr 13, 2022
3a8696b
Compute first_access correctly
Apr 13, 2022
2343153
wip, but tests pass
Apr 13, 2022
2599790
Fix diff_2 assignment
Apr 13, 2022
db16340
cleanup
Apr 13, 2022
81acc69
Use verify_at_rows to speed up tests and derive EnumIter
Apr 14, 2022
6331061
Add cleanup and explain diff_1 and diff_2
Apr 15, 2022
eb88bc4
cleanup
Apr 28, 2022
6e8e98b
fmt
Apr 28, 2022
3e04822
Add newline to fix cargo fmt
Apr 28, 2022
805aa86
Fix degree test and TxLog table assignment
Apr 29, 2022
ca0cf8c
Cleanup and change index type to u8 from usize
Apr 29, 2022
b2ac127
Rename to diff_1->upper_limb_difference and diff_2->lower_limb_differ…
Apr 29, 2022
e7d2527
Explain assignment in comments
May 2, 2022
b83cef8
Merge branch 'main' into feat/state_circuit_refactor
z2trillion May 2, 2022
09c1b24
Merge branch 'main' into feat/state_circuit_refactor
z2trillion May 4, 2022
4ab357f
Merge remote-tracking branch 'origin/main' into feat/state_circuit_re…
lispc May 4, 2022
d2d337a
fix conflicts
lispc May 4, 2022
47fcb9c
Merge branch 'feat/state_circuit_refactor' of github.com:scroll-tech/…
lispc May 4, 2022
5f5264c
Merge branch 'main' into feat/state_circuit_refactor
z2trillion May 4, 2022
02f7b2a
Merge branch 'main' into feat/state_circuit_refactor
z2trillion May 4, 2022
378eda8
Merge branch 'main' into feat/state_circuit_refactor
z2trillion May 5, 2022
6b18a49
Merge branch 'main' into feat/state_circuit_refactor
lispc May 9, 2022
424b5f5
lint
lispc May 9, 2022
fddb8c5
Merge remote-tracking branch 'origin/main' into shl_shr_new
lispc May 9, 2022
9662079
Merge branch 'shl_shr_new' into scroll-dev-0508-base2
lispc May 9, 2022
0a1ce20
Merge remote-tracking branch 'han/feature/stop' into scroll-dev-0508-…
lispc May 9, 2022
efaa3da
new state + shr_shl + stop
lispc May 9, 2022
7c9000e
squash
lispc May 9, 2022
396632a
clean
lispc May 9, 2022
ccbef49
clean tests
lispc May 9, 2022
eb00c1e
lint
lispc May 9, 2022
ae82862
spelling
lispc May 12, 2022
366044c
lint
lispc May 12, 2022
d2395d0
Merge branch 'scroll-dev-0508-base' into scroll-dev-0508
lispc May 12, 2022
60eb5f3
lint
lispc May 12, 2022
87b9f40
failing
lispc May 12, 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
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ help: ## Display this help screen

clippy: ## Run clippy checks over all workspace members
@cargo check --all-features
@cargo clippy --all-features --all-targets -- -D clippy::all
@cargo clippy --all-features --all-targets -- -D warnings

doc: ## Generate and tests docs including private items
@cargo doc --no-deps --all --document-private-items
Expand All @@ -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
15 changes: 13 additions & 2 deletions bus-mapping/src/circuit_input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ pub use access::{Access, AccessSet, AccessValue, CodeSource};
pub use block::{Block, BlockContext};
pub use call::{Call, CallContext, CallKind};
use core::fmt::Debug;
use eth_types::{self, Address, GethExecStep, GethExecTrace, Word};
use eth_types::evm_types::GasCost;
use eth_types::{self, Address, GethExecStep, GethExecTrace, ToWord, Word};
use ethers_providers::JsonRpcClient;
pub use execution::{CopyDetails, ExecState, ExecStep, StepAuxiliaryData};
pub use input_state_ref::CircuitInputStateRef;
Expand Down Expand Up @@ -167,11 +168,21 @@ impl<'a> CircuitInputBuilder {
let mut tx = self.new_tx(eth_tx, !geth_trace.failed)?;
let mut tx_ctx = TransactionContext::new(eth_tx, geth_trace, is_last_tx)?;

if let Some(al) = &eth_tx.access_list {
for item in &al.0 {
self.sdb.add_account_to_access_list(item.address);
for k in &item.storage_keys {
self.sdb
.add_account_storage_to_access_list((item.address, (*k).to_word()));
}
}
}
// TODO: Move into gen_associated_steps with
// - execution_state: BeginTx
// - op: None
// Generate BeginTx step
let begin_tx_step = gen_begin_tx_ops(&mut self.state_ref(&mut tx, &mut tx_ctx))?;
let mut begin_tx_step = gen_begin_tx_ops(&mut self.state_ref(&mut tx, &mut tx_ctx))?;
begin_tx_step.gas_cost = GasCost(tx.gas - geth_trace.struct_logs[0].gas.0);
tx.steps_mut().push(begin_tx_step);

for (index, geth_step) in geth_trace.struct_logs.iter().enumerate() {
Expand Down
12 changes: 12 additions & 0 deletions bus-mapping/src/circuit_input_builder/input_state_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,13 @@ impl<'a> CircuitInputStateRef<'a> {
.ok_or(Error::CodeNotFound(code_hash))
}

/// Reference to the caller's Call
pub fn caller(&self) -> Result<&Call, Error> {
self.tx_ctx
.caller_index()
.map(|caller_idx| &self.tx.calls()[caller_idx])
}

/// Reference to the current Call
pub fn call(&self) -> Result<&Call, Error> {
self.tx_ctx
Expand All @@ -294,6 +301,11 @@ impl<'a> CircuitInputStateRef<'a> {
self.tx_ctx.call_ctx()
}

/// Reference to the current CallContext
pub fn caller_ctx(&self) -> Result<&CallContext, Error> {
self.tx_ctx.caller_ctx()
}

/// Mutable reference to the call CallContext
pub fn call_ctx_mut(&mut self) -> Result<&mut CallContext, Error> {
self.tx_ctx.call_ctx_mut()
Expand Down
14 changes: 12 additions & 2 deletions bus-mapping/src/circuit_input_builder/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,24 @@ impl TransactionContext {
&self.calls
}

/// Return the index of the caller (the second last call in the call stack).
pub fn caller_index(&self) -> Result<usize, Error> {
self.caller_ctx().map(|call| call.index)
}

/// Return the index of the current call (the last call in the call stack).
pub(crate) fn call_index(&self) -> Result<usize, Error> {
self.call_ctx().map(|call| call.index)
}

pub(crate) fn caller_ctx(&self) -> Result<&CallContext, Error> {
self.calls
.last()
.len()
.checked_sub(2)
.map(|idx| &self.calls[idx])
.ok_or(Error::InvalidGethExecTrace(
"Call stack is empty but call is used",
))
.map(|call| call.index)
}

pub(crate) fn call_ctx(&self) -> Result<&CallContext, Error> {
Expand Down
12 changes: 7 additions & 5 deletions bus-mapping/src/evm/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ mod mload;
mod mstore;
mod number;
mod origin;
mod r#return;
mod selfbalance;
mod sload;
mod sstore;
Expand All @@ -52,6 +53,7 @@ use gasprice::GasPrice;
use mload::Mload;
use mstore::Mstore;
use origin::Origin;
use r#return::Return;
use selfbalance::Selfbalance;
use sload::Sload;
use sstore::Sstore;
Expand Down Expand Up @@ -118,7 +120,7 @@ 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,
Expand Down Expand Up @@ -191,18 +193,18 @@ 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,
// OpcodeId::CALLCODE => {},
// TODO: Handle RETURN by its own gen_associated_ops.
OpcodeId::RETURN => Stop::gen_associated_ops,
// TODO: Fully implement RETURN.
OpcodeId::RETURN => Return::gen_associated_ops,
// OpcodeId::DELEGATECALL => {},
// OpcodeId::CREATE2 => {},
// OpcodeId::STATICCALL => {},
// TODO: Handle REVERT by its own gen_associated_ops.
OpcodeId::REVERT => Stop::gen_associated_ops,
OpcodeId::REVERT => Return::gen_associated_ops,
// OpcodeId::SELFDESTRUCT => {},
OpcodeId::CALLCODE | OpcodeId::DELEGATECALL | OpcodeId::STATICCALL => {
warn!("Using dummy gen_call_ops for opcode {:?}", opcode_id);
Expand Down
2 changes: 1 addition & 1 deletion bus-mapping/src/evm/opcodes/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl Opcode for Call {
),
(CallContextField::MemorySize, next_memory_word_size.into()),
(
CallContextField::StateWriteCounter,
CallContextField::ReversibleWriteCounter,
(exec_step.reversible_write_counter + 1).into(),
),
] {
Expand Down
20 changes: 20 additions & 0 deletions bus-mapping/src/evm/opcodes/return.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use super::Opcode;
use crate::circuit_input_builder::{CircuitInputStateRef, ExecStep};
use crate::Error;
use eth_types::GethExecStep;

/// Placeholder structure used to implement [`Opcode`] trait over it
/// corresponding to the [`OpcodeId::RETURN`](crate::evm::OpcodeId::RETURN).
#[derive(Debug, Copy, Clone)]
pub(crate) struct Return;

impl Opcode for Return {
fn gen_associated_ops(
state: &mut CircuitInputStateRef,
geth_steps: &[GethExecStep],
) -> Result<Vec<ExecStep>, Error> {
let exec_step = state.new_step(&geth_steps[0])?;
state.handle_return()?;
Ok(vec![exec_step])
}
}
100 changes: 96 additions & 4 deletions bus-mapping/src/evm/opcodes/stop.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use super::Opcode;
use crate::circuit_input_builder::{CircuitInputStateRef, ExecStep};
use crate::Error;
use eth_types::GethExecStep;
use crate::{
circuit_input_builder::{CircuitInputStateRef, ExecStep},
operation::{CallContextField, CallContextOp, RW},
Error,
};
use eth_types::{GethExecStep, ToWord};

/// Placeholder structure used to implement [`Opcode`] trait over it
/// corresponding to the [`OpcodeId::STOP`](crate::evm::OpcodeId::STOP)
Expand All @@ -17,8 +20,97 @@ impl Opcode for Stop {
state: &mut CircuitInputStateRef,
geth_steps: &[GethExecStep],
) -> Result<Vec<ExecStep>, Error> {
let exec_step = state.new_step(&geth_steps[0])?;
let geth_step = &geth_steps[0];
let mut exec_step = state.new_step(geth_step)?;

let call = state.call()?.clone();

state.push_op(
&mut exec_step,
RW::READ,
CallContextOp {
call_id: call.call_id,
field: CallContextField::IsSuccess,
value: 1.into(),
},
);

if call.is_root {
state.push_op(
&mut exec_step,
RW::READ,
CallContextOp {
call_id: call.call_id,
field: CallContextField::IsPersistent,
value: 1.into(),
},
);
} else {
let caller = state.caller()?.clone();
state.push_op(
&mut exec_step,
RW::READ,
CallContextOp {
call_id: call.call_id,
field: CallContextField::CallerId,
value: caller.call_id.into(),
},
);

let geth_step_next = &geth_steps[1];
let caller_gas_left = geth_step_next.gas.0 - geth_step.gas.0;
for (field, value) in [
(CallContextField::IsRoot, (caller.is_root as u64).into()),
(
CallContextField::IsCreate,
(caller.is_create() as u64).into(),
),
(CallContextField::CodeSource, caller.code_hash.to_word()),
(CallContextField::ProgramCounter, geth_step_next.pc.0.into()),
(
CallContextField::StackPointer,
geth_step_next.stack.stack_pointer().0.into(),
),
(CallContextField::GasLeft, caller_gas_left.into()),
(
CallContextField::MemorySize,
geth_step_next.memory.word_size().into(),
),
(
CallContextField::ReversibleWriteCounter,
state.caller_ctx()?.reversible_write_counter.into(),
),
] {
state.push_op(
&mut exec_step,
RW::READ,
CallContextOp {
call_id: caller.call_id,
field,
value,
},
);
}

for (field, value) in [
(CallContextField::LastCalleeId, call.call_id.into()),
(CallContextField::LastCalleeReturnDataOffset, 0.into()),
(CallContextField::LastCalleeReturnDataLength, 0.into()),
] {
state.push_op(
&mut exec_step,
RW::WRITE,
CallContextOp {
call_id: caller.call_id,
field,
value,
},
);
}
}

state.handle_return()?;

Ok(vec![exec_step])
}
}
4 changes: 2 additions & 2 deletions bus-mapping/src/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,8 @@ pub enum CallContextField {
GasLeft,
/// MemorySize
MemorySize,
/// StateWriteCounter
StateWriteCounter,
/// ReversibleWriteCounter
ReversibleWriteCounter,
}

/// Represents an CallContext read/write operation.
Expand Down
2 changes: 1 addition & 1 deletion circuit-benchmarks/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::io::Write;

fn main() {
let degree: usize = var("DEGREE")
.unwrap_or_else(|_| "11".to_string())
.unwrap_or_else(|_| "17".to_string())
.parse()
.expect("Cannot parse DEGREE env var as usize");

Expand Down
23 changes: 18 additions & 5 deletions integration-tests/src/bin/gen_blockchain_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use ethers::{
},
core::utils::WEI_IN_ETHER,
middleware::SignerMiddleware,
prelude::NonceManagerMiddleware,
providers::{Middleware, PendingTransaction},
signers::Signer,
solc::Solc,
Expand Down Expand Up @@ -54,7 +55,7 @@ where
.method::<_, bool>("transfer", (to, amount))
.expect("cannot construct ERC20 transfer call");
// Set gas to avoid `eth_estimateGas` call
let call = call.legacy();
//let call = call.legacy();
let call = call.gas(100_000);
call.tx
}
Expand Down Expand Up @@ -172,7 +173,10 @@ async fn main() {
//

let mut deployments = HashMap::new();
let prov_wallet0 = Arc::new(SignerMiddleware::new(get_provider(), wallet0));
let prov_wallet0 = Arc::new(NonceManagerMiddleware::new(
SignerMiddleware::new(get_provider(), wallet0.clone()),
wallet0.address(),
));

// Greeter
let contract = deploy(
Expand All @@ -194,7 +198,7 @@ async fn main() {
contracts
.get("OpenZeppelinERC20TestToken")
.expect("contract not found"),
prov_wallet0.address(),
wallet0.address(),
)
.await;
let block_num = prov.get_block_number().await.expect("cannot get block_num");
Expand Down Expand Up @@ -325,14 +329,17 @@ async fn main() {
for (i, (from_i, to_i)) in [(0, 1), (2, 3), (1, 0), (3, 2)].iter().enumerate() {
let amount = U256::from(0x800000000000000 / (i + 1));
let prov_wallet = &wallets[*from_i];
let tx = erc20_transfer(
let mut tx = erc20_transfer(
prov_wallet.clone(),
contract_address,
contract_abi,
wallets[*to_i].address(),
amount,
);

prov_wallet.fill_transaction(&mut tx, None).await.unwrap();
tx.set_gas(100_000u64);

let pending_tx = prov_wallet
.send_transaction(tx, None)
.await
Expand All @@ -345,7 +352,13 @@ async fn main() {
let pending_tx = PendingTransaction::new(*tx_hash, wallets[i].inner());
let receipt = pending_tx.confirmations(0usize).await.unwrap().unwrap();
let expected_status = if i % 2 == 0 { 1u64 } else { 0u64 };
assert_eq!(receipt.status, Some(U64::from(expected_status)));
assert_eq!(
receipt.status,
Some(U64::from(expected_status)),
"failed tx hash: {:?}, receipt: {:#?}",
tx_hash,
receipt
);
}
let block_num = prov.get_block_number().await.expect("cannot get block_num");
blocks.insert(
Expand Down
Loading