Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Update geth-utils and bus-mapping to build more witness #292

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
1,024 changes: 727 additions & 297 deletions bus-mapping/src/circuit_input_builder.rs

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions bus-mapping/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ use std::error::Error as StdError;
pub enum Error {
/// Serde de/serialization error.
SerdeError(serde_json::error::Error),
/// Error while generating a trace.
TracingError,
/// JSON-RPC related error.
JSONRpcError(ProviderError),
/// OpcodeId is not a call type.
Expand All @@ -21,9 +19,9 @@ pub enum Error {
/// Storage key not found in the StateDB
StorageKeyNotFound(Address, Word),
/// Unable to figure out error at a [`GethExecStep`]
UnexpectedExecStepError(&'static str, Box<GethExecStep>),
UnexpectedExecStepError(&'static str, GethExecStep),
/// Invalid [`GethExecStep`] due to an invalid/unexpected value in it.
InvalidGethExecStep(&'static str, Box<GethExecStep>),
InvalidGethExecStep(&'static str, GethExecStep),
/// Eth type related error.
EthTypeError(eth_types::Error),
}
Expand Down
8 changes: 5 additions & 3 deletions bus-mapping/src/evm/opcodes/coinbase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ mod coinbase_tests {
builder.handle_tx(&block.eth_tx, &block.geth_trace).unwrap();

let mut test_builder = block.new_circuit_input_builder();
let mut tx = test_builder.new_tx(&block.eth_tx).unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx);
let mut tx = test_builder
.new_tx(&block.eth_tx, !block.geth_trace.failed)
.unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx, &block.geth_trace).unwrap();

// Generate step corresponding to COINBASE
let mut step = ExecStep::new(
Expand All @@ -43,7 +45,7 @@ mod coinbase_tests {
state_ref.push_stack_op(
RW::WRITE,
StackAddress::from(1024 - 1),
block.b_constant.coinbase.to_word(),
block.eth_block.author.to_word(),
);

tx.steps_mut().push(step);
Expand Down
6 changes: 4 additions & 2 deletions bus-mapping/src/evm/opcodes/dup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ mod dup_tests {
builder.handle_tx(&block.eth_tx, &block.geth_trace).unwrap();

let mut test_builder = block.new_circuit_input_builder();
let mut tx = test_builder.new_tx(&block.eth_tx).unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx);
let mut tx = test_builder
.new_tx(&block.eth_tx, !block.geth_trace.failed)
.unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx, &block.geth_trace).unwrap();

// Generate steps corresponding to DUP1, DUP3, DUP5
for (i, word) in [word!("0x3"), word!("0x2"), word!("0x1")]
Expand Down
9 changes: 5 additions & 4 deletions bus-mapping/src/evm/opcodes/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mod gas_tests {
mock::BlockData,
operation::StackAddress,
};
use eth_types::{bytecode, bytecode::Bytecode, Word};
use eth_types::{bytecode, bytecode::Bytecode, evm_types::GasCost, Word};
use mock::new_single_tx_trace_code_at_start;

use super::*;
Expand All @@ -39,8 +39,8 @@ mod gas_tests {
builder.handle_tx(&block.eth_tx, &block.geth_trace)?;

let mut test_builder = block.new_circuit_input_builder();
let mut tx = test_builder.new_tx(&block.eth_tx)?;
let mut tx_ctx = TransactionContext::new(&block.eth_tx);
let mut tx = test_builder.new_tx(&block.eth_tx, !block.geth_trace.failed)?;
let mut tx_ctx = TransactionContext::new(&block.eth_tx, &block.geth_trace)?;

let mut step = ExecStep::new(
&block.geth_trace.struct_logs[0],
Expand Down Expand Up @@ -69,7 +69,8 @@ mod gas_tests {
fn gas_opcode_impl() -> Result<(), Error> {
const GAS_LIMIT: u64 = 1_000_000;

const GAS_COST: u64 = OpcodeId::PUSH1.constant_gas_cost().as_u64()
const GAS_COST: u64 = GasCost::TX.as_u64()
+ OpcodeId::PUSH1.constant_gas_cost().as_u64()
+ OpcodeId::PUSH1.constant_gas_cost().as_u64()
+ OpcodeId::GAS.constant_gas_cost().as_u64();

Expand Down
6 changes: 4 additions & 2 deletions bus-mapping/src/evm/opcodes/jump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ mod jump_tests {
builder.handle_tx(&block.eth_tx, &block.geth_trace).unwrap();

let mut test_builder = block.new_circuit_input_builder();
let mut tx = test_builder.new_tx(&block.eth_tx).unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx);
let mut tx = test_builder
.new_tx(&block.eth_tx, !block.geth_trace.failed)
.unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx, &block.geth_trace).unwrap();

// Generate step corresponding to JUMP
let mut step = ExecStep::new(
Expand Down
6 changes: 4 additions & 2 deletions bus-mapping/src/evm/opcodes/jumpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ mod jumpi_tests {
builder.handle_tx(&block.eth_tx, &block.geth_trace).unwrap();

let mut test_builder = block.new_circuit_input_builder();
let mut tx = test_builder.new_tx(&block.eth_tx).unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx);
let mut tx = test_builder
.new_tx(&block.eth_tx, !block.geth_trace.failed)
.unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx, &block.geth_trace).unwrap();

// Generate step corresponding to JUMP
let mut step = ExecStep::new(
Expand Down
6 changes: 4 additions & 2 deletions bus-mapping/src/evm/opcodes/mload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ mod mload_tests {
builder.handle_tx(&block.eth_tx, &block.geth_trace).unwrap();

let mut test_builder = block.new_circuit_input_builder();
let mut tx = test_builder.new_tx(&block.eth_tx).unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx);
let mut tx = test_builder
.new_tx(&block.eth_tx, !block.geth_trace.failed)
.unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx, &block.geth_trace).unwrap();

// Generate step corresponding to MLOAD
let mut step = ExecStep::new(
Expand Down
6 changes: 4 additions & 2 deletions bus-mapping/src/evm/opcodes/msize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ mod msize_tests {
builder.handle_tx(&block.eth_tx, &block.geth_trace).unwrap();

let mut test_builder = block.new_circuit_input_builder();
let mut tx = test_builder.new_tx(&block.eth_tx).unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx);
let mut tx = test_builder
.new_tx(&block.eth_tx, !block.geth_trace.failed)
.unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx, &block.geth_trace).unwrap();

let mut step = ExecStep::new(
&block.geth_trace.struct_logs[0],
Expand Down
12 changes: 8 additions & 4 deletions bus-mapping/src/evm/opcodes/mstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ mod mstore_tests {
builder.handle_tx(&block.eth_tx, &block.geth_trace).unwrap();

let mut test_builder = block.new_circuit_input_builder();
let mut tx = test_builder.new_tx(&block.eth_tx).unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx);
let mut tx = test_builder
.new_tx(&block.eth_tx, !block.geth_trace.failed)
.unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx, &block.geth_trace).unwrap();

// Generate step corresponding to MSTORE
let mut step = ExecStep::new(
Expand Down Expand Up @@ -138,8 +140,10 @@ mod mstore_tests {
builder.handle_tx(&block.eth_tx, &block.geth_trace).unwrap();

let mut test_builder = block.new_circuit_input_builder();
let mut tx = test_builder.new_tx(&block.eth_tx).unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx);
let mut tx = test_builder
.new_tx(&block.eth_tx, !block.geth_trace.failed)
.unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx, &block.geth_trace).unwrap();

// Generate step corresponding to MSTORE
let mut step = ExecStep::new(
Expand Down
6 changes: 4 additions & 2 deletions bus-mapping/src/evm/opcodes/pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ mod pc_tests {
builder.handle_tx(&block.eth_tx, &block.geth_trace).unwrap();

let mut test_builder = block.new_circuit_input_builder();
let mut tx = test_builder.new_tx(&block.eth_tx).unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx);
let mut tx = test_builder
.new_tx(&block.eth_tx, !block.geth_trace.failed)
.unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx, &block.geth_trace).unwrap();

// Generate step corresponding to MLOAD
let mut step = ExecStep::new(
Expand Down
6 changes: 4 additions & 2 deletions bus-mapping/src/evm/opcodes/pop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ mod pop_tests {
builder.handle_tx(&block.eth_tx, &block.geth_trace).unwrap();

let mut test_builder = block.new_circuit_input_builder();
let mut tx = test_builder.new_tx(&block.eth_tx).unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx);
let mut tx = test_builder
.new_tx(&block.eth_tx, !block.geth_trace.failed)
.unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx, &block.geth_trace).unwrap();

// Generate step corresponding to POP
let mut step = ExecStep::new(
Expand Down
6 changes: 4 additions & 2 deletions bus-mapping/src/evm/opcodes/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ mod push_tests {
builder.handle_tx(&block.eth_tx, &block.geth_trace).unwrap();

let mut test_builder = block.new_circuit_input_builder();
let mut tx = test_builder.new_tx(&block.eth_tx).unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx);
let mut tx = test_builder
.new_tx(&block.eth_tx, !block.geth_trace.failed)
.unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx, &block.geth_trace).unwrap();

// Generate steps corresponding to PUSH1 80, PUSH2 1234,
// PUSH16 0x00112233445566778899aabbccddeeff
Expand Down
34 changes: 20 additions & 14 deletions bus-mapping/src/evm/opcodes/sload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ impl Opcode for Sload {

// Storage read
let storage_value_read = step.storage.get_or_err(&stack_value_read)?;
state.push_op(StorageOp::new(
state.push_op(
RW::READ,
state.call().address,
stack_value_read,
storage_value_read,
storage_value_read,
));
StorageOp::new(
state.call().address,
stack_value_read,
storage_value_read,
storage_value_read,
),
);

// First stack write
state.push_stack_op(RW::WRITE, stack_position, storage_value_read);
Expand Down Expand Up @@ -75,8 +77,10 @@ mod sload_tests {
builder.handle_tx(&block.eth_tx, &block.geth_trace).unwrap();

let mut test_builder = block.new_circuit_input_builder();
let mut tx = test_builder.new_tx(&block.eth_tx).unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx);
let mut tx = test_builder
.new_tx(&block.eth_tx, !block.geth_trace.failed)
.unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx, &block.geth_trace).unwrap();

// Generate step corresponding to SLOAD
let mut step = ExecStep::new(
Expand All @@ -89,13 +93,15 @@ mod sload_tests {
// Add StackOp associated to the stack pop.
state_ref.push_stack_op(RW::READ, StackAddress::from(1023), Word::from(0x0u32));
// Add StorageOp associated to the storage read.
state_ref.push_op(StorageOp::new(
state_ref.push_op(
RW::READ,
Address::from([0u8; 20]),
Word::from(0x0u32),
Word::from(0x6fu32),
Word::from(0x6fu32),
));
StorageOp::new(
Address::from([0u8; 20]),
Word::from(0x0u32),
Word::from(0x6fu32),
Word::from(0x6fu32),
),
);
// Add StackOp associated to the stack push.
state_ref.push_stack_op(RW::WRITE, StackAddress::from(1023), Word::from(0x6fu32));
tx.steps_mut().push(step);
Expand Down
18 changes: 12 additions & 6 deletions bus-mapping/src/evm/opcodes/stackonlyop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ mod stackonlyop_tests {
builder.handle_tx(&block.eth_tx, &block.geth_trace).unwrap();

let mut test_builder = block.new_circuit_input_builder();
let mut tx = test_builder.new_tx(&block.eth_tx).unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx);
let mut tx = test_builder
.new_tx(&block.eth_tx, !block.geth_trace.failed)
.unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx, &block.geth_trace).unwrap();

// Generate step corresponding to NOT
let mut step = ExecStep::new(
Expand Down Expand Up @@ -125,8 +127,10 @@ mod stackonlyop_tests {
builder.handle_tx(&block.eth_tx, &block.geth_trace).unwrap();

let mut test_builder = block.new_circuit_input_builder();
let mut tx = test_builder.new_tx(&block.eth_tx).unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx);
let mut tx = test_builder
.new_tx(&block.eth_tx, !block.geth_trace.failed)
.unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx, &block.geth_trace).unwrap();

// Generate step corresponding to ADD
let mut step = ExecStep::new(
Expand Down Expand Up @@ -187,8 +191,10 @@ mod stackonlyop_tests {
builder.handle_tx(&block.eth_tx, &block.geth_trace).unwrap();

let mut test_builder = block.new_circuit_input_builder();
let mut tx = test_builder.new_tx(&block.eth_tx).unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx);
let mut tx = test_builder
.new_tx(&block.eth_tx, !block.geth_trace.failed)
.unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx, &block.geth_trace).unwrap();

// Generate step corresponding to ADDMOD
let mut step = ExecStep::new(
Expand Down
5 changes: 3 additions & 2 deletions bus-mapping/src/evm/opcodes/stop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ pub(crate) struct Stop;

impl Opcode for Stop {
fn gen_associated_ops(
_state: &mut CircuitInputStateRef,
state: &mut CircuitInputStateRef,
_steps: &[GethExecStep],
) -> Result<(), Error> {
// Stop does not generate any operations
state.handle_return()?;
ed255 marked this conversation as resolved.
Show resolved Hide resolved

Ok(())
}
}
6 changes: 4 additions & 2 deletions bus-mapping/src/evm/opcodes/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,10 @@ mod swap_tests {
builder.handle_tx(&block.eth_tx, &block.geth_trace).unwrap();

let mut test_builder = block.new_circuit_input_builder();
let mut tx = test_builder.new_tx(&block.eth_tx).unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx);
let mut tx = test_builder
.new_tx(&block.eth_tx, !block.geth_trace.failed)
.unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx, &block.geth_trace).unwrap();

// Generate steps corresponding to DUP1, DUP3, DUP5
for (i, (a, b)) in [(6, 5), (5, 3), (3, 1)].iter().enumerate() {
Expand Down
8 changes: 5 additions & 3 deletions bus-mapping/src/evm/opcodes/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ mod timestamp_tests {
builder.handle_tx(&block.eth_tx, &block.geth_trace).unwrap();

let mut test_builder = block.new_circuit_input_builder();
let mut tx = test_builder.new_tx(&block.eth_tx).unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx);
let mut tx = test_builder
.new_tx(&block.eth_tx, !block.geth_trace.failed)
.unwrap();
let mut tx_ctx = TransactionContext::new(&block.eth_tx, &block.geth_trace).unwrap();

// Generate step corresponding to TIMESTAMP
let mut step = ExecStep::new(
Expand All @@ -42,7 +44,7 @@ mod timestamp_tests {
state_ref.push_stack_op(
RW::WRITE,
StackAddress::from(1024 - 1),
block.b_constant.timestamp,
block.eth_block.timestamp,
);

tx.steps_mut().push(step);
Expand Down
4 changes: 3 additions & 1 deletion bus-mapping/src/exec_trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::fmt;
#[derive(Clone, Copy, PartialEq, Eq)]
/// The target and index of an `Operation` in the context of an
/// `ExecutionTrace`.
pub struct OperationRef(Target, usize);
pub struct OperationRef(pub Target, pub usize);

impl fmt::Debug for OperationRef {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand All @@ -21,6 +21,7 @@ impl fmt::Debug for OperationRef {
Target::TxRefund => "TxRefund",
Target::Account => "Account",
Target::AccountDestructed => "AccountDestructed",
Target::CallContext => "CallContext",
},
self.1
))
Expand All @@ -40,6 +41,7 @@ impl From<(Target, usize)> for OperationRef {
Target::TxRefund => Self(Target::TxRefund, op_ref_data.1),
Target::Account => Self(Target::Account, op_ref_data.1),
Target::AccountDestructed => Self(Target::AccountDestructed, op_ref_data.1),
Target::CallContext => Self(Target::CallContext, op_ref_data.1),
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions bus-mapping/src/geth_errors.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
/// Geth error message for stack overflow
pub const GETH_ERR_STACK_OVERFLOW: &str = "stack limit reached";
/// Geth error message for invalid opcode
pub const GETH_ERR_INVALID_OPCODE: &str = "invalid opcode";
/// Geth error message for stack underflow
pub const GETH_ERR_STACK_UNDERFLOW: &str = "stack underflow";
/// Geth error message for out of gas
pub const GETH_ERR_OUT_OF_GAS: &str = "out of gas";
/// Geth error message for gas uint64 overflow
pub const GETH_ERR_GAS_UINT_OVERFLOW: &str = "gas uint64 overflow";
/// Geth error message for write protection
pub const GETH_ERR_WRITE_PROTECTION: &str = "write protection";
Loading