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
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: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions bus-mapping/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ authors = ["CPerezz <c.perezbaro@gmail.com>"]

[dependencies]
eth-types = { path = "../eth-types" }
keccak256 = { path = "../keccak256" }
ethers-core = "0.6"
ethers-providers = "0.6"
itertools = "0.10"
Expand Down
14 changes: 8 additions & 6 deletions bus-mapping/src/circuit_input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ pub enum ExecError {
InvalidJump,
/// For RETURNDATACOPY
ReturnDataOutOfBounds,
// NOTE: We don't use the GasUintOverflow in favour of always reporting an
// OutOfGas error.
// /// Internal calculation of gas overflow
// GasUintOverflow,
/// For RETURN in a CREATE, CREATE2
CodeStoreOutOfGas,
/// For RETURN in a CREATE, CREATE2
Expand Down Expand Up @@ -496,6 +492,10 @@ impl TransactionContext {
} else if geth_step.depth - 1 == geth_next_step.depth {
let is_success = !geth_next_step.stack.last()?.is_zero();
call_is_success_map.insert(call_indices.pop().unwrap(), is_success);
// Callee with empty code
} else if CallKind::try_from(geth_step.op).is_ok() {
let is_success = !geth_next_step.stack.last()?.is_zero();
call_is_success_map.insert(index, is_success);
}
}
}
Expand Down Expand Up @@ -566,10 +566,12 @@ impl TransactionContext {
op_refs: Vec::new(),
})
} else if let Some(reversion_group) = self.reversion_groups.last_mut() {
let caller_swc = self.calls.last().expect("calls should not be empty").swc;
let caller_ctx = self.calls.last().expect("calls should not be empty");
let caller_swc = caller_ctx.swc;
let caller_swc_offset = reversion_group
.calls
.last()
.iter()
.find(|(call_idx, _)| *call_idx == caller_ctx.index)
.expect("calls should not be empty")
.1;
reversion_group
Expand Down
104 changes: 63 additions & 41 deletions bus-mapping/src/evm/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ use eth_types::{
evm_types::{GasCost, MAX_REFUND_QUOTIENT_OF_GAS_USED},
GethExecStep, ToWord,
};
use keccak256::EMPTY_HASH;
use log::warn;

mod call;
mod calldatacopy;
mod calldatasize;
mod caller;
Expand All @@ -30,6 +32,7 @@ mod stackonlyop;
mod stop;
mod swap;

use call::Call;
use calldatacopy::Calldatacopy;
use calldatasize::Calldatasize;
use caller::Caller;
Expand Down Expand Up @@ -207,7 +210,7 @@ fn fn_gen_associated_ops(opcode_id: &OpcodeId) -> FnGenAssociatedOps {
// OpcodeId::LOG3 => {},
// OpcodeId::LOG4 => {},
// OpcodeId::CREATE => {},
// OpcodeId::CALL => {},
OpcodeId::CALL => Call::gen_associated_ops,
// OpcodeId::CALLCODE => {},
// TODO: Handle RETURN by its own gen_associated_ops.
OpcodeId::RETURN => Stop::gen_associated_ops,
Expand Down Expand Up @@ -337,14 +340,23 @@ pub fn gen_begin_tx_ops(state: &mut CircuitInputStateRef) -> Result<ExecStep, Er
},
)?;

match (call.is_create(), state.is_precompiled(&call.address)) {
(true, _) => {
// TODO: Implement creation transaction
// There are 4 branches from here.
Comment thread
CPerezz marked this conversation as resolved.
match (
call.is_create(),
state.is_precompiled(&call.address),
code_hash.to_fixed_bytes() == *EMPTY_HASH,
) {
// 1. Creation transaction.
(true, _, _) => {
warn!("Creation transaction is left unimplemented");
Ok(exec_step)
}
(_, true) => {
// TODO: Implement calling to precompiled
// 2. Call to precompiled.
(_, true, _) => {
warn!("Call to precompiled is left unimplemented");
Ok(exec_step)
}
_ => {
(_, _, is_empty_code_hash) => {
state.push_op(
&mut exec_step,
RW::READ,
Expand All @@ -355,42 +367,52 @@ pub fn gen_begin_tx_ops(state: &mut CircuitInputStateRef) -> Result<ExecStep, Er
value_prev: code_hash.to_word(),
},
);
}
}

for (field, value) in [
(CallContextField::Depth, call.depth.into()),
(
CallContextField::CallerAddress,
call.caller_address.to_word(),
),
(CallContextField::CalleeAddress, call.address.to_word()),
(
CallContextField::CallDataOffset,
call.call_data_offset.into(),
),
(
CallContextField::CallDataLength,
call.call_data_length.into(),
),
(CallContextField::Value, call.value),
(CallContextField::IsStatic, (call.is_static as usize).into()),
(CallContextField::LastCalleeId, 0.into()),
(CallContextField::LastCalleeReturnDataOffset, 0.into()),
(CallContextField::LastCalleeReturnDataLength, 0.into()),
] {
state.push_op(
&mut exec_step,
RW::READ,
CallContextOp {
call_id: call.call_id,
field,
value,
},
);
}
// 3. Call to account with empty code.
if is_empty_code_hash {
warn!("Call to account with empty code is left unimplemented");
return Ok(exec_step);
}

Ok(exec_step)
// 4. Call to account with non-empty code.
for (field, value) in [
(CallContextField::Depth, call.depth.into()),
(
CallContextField::CallerAddress,
call.caller_address.to_word(),
),
(CallContextField::CalleeAddress, call.address.to_word()),
(
CallContextField::CallDataOffset,
call.call_data_offset.into(),
),
(
CallContextField::CallDataLength,
call.call_data_length.into(),
),
(CallContextField::Value, call.value),
(CallContextField::IsStatic, (call.is_static as usize).into()),
(CallContextField::LastCalleeId, 0.into()),
(CallContextField::LastCalleeReturnDataOffset, 0.into()),
(CallContextField::LastCalleeReturnDataLength, 0.into()),
(CallContextField::IsRoot, 1.into()),
(CallContextField::IsCreate, 0.into()),
(CallContextField::CodeSource, code_hash.to_word()),
] {
state.push_op(
&mut exec_step,
RW::READ,
CallContextOp {
call_id: call.call_id,
field,
value,
},
);
}

Ok(exec_step)
}
}
}

pub fn gen_end_tx_ops(state: &mut CircuitInputStateRef) -> Result<ExecStep, Error> {
Expand Down
Loading