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

Commit 7dad9b1

Browse files
authored
Merge branch 'scroll-stable' into goerli-0215
2 parents 3395fe1 + ab05f73 commit 7dad9b1

File tree

21 files changed

+276
-52
lines changed

21 files changed

+276
-52
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bus-mapping/src/circuit_input_builder.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,7 @@ impl<'a> CircuitInputBuilder {
368368
state_ref.call().map(|c| c.call_id).unwrap_or(0),
369369
state_ref.call_ctx()?.memory.len(),
370370
if geth_step.op.is_push() {
371-
match geth_step.stack.last() {
372-
Ok(w) => format!("{:?}", w),
373-
Err(_) => "".to_string(),
374-
}
371+
format!("{:?}", geth_trace.struct_logs[index + 1].stack.last())
375372
} else if geth_step.op.is_call_without_value() {
376373
format!(
377374
"{:?} {:40x} {:?} {:?} {:?} {:?}",
@@ -427,11 +424,13 @@ impl<'a> CircuitInputBuilder {
427424
// - execution_state: EndTx
428425
// - op: None
429426
// Generate EndTx step
427+
log::trace!("gen_end_tx_ops");
430428
let end_tx_step = gen_end_tx_ops(&mut self.state_ref(&mut tx, &mut tx_ctx))?;
431429
tx.steps_mut().push(end_tx_step);
432430

433431
self.sdb.commit_tx();
434432
self.block.txs.push(tx);
433+
log::trace!("handle_tx finished");
435434

436435
Ok(())
437436
}

bus-mapping/src/circuit_input_builder/input_state_ref.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -732,9 +732,10 @@ impl<'a> CircuitInputStateRef<'a> {
732732
} else {
733733
let (found, account) = self.sdb.get_account(&code_address);
734734
if !found {
735-
return Err(Error::AccountNotFound(code_address));
735+
(CodeSource::Address(code_address), H256::from(*EMPTY_HASH))
736+
} else {
737+
(CodeSource::Address(code_address), account.code_hash)
736738
}
737-
(CodeSource::Address(code_address), account.code_hash)
738739
}
739740
}
740741
};
@@ -1274,19 +1275,13 @@ impl<'a> CircuitInputStateRef<'a> {
12741275
step.op,
12751276
OpcodeId::CALL | OpcodeId::CALLCODE | OpcodeId::DELEGATECALL | OpcodeId::STATICCALL
12761277
) {
1277-
let caller = self.call()?;
1278-
let callee_address = match CallKind::try_from(step.op)? {
1279-
CallKind::Call | CallKind::StaticCall => step.stack.nth_last(1)?.to_address(),
1280-
CallKind::CallCode | CallKind::DelegateCall => caller.address,
1281-
_ => unreachable!(),
1282-
};
1283-
1284-
if is_precompiled(&callee_address) {
1278+
let code_address = step.stack.nth_last(1)?.to_address();
1279+
if is_precompiled(&code_address) {
12851280
// Log the precompile address and gas left. Since this failure is mainly caused
12861281
// by out of gas.
12871282
log::trace!(
1288-
"Precompile failed: callee_address = {}, step.gas = {}",
1289-
callee_address,
1283+
"Precompile failed: code_address = {}, step.gas = {}",
1284+
code_address,
12901285
step.gas.0,
12911286
);
12921287
return Ok(Some(ExecError::PrecompileFailed));

bus-mapping/src/evm/opcodes.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ mod error_invalid_opcode;
6262
mod error_oog_call;
6363
mod error_oog_log;
6464
mod error_oog_sload_sstore;
65+
mod error_precompile_failed;
6566
mod error_stack_oog_constant;
6667

6768
#[cfg(test)]
@@ -86,6 +87,7 @@ use error_invalid_opcode::InvalidOpcode;
8687
use error_oog_call::OOGCall;
8788
use error_oog_log::ErrorOOGLog;
8889
use error_oog_sload_sstore::OOGSloadSstore;
90+
use error_precompile_failed::PrecompileFailed;
8991
use error_stack_oog_constant::ErrorStackOogConstant;
9092
use exp::Exponentiation;
9193
use extcodecopy::Extcodecopy;
@@ -274,6 +276,7 @@ fn fn_gen_error_state_associated_ops(error: &ExecError) -> Option<FnGenAssociate
274276
ExecError::StackUnderflow => Some(ErrorStackOogConstant::gen_associated_ops),
275277
// call & callcode can encounter InsufficientBalance error, Use pop-7 generic CallOpcode
276278
ExecError::InsufficientBalance => Some(CallOpcode::<7>::gen_associated_ops),
279+
ExecError::PrecompileFailed => Some(PrecompileFailed::gen_associated_ops),
277280

278281
// more future errors place here
279282
_ => {
@@ -637,6 +640,7 @@ pub fn gen_end_tx_ops(state: &mut CircuitInputStateRef) -> Result<ExecStep, Erro
637640
let effective_tip = state.tx.gas_price - block_info.base_fee;
638641
let (found, coinbase_account) = state.sdb.get_account_mut(&block_info.coinbase);
639642
if !found {
643+
log::error!("coinbase account not found: {}", block_info.coinbase);
640644
return Err(Error::AccountNotFound(block_info.coinbase));
641645
}
642646
let coinbase_balance_prev = coinbase_account.balance;

bus-mapping/src/evm/opcodes/create.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ impl<const IS_CREATE2: bool> Opcode for Create<IS_CREATE2> {
2121
geth_steps: &[GethExecStep],
2222
) -> Result<Vec<ExecStep>, Error> {
2323
let geth_step = &geth_steps[0];
24+
let mut exec_step = state.new_step(geth_step)?;
2425

2526
let offset = geth_step.stack.nth_last(1)?.as_usize();
2627
let length = geth_step.stack.nth_last(2)?.as_usize();
@@ -34,8 +35,6 @@ impl<const IS_CREATE2: bool> Opcode for Create<IS_CREATE2> {
3435
}
3536
let next_memory_word_size = state.call_ctx()?.memory_word_size();
3637

37-
let mut exec_step = state.new_step(geth_step)?;
38-
3938
let callee = state.parse_call(geth_step)?;
4039

4140
let n_pop = if IS_CREATE2 { 4 } else { 3 };
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
use crate::circuit_input_builder::{CircuitInputStateRef, ExecStep};
2+
use crate::error::ExecError;
3+
use crate::evm::Opcode;
4+
use crate::Error;
5+
use eth_types::evm_types::OpcodeId;
6+
use eth_types::GethExecStep;
7+
8+
#[derive(Debug, Copy, Clone)]
9+
pub(crate) struct PrecompileFailed;
10+
11+
impl Opcode for PrecompileFailed {
12+
fn gen_associated_ops(
13+
state: &mut CircuitInputStateRef,
14+
geth_steps: &[GethExecStep],
15+
) -> Result<Vec<ExecStep>, Error> {
16+
let geth_step = &geth_steps[0];
17+
let stack_input_num = match geth_step.op {
18+
OpcodeId::CALL | OpcodeId::CALLCODE => 7,
19+
OpcodeId::DELEGATECALL | OpcodeId::STATICCALL => 6,
20+
op => unreachable!("{op} should not happen in PrecompileFailed"),
21+
};
22+
23+
let mut exec_step = state.new_step(geth_step)?;
24+
exec_step.error = Some(ExecError::PrecompileFailed);
25+
26+
for i in 0..stack_input_num {
27+
state.stack_read(
28+
&mut exec_step,
29+
geth_step.stack.nth_last_filled(i),
30+
geth_step.stack.nth_last(i)?,
31+
)?;
32+
}
33+
34+
state.stack_write(
35+
&mut exec_step,
36+
geth_step.stack.nth_last_filled(stack_input_num - 1),
37+
// Must fail.
38+
(0_u64).into(),
39+
)?;
40+
41+
Ok(vec![exec_step])
42+
}
43+
}

bus-mapping/src/evm/opcodes/extcodehash.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,16 @@ impl Opcode for Extcodehash {
6161
} else {
6262
H256::zero()
6363
};
64+
//log::trace!("extcodehash addr {:?} acc {:?} exists {:?} codehash {:?}",
65+
// external_address, account, exists, code_hash);
6466
state.account_read(
6567
&mut exec_step,
6668
external_address,
6769
AccountField::CodeHash,
6870
code_hash.to_word(),
6971
code_hash.to_word(),
7072
)?;
71-
73+
debug_assert_eq!(steps[1].stack.last()?, code_hash.to_word());
7274
// Stack write of the result of EXTCODEHASH.
7375
state.stack_write(&mut exec_step, stack_address, steps[1].stack.last()?)?;
7476

bus-mapping/src/mock.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ impl BlockData {
6767

6868
for account in geth_data.accounts {
6969
let code_hash = code_db.insert(account.code.to_vec());
70+
log::trace!(
71+
"trace code {:?} {:?}",
72+
code_hash,
73+
hex::encode(account.code.to_vec())
74+
);
7075
sdb.set_account(
7176
&account.address,
7277
state_db::Account {

bus-mapping/src/state_db.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,7 @@ impl Account {
114114

115115
/// Return if account is empty or not.
116116
pub fn is_empty(&self) -> bool {
117-
self.nonce.is_zero()
118-
&& self.balance.is_zero()
119-
&& self.storage.is_empty()
120-
&& self.code_hash.eq(&CODE_HASH_ZERO)
117+
self.nonce.is_zero() && self.balance.is_zero() && self.code_hash.eq(&CODE_HASH_ZERO)
121118
}
122119
}
123120

bus-mapping/src/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ pub fn read_env_var<T: Clone + FromStr>(var_name: &'static str, default: T) -> T
88
.map(|s| s.parse::<T>().unwrap_or_else(|_| default.clone()))
99
.unwrap_or(default)
1010
}
11-
pub(crate) static CHECK_MEM_STRICT: Lazy<bool> =
12-
Lazy::new(|| read_env_var("CHECK_MEM_STRICT", false));
11+
/// ..
12+
pub static CHECK_MEM_STRICT: Lazy<bool> = Lazy::new(|| read_env_var("CHECK_MEM_STRICT", false));

0 commit comments

Comments
 (0)