Skip to content

Commit

Permalink
Retype Gas limit and nonce to u64 (privacy-scaling-explorations#1409)
Browse files Browse the repository at this point in the history
### Description

- Gas limit from Word to u64
- Nonce from Word to u64

### Issue Link

Fix privacy-scaling-explorations#1377

### Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

### Contents

- change geth_type Account's nonce and gas_limit to eth_core::U64. We
can not use simple u64 because we need to serialize nonce and gas_limit
to hex value with 0x prefix for Geth RPC to use.
- simple u64 is used in rest of the places.

### Rationale
  • Loading branch information
ChihChengLiang authored May 16, 2023
1 parent 255a9bc commit d21952d
Show file tree
Hide file tree
Showing 28 changed files with 171 additions and 281 deletions.
2 changes: 1 addition & 1 deletion bus-mapping/src/circuit_input_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ pub fn build_state_code_db(
sdb.set_account(
&proof.address,
state_db::Account {
nonce: proof.nonce,
nonce: proof.nonce.as_u64(),
balance: proof.balance,
storage,
code_hash: proof.code_hash,
Expand Down
4 changes: 2 additions & 2 deletions bus-mapping/src/circuit_input_builder/input_state_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl<'a> CircuitInputStateRef<'a> {
// accounts, but the corresponding account in the state DB is empty
// (which means code_hash=EMPTY_HASH).
let account_value_prev = match op.field {
AccountField::Nonce => account.nonce,
AccountField::Nonce => account.nonce.to_word(),
AccountField::Balance => account.balance,
AccountField::CodeHash => {
if account.is_empty() {
Expand Down Expand Up @@ -318,7 +318,7 @@ impl<'a> CircuitInputStateRef<'a> {
// Perform the write to the account in the StateDB
if matches!(rw, RW::WRITE) {
match op.field {
AccountField::Nonce => account.nonce = op.value,
AccountField::Nonce => account.nonce = op.value.as_u64(),
AccountField::Balance => account.balance = op.value,
AccountField::CodeHash => account.code_hash = H256::from(op.value.to_be_bytes()),
}
Expand Down
90 changes: 21 additions & 69 deletions bus-mapping/src/circuit_input_builder/tracer_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,7 @@ fn tracer_err_insufficient_balance() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1]
.to(accs[1].address)
.from(accs[2].address)
.nonce(Word::one());
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -406,10 +403,7 @@ fn tracer_err_address_collision() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1]
.to(accs[1].address)
.from(accs[2].address)
.nonce(Word::one());
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -529,10 +523,7 @@ fn tracer_create_collision_free() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1]
.to(accs[1].address)
.from(accs[2].address)
.nonce(Word::one());
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -573,7 +564,7 @@ fn tracer_create_collision_free() {
builder.builder.sdb.set_account(
&ADDR_B,
Account {
nonce: Word::zero(),
nonce: 0,
balance: Word::from(555u64), /* same value as in
* `mock::new_tracer_account` */
storage: HashMap::new(),
Expand All @@ -583,7 +574,7 @@ fn tracer_create_collision_free() {
builder.builder.sdb.set_account(
&create_address,
Account {
nonce: Word::zero(),
nonce: 0,
balance: Word::zero(),
storage: HashMap::new(),
code_hash: Hash::zero(),
Expand Down Expand Up @@ -662,10 +653,7 @@ fn tracer_err_code_store_out_of_gas() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1]
.to(accs[1].address)
.from(accs[2].address)
.nonce(Word::one());
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -715,7 +703,7 @@ fn tracer_err_code_store_out_of_gas_tx_deploy() {
txs[0]
.from(accs[1].address)
.gas(55000u64.into())
.nonce(Word::zero())
.nonce(0)
.input(code_creator.into());
},
|block, _tx| block.number(0x0264),
Expand Down Expand Up @@ -814,10 +802,7 @@ fn tracer_err_invalid_code() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1]
.to(accs[1].address)
.from(accs[2].address)
.nonce(Word::one());
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -914,10 +899,7 @@ fn tracer_err_max_code_size_exceeded() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1]
.to(accs[1].address)
.from(accs[2].address)
.nonce(Word::one());
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -967,7 +949,7 @@ fn tracer_err_max_code_size_exceeded_tx_deploy() {
txs[0]
.from(accs[1].address)
.gas(60000u64.into())
.nonce(Word::zero())
.nonce(0)
.input(code_creator.into());
},
|block, _tx| block.number(0x0264),
Expand Down Expand Up @@ -1058,10 +1040,7 @@ fn tracer_create_stop() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1]
.to(accs[1].address)
.from(accs[2].address)
.nonce(Word::one());
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -1179,10 +1158,7 @@ fn tracer_err_invalid_jump() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1]
.to(accs[1].address)
.from(accs[2].address)
.nonce(Word::one());
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -1282,10 +1258,7 @@ fn tracer_err_execution_reverted() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1]
.to(accs[1].address)
.from(accs[2].address)
.nonce(Word::one());
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -1344,10 +1317,7 @@ fn tracer_stop() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1]
.to(accs[1].address)
.from(accs[2].address)
.nonce(Word::one());
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -1415,10 +1385,7 @@ fn tracer_err_return_data_out_of_bounds() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1]
.to(accs[1].address)
.from(accs[2].address)
.nonce(Word::one());
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -1571,10 +1538,7 @@ fn tracer_err_write_protection(is_call: bool) {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1]
.to(accs[1].address)
.from(accs[2].address)
.nonce(Word::one());
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -1776,10 +1740,7 @@ fn create2_address() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1]
.to(accs[1].address)
.from(accs[2].address)
.nonce(Word::one());
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -1877,10 +1838,7 @@ fn create_address() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1]
.to(accs[1].address)
.from(accs[2].address)
.nonce(Word::one());
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -1913,7 +1871,7 @@ fn create_address() {
builder.builder.sdb.set_account(
&ADDR_B,
Account {
nonce: Word::from(1),
nonce: 1,
..Account::zero()
},
);
Expand Down Expand Up @@ -1964,10 +1922,7 @@ fn test_gen_access_trace() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1]
.to(accs[1].address)
.from(accs[2].address)
.nonce(Word::one());
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down Expand Up @@ -2189,10 +2144,7 @@ fn test_gen_access_trace_create_push_call_stack() {
},
|mut txs, accs| {
txs[0].to(accs[0].address).from(accs[2].address);
txs[1]
.to(accs[1].address)
.from(accs[2].address)
.nonce(Word::one());
txs[1].to(accs[1].address).from(accs[2].address).nonce(1);
},
|block, _tx| block.number(0xcafeu64),
LoggerConfig::enable_memory(),
Expand Down
4 changes: 2 additions & 2 deletions bus-mapping/src/evm/opcodes/begin_end_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ fn gen_begin_tx_steps(state: &mut CircuitInputStateRef) -> Result<ExecStep, Erro
&mut exec_step,
caller_address,
AccountField::Nonce,
nonce_prev + 1,
nonce_prev,
(nonce_prev + 1).into(),
nonce_prev.into(),
)?;

// Add caller and callee into access list
Expand Down
4 changes: 2 additions & 2 deletions bus-mapping/src/evm/opcodes/extcodehash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ mod extcodehash_tests {
EXTCODEHASH
STOP
});
let mut nonce = Word::from(300u64);
let mut nonce = 300u64;
let mut balance = Word::from(800u64);
let mut code_ext = Bytes::from([34, 54, 56]);

if !exists {
nonce = Word::zero();
nonce = 0;
balance = Word::zero();
code_ext = Bytes::default();
}
Expand Down
12 changes: 2 additions & 10 deletions bus-mapping/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,8 @@ impl BlockData {
}

for account in geth_data.accounts {
let code_hash = code_db.insert(account.code.to_vec());
sdb.set_account(
&account.address,
state_db::Account {
nonce: account.nonce,
balance: account.balance,
storage: account.storage,
code_hash,
},
);
code_db.insert(account.code.to_vec());
sdb.set_account(&account.address, state_db::Account::from(account.clone()));
}

Self {
Expand Down
Loading

0 comments on commit d21952d

Please sign in to comment.