Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: stack reconstruct #993

Merged
merged 90 commits into from
Feb 7, 2024
Merged
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
91af5ba
init reconstruct
lightsing Oct 7, 2023
94a09a8
add StackPopOnlyOpcode
lightsing Oct 7, 2023
1fa6145
impl arthmetic opcode stack output
lightsing Oct 7, 2023
e54f3ed
impl get block header field opcode
lightsing Oct 8, 2023
b80d86a
impl blockhash
lightsing Oct 8, 2023
675bb28
impl PC, MSIZE, GAS
lightsing Oct 8, 2023
94ae09f
remove StackOnlyOpcode
lightsing Oct 8, 2023
2807586
add strict check
lightsing Oct 8, 2023
f2efe91
impl PUSHn
lightsing Oct 8, 2023
9ad25a0
impl Address
lightsing Oct 8, 2023
49be48c
cleanup stack usage
lightsing Oct 9, 2023
1ac20fc
impl ORIGIN
lightsing Oct 9, 2023
d1c970c
use prestate
lightsing Oct 13, 2023
1af14aa
rename to enable-stack
lightsing Oct 17, 2023
1e19026
cleanup stack usage
lightsing Oct 18, 2023
20a9185
disable trace_tests
lightsing Oct 18, 2023
332b186
fix and add assert
lightsing Oct 19, 2023
5279b69
fix doc test
lightsing Oct 19, 2023
c6cbfbd
fix cfg
lightsing Oct 19, 2023
fd79956
Merge branch 'develop' into feat/stack-reconstruct
lightsing Oct 31, 2023
6b2ad38
use callTracer
lightsing Nov 9, 2023
f083cc1
do not parse call when is_precheck not ok
lightsing Nov 14, 2023
50ebc44
do not parse call in create precheck not ok
lightsing Nov 14, 2023
0cbed73
fix offset
lightsing Nov 14, 2023
4e5a97c
fix compile
lightsing Nov 14, 2023
909a5e7
disable tracer_tests
lightsing Nov 14, 2023
e081e2e
fix test
lightsing Nov 14, 2023
3ebc850
fix caller_address
lightsing Nov 14, 2023
ad13923
fix parse_call
lightsing Nov 14, 2023
781c083
silent more fields
lightsing Nov 14, 2023
b514744
unbound recursion
lightsing Nov 14, 2023
059424c
Merge branch 'develop' into feat/stack-reconstruct
lightsing Nov 15, 2023
8fceb1b
Merge branch 'develop' into calltracer
lightsing Nov 15, 2023
7e0d7db
Merge branch 'develop' into feat/stack-reconstruct
lightsing Nov 15, 2023
631c837
remove stack usage
lightsing Nov 16, 2023
841575d
update LoggerConfig
lightsing Nov 16, 2023
524bbb5
cleanup
lightsing Nov 16, 2023
b4c5578
fix root
lightsing Nov 16, 2023
0a157e5
fix test
lightsing Nov 16, 2023
8389092
fix doc test
lightsing Nov 16, 2023
28ff550
cleanup
lightsing Nov 16, 2023
cd99f3a
upgrade geth version
lightsing Nov 16, 2023
b6f0eaf
add feature switch
lightsing Nov 17, 2023
51cd8bf
add missing
lightsing Nov 20, 2023
ea9fa0a
Merge branch 'develop' into feat/feature-switch
lightsing Nov 22, 2023
1002dfd
add call tracer and prestate tracer
lightsing Nov 23, 2023
e3f284d
handle precheck failed call
lightsing Nov 23, 2023
c3462b0
why ignore not working
lightsing Nov 23, 2023
87e0a80
Merge branch 'develop' into feat/more-tracer
lightsing Nov 24, 2023
1a43b24
Merge branch 'develop' into feat/more-tracer
lightsing Nov 25, 2023
ce1a983
add l2 prestate
lightsing Nov 27, 2023
662e146
use go1.20
lightsing Nov 27, 2023
741ab3a
0x5c/5e assigned by cankun
lightsing Nov 27, 2023
0bf2040
Merge branch 'develop' into feat/more-tracer
lightsing Jan 16, 2024
f83fb1e
update l2geth
lightsing Jan 17, 2024
1f8b769
Merge branch 'feat/more-tracer' into feat/stack-reconstruct
lightsing Jan 18, 2024
813e85a
Merge branch 'develop' into feat/stack-reconstruct
lightsing Jan 24, 2024
8ad89c3
fix merge
lightsing Jan 24, 2024
cfb7286
Merge remote-tracking branch 'origin/develop' into feat/stack-reconst…
lightsing Jan 24, 2024
47d5fb9
clippy
lightsing Jan 24, 2024
93a7a2f
fix call trace
lightsing Jan 24, 2024
0a3eecd
fix call trace
lightsing Jan 24, 2024
254a181
Merge remote-tracking branch 'origin/develop' into feat/stack-reconst…
lightsing Jan 26, 2024
7c84b7c
Merge branch 'develop' into feat/stack-reconstruct
lightsing Jan 30, 2024
bed75af
fix merge
lightsing Jan 30, 2024
54d284d
recover test
lightsing Jan 31, 2024
e17a17b
Merge branch 'develop' into feat/stack-reconstruct
lightsing Jan 31, 2024
0f2f739
Merge branch 'develop' into feat/stack-reconstruct
DreamWuGit Feb 1, 2024
da5e775
fix stack_pointer
lightsing Feb 1, 2024
f4cc230
fix update_codedb
lightsing Feb 2, 2024
47ad1c9
handle last step error
lightsing Feb 5, 2024
da06a66
fix order
lightsing Feb 5, 2024
743dfd1
fix order
lightsing Feb 5, 2024
c94c3ad
skip empty
lightsing Feb 5, 2024
034233a
fix oog step
lightsing Feb 5, 2024
77f5099
fix stack_pointer
lightsing Feb 5, 2024
0298bec
fix create empty
lightsing Feb 5, 2024
31cd64f
fix ErrorCreationCode
lightsing Feb 5, 2024
c6b5a27
try fix call empty
lightsing Feb 5, 2024
5244622
try fix call empty
lightsing Feb 5, 2024
8abb980
fix precompile fail
lightsing Feb 6, 2024
2515b67
fix precompile fail
lightsing Feb 6, 2024
ae9bf5a
fix create in tx
lightsing Feb 6, 2024
4524c75
fix output
lightsing Feb 6, 2024
f644773
fix test
lightsing Feb 6, 2024
ae14318
fix call to self in create
lightsing Feb 7, 2024
86c9a7b
clippy
lightsing Feb 7, 2024
aca05af
Merge branch 'develop' into feat/stack-reconstruct
lightsing Feb 7, 2024
a55b779
downgrade submodule
lightsing Feb 7, 2024
95c5ad6
clippy
lightsing Feb 7, 2024
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
2 changes: 1 addition & 1 deletion bus-mapping/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ rand.workspace = true
rayon.workspace = true

[features]
default = ["test", "enable-stack", "enable-storage"]
default = ["test", "enable-storage"]
test = ["mock", "rand"]
scroll = ["eth-types/scroll", "mock?/scroll"]
# Enable shanghai feature of mock only if mock is enabled (by test).
Expand Down
121 changes: 66 additions & 55 deletions bus-mapping/src/circuit_input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ pub use call::{Call, CallContext, CallKind};
use core::fmt::Debug;
use eth_types::{
self,
evm_types::{GasCost, OpcodeId},
evm_types::GasCost,
geth_types,
sign_types::{pk_bytes_le, pk_bytes_swap_endianness, SignData},
Address, GethExecStep, GethExecTrace, ToBigEndian, ToWord, Word, H256,
Address, GethExecTrace, ToBigEndian, ToWord, Word, H256,
};
use ethers_providers::JsonRpcClient;
pub use execution::{
Expand All @@ -55,6 +55,9 @@ pub use transaction::{
Transaction, TransactionContext, TxL1Fee, TX_L1_COMMIT_EXTRA_COST, TX_L1_FEE_PRECISION,
};

#[cfg(feature = "enable-stack")]
use eth_types::evm_types::OpcodeId;

/// Setup parameters for ECC-related precompile calls.
#[derive(Debug, Clone, Copy)]
pub struct PrecompileEcParams {
Expand Down Expand Up @@ -616,53 +619,58 @@ impl<'a> CircuitInputBuilder {
state_ref.call().map(|c| c.call_id).unwrap_or(0),
state_ref.call_ctx()?.memory.len(),
geth_step.refund.0,
if geth_step.op.is_push_with_data() {
format!("{:?}", geth_trace.struct_logs.get(index + 1).map(|step| step.stack.last()))
} else if geth_step.op.is_call_without_value() {
format!(
"{:?} {:40x} {:?} {:?} {:?} {:?}",
geth_step.stack.last(),
geth_step.stack.nth_last(1).unwrap_or_default(),
geth_step.stack.nth_last(2),
geth_step.stack.nth_last(3),
geth_step.stack.nth_last(4),
geth_step.stack.nth_last(5)
)
} else if geth_step.op.is_call_with_value() {
format!(
"{:?} {:40x} {:?} {:?} {:?} {:?} {:?}",
geth_step.stack.last(),
geth_step.stack.nth_last(1).unwrap_or_default(),
geth_step.stack.nth_last(2),
geth_step.stack.nth_last(3),
geth_step.stack.nth_last(4),
geth_step.stack.nth_last(5),
geth_step.stack.nth_last(6),
)
} else if geth_step.op.is_create() {
format!(
"value {:?} offset {:?} size {:?} {}",
geth_step.stack.last(),
geth_step.stack.nth_last(1),
geth_step.stack.nth_last(2),
if geth_step.op == OpcodeId::CREATE2 {
format!("salt {:?}", geth_step.stack.nth_last(3))
} else {
"".to_string()
}
)
} else if matches!(geth_step.op, OpcodeId::SSTORE) {
format!(
"{:?} {:?} {:?}",
state_ref.call().map(|c| c.address),
geth_step.stack.last(),
geth_step.stack.nth_last(1),
)
} else {
let stack_input_num = 1024 - geth_step.op.valid_stack_ptr_range().1 as usize;
(0..stack_input_num).map(|i|
format!("{:?}", geth_step.stack.nth_last(i))
).collect_vec().join(" ")
{
#[cfg(feature = "enable-stack")]
if geth_step.op.is_push_with_data() {
format!("{:?}", geth_trace.struct_logs.get(index + 1).map(|step| step.stack.last()))
} else if geth_step.op.is_call_without_value() {
format!(
"{:?} {:40x} {:?} {:?} {:?} {:?}",
geth_step.stack.last(),
geth_step.stack.nth_last(1).unwrap_or_default(),
geth_step.stack.nth_last(2),
geth_step.stack.nth_last(3),
geth_step.stack.nth_last(4),
geth_step.stack.nth_last(5)
)
} else if geth_step.op.is_call_with_value() {
format!(
"{:?} {:40x} {:?} {:?} {:?} {:?} {:?}",
geth_step.stack.last(),
geth_step.stack.nth_last(1).unwrap_or_default(),
geth_step.stack.nth_last(2),
geth_step.stack.nth_last(3),
geth_step.stack.nth_last(4),
geth_step.stack.nth_last(5),
geth_step.stack.nth_last(6),
)
} else if geth_step.op.is_create() {
format!(
"value {:?} offset {:?} size {:?} {}",
geth_step.stack.last(),
geth_step.stack.nth_last(1),
geth_step.stack.nth_last(2),
if geth_step.op == OpcodeId::CREATE2 {
format!("salt {:?}", geth_step.stack.nth_last(3))
} else {
"".to_string()
}
)
} else if matches!(geth_step.op, OpcodeId::SSTORE) {
format!(
"{:?} {:?} {:?}",
state_ref.call().map(|c| c.address),
geth_step.stack.last(),
geth_step.stack.nth_last(1),
)
} else {
let stack_input_num = 1024 - geth_step.op.valid_stack_ptr_range().1 as usize;
(0..stack_input_num).map(|i|
format!("{:?}", geth_step.stack.nth_last(i))
).collect_vec().join(" ")
}
#[cfg(not(feature = "enable-stack"))]
"N/A".to_string()
}
);
debug_assert_eq!(
Expand Down Expand Up @@ -910,9 +918,9 @@ pub fn keccak_inputs_tx_circuit(txs: &[geth_types::Transaction]) -> Result<Vec<V
}

/// Retrieve the init_code from memory for {CREATE, CREATE2}
pub fn get_create_init_code(call_ctx: &CallContext, step: &GethExecStep) -> Result<Vec<u8>, Error> {
let offset = step.stack.nth_last(1)?.low_u64() as usize;
let length = step.stack.nth_last(2)?.as_usize();
pub fn get_create_init_code(call_ctx: &CallContext) -> Result<Vec<u8>, Error> {
let offset = call_ctx.stack.nth_last(1)?.low_u64() as usize;
let length = call_ctx.stack.nth_last(2)?.as_usize();

let mem_len = call_ctx.memory.0.len();
let mut result = vec![0u8; length];
Expand All @@ -925,9 +933,12 @@ pub fn get_create_init_code(call_ctx: &CallContext, step: &GethExecStep) -> Resu
}

/// Retrieve the memory offset and length of call.
pub fn get_call_memory_offset_length(step: &GethExecStep, nth: usize) -> Result<(u64, u64), Error> {
let offset = step.stack.nth_last(nth)?;
let length = step.stack.nth_last(nth + 1)?;
pub fn get_call_memory_offset_length(
call_ctx: &CallContext,
nth: usize,
) -> Result<(u64, u64), Error> {
let offset = call_ctx.stack.nth_last(nth)?;
let length = call_ctx.stack.nth_last(nth + 1)?;
if length.is_zero() {
Ok((0, 0))
} else {
Expand Down
6 changes: 4 additions & 2 deletions bus-mapping/src/circuit_input_builder/call.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::CodeSource;
use crate::{exec_trace::OperationRef, Error};
use eth_types::{
evm_types::{Memory, OpcodeId},
evm_types::{Memory, OpcodeId, Stack},
Address, Hash, Word,
};

Expand Down Expand Up @@ -130,7 +130,7 @@ impl Call {
}

/// Context of a [`Call`].
#[derive(Debug, Default)]
#[derive(Debug, Clone, Default)]
pub struct CallContext {
/// Index of call
pub index: usize,
Expand All @@ -143,6 +143,8 @@ pub struct CallContext {
pub call_data: Vec<u8>,
/// memory context of current call
pub memory: Memory,
/// stack context of current call
pub stack: Stack,
/// return data buffer
pub return_data: Vec<u8>,
}
Expand Down
2 changes: 1 addition & 1 deletion bus-mapping/src/circuit_input_builder/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl ExecStep {
ExecStep {
exec_state: ExecState::Op(step.op),
pc: step.pc,
stack_size: step.stack.0.len(),
stack_size: call_ctx.stack.0.len(),
memory_size: call_ctx.memory.len(),
gas_left: step.gas,
gas_cost: step.gas_cost,
Expand Down
Loading
Loading