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

Commit d815e8d

Browse files
authored
Fix chain ID from a Word to Uint64. (#553)
1 parent 6c6865f commit d815e8d

File tree

28 files changed

+91
-98
lines changed

28 files changed

+91
-98
lines changed

bus-mapping/src/circuit_input_builder.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,14 +587,14 @@ pub fn keccak_inputs(block: &Block, code_db: &CodeDB) -> Result<Vec<Vec<u8>>, Er
587587
let mut keccak_inputs = Vec::new();
588588
// Tx Circuit
589589
let txs: Vec<geth_types::Transaction> = block.txs.iter().map(|tx| tx.into()).collect();
590-
keccak_inputs.extend_from_slice(&keccak_inputs_tx_circuit(&txs, block.chain_id().as_u64())?);
590+
keccak_inputs.extend_from_slice(&keccak_inputs_tx_circuit(&txs, block.chain_id())?);
591591
log::debug!(
592592
"keccak total len after txs: {}",
593593
keccak_inputs.iter().map(|i| i.len()).sum::<usize>()
594594
);
595595
// PI circuit
596596
keccak_inputs.push(keccak_inputs_pi_circuit(
597-
block.chain_id().as_u64(),
597+
block.chain_id(),
598598
block.prev_state_root,
599599
block.withdraw_root,
600600
&block.headers,
@@ -827,7 +827,7 @@ type EthBlock = eth_types::Block<eth_types::Transaction>;
827827
/// the necessary information and using the CircuitInputBuilder.
828828
pub struct BuilderClient<P: JsonRpcClient> {
829829
cli: GethClient<P>,
830-
chain_id: Word,
830+
chain_id: u64,
831831
circuits_params: CircuitsParams,
832832
}
833833

@@ -895,7 +895,7 @@ impl<P: JsonRpcClient> BuilderClient<P> {
895895

896896
Ok(Self {
897897
cli: client,
898-
chain_id: chain_id.into(),
898+
chain_id,
899899
circuits_params,
900900
})
901901
}

bus-mapping/src/circuit_input_builder/block.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
operation::{OperationContainer, RWCounter},
88
Error,
99
};
10-
use eth_types::{Address, Hash, ToWord, Word, U256};
10+
use eth_types::{Address, Hash, ToWord, Word};
1111
use std::collections::{BTreeMap, HashMap};
1212

1313
/// Context of a [`Block`] which can mutate in a [`Transaction`].
@@ -70,7 +70,7 @@ impl Default for BlockSteps {
7070
#[derive(Debug, Clone)]
7171
pub struct BlockHead {
7272
/// chain id
73-
pub chain_id: Word,
73+
pub chain_id: u64,
7474
/// history hashes contains most recent 256 block hashes in history, where
7575
/// the lastest one is at history_hashes[history_hashes.len() - 1].
7676
pub history_hashes: Vec<Word>,
@@ -92,7 +92,7 @@ pub struct BlockHead {
9292
impl BlockHead {
9393
/// Create a new block.
9494
pub fn new(
95-
chain_id: Word,
95+
chain_id: u64,
9696
history_hashes: Vec<Word>,
9797
eth_block: &eth_types::Block<eth_types::Transaction>,
9898
) -> Result<Self, Error> {
@@ -160,7 +160,7 @@ pub struct Block {
160160
/// Circuits Setup Paramteres
161161
pub circuits_params: CircuitsParams,
162162
/// chain id
163-
pub chain_id: Word,
163+
pub chain_id: u64,
164164
}
165165

166166
impl Block {
@@ -187,7 +187,7 @@ impl Block {
187187
}
188188
/// Create a new block.
189189
pub fn new<TX>(
190-
chain_id: Word,
190+
chain_id: u64,
191191
history_hashes: Vec<Word>,
192192
eth_block: &eth_types::Block<eth_types::Transaction>,
193193
circuits_params: CircuitsParams,
@@ -219,7 +219,7 @@ impl Block {
219219
}
220220

221221
/// Return the chain id.
222-
pub fn chain_id(&self) -> U256 {
222+
pub fn chain_id(&self) -> u64 {
223223
self.chain_id
224224
}
225225

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ mod chainid_tests {
5454
},
5555
(
5656
RW::WRITE,
57-
&StackOp::new(1, StackAddress::from(1023), *MOCK_CHAIN_ID)
57+
&StackOp::new(1, StackAddress::from(1023), (*MOCK_CHAIN_ID).into())
5858
)
5959
);
6060
}

bus-mapping/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct BlockData {
2020
/// CodeDB
2121
pub code_db: CodeDB,
2222
/// chain id
23-
pub chain_id: Word,
23+
pub chain_id: u64,
2424
/// history hashes contains most recent 256 block hashes in history, where
2525
/// the lastest one is at history_hashes[history_hashes.len() - 1].
2626
pub history_hashes: Vec<Word>,

circuit-benchmarks/src/super_circuit.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@ mod tests {
4343

4444
let mut rng = ChaChaRng::seed_from_u64(2);
4545

46-
let chain_id = (*MOCK_CHAIN_ID).as_u64();
47-
4846
let bytecode = bytecode! {
4947
STOP
5048
};
5149

52-
let wallet_a = LocalWallet::new(&mut rng).with_chain_id(chain_id);
50+
let wallet_a = LocalWallet::new(&mut rng).with_chain_id(*MOCK_CHAIN_ID);
5351

5452
let addr_a = wallet_a.address();
5553
let addr_b = address!("0x000000000000000000000000000000000000BBBB");

circuit-benchmarks/src/tx_circuit.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,8 @@ mod tests {
8080

8181
let max_txs: usize = 2_usize.pow(degree) / ROWS_PER_TX;
8282

83-
let chain_id: u64 = mock::MOCK_CHAIN_ID.low_u64();
8483
let txs = vec![mock::CORRECT_MOCK_TXS[0].clone().into()];
85-
let circuit = TxCircuit::<Fr>::new(max_txs, MAX_CALLDATA, chain_id, txs);
84+
let circuit = TxCircuit::<Fr>::new(max_txs, MAX_CALLDATA, *mock::MOCK_CHAIN_ID, txs);
8685
(degree as usize, circuit)
8786
}
8887

eth-types/src/evm_types/block_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ pub const NUM_PREV_BLOCK_ALLOWED: u64 = 256;
88

99
/// Calculate block hash by chain ID and block number (only for scroll).
1010
/// Return a pair of input and output.
11-
pub fn calculate_block_hash(chain_id: U256, block_number: U256) -> (Vec<u8>, U256) {
11+
pub fn calculate_block_hash(chain_id: u64, block_number: U256) -> (Vec<u8>, U256) {
1212
let mut input = vec![0; 16];
1313

14-
U64([chain_id.low_u64()]).to_big_endian(&mut input[..8]);
14+
U64([chain_id]).to_big_endian(&mut input[..8]);
1515
U64([block_number.low_u64()]).to_big_endian(&mut input[8..]);
1616

1717
let output = U256::from_big_endian(&keccak256(&input));

eth-types/src/geth_types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ impl Transaction {
355355
#[derive(Debug, Clone)]
356356
pub struct GethData {
357357
/// chain id
358-
pub chain_id: Word,
358+
pub chain_id: u64,
359359
/// history hashes contains most recent 256 block hashes in history, where
360360
/// the lastest one is at history_hashes[history_hashes.len() - 1].
361361
pub history_hashes: Vec<Word>,
@@ -372,10 +372,10 @@ impl GethData {
372372
pub fn sign(&mut self, wallets: &HashMap<Address, LocalWallet>) {
373373
for tx in self.eth_block.transactions.iter_mut() {
374374
let wallet = wallets.get(&tx.from).unwrap();
375-
assert_eq!(Word::from(wallet.chain_id()), self.chain_id);
375+
assert_eq!(wallet.chain_id(), self.chain_id);
376376
let geth_tx: Transaction = (&*tx).into();
377377
let req: TransactionRequest = (&geth_tx).into();
378-
let sig = wallet.sign_transaction_sync(&req.chain_id(self.chain_id.as_u64()).into());
378+
let sig = wallet.sign_transaction_sync(&req.chain_id(self.chain_id).into());
379379
tx.v = U64::from(sig.v);
380380
tx.r = sig.r;
381381
tx.s = sig.s;

external-tracer/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use std::collections::HashMap;
1111
#[derive(Debug, Default, Clone, Serialize)]
1212
pub struct TraceConfig {
1313
/// chain id
14-
pub chain_id: Word,
14+
pub chain_id: u64,
1515
/// history hashes contains most recent 256 block hashes in history, where
1616
/// the lastest one is at history_hashes[history_hashes.len() - 1].
1717
pub history_hashes: Vec<Word>,

geth-utils/gethutil/trace.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ type Transaction struct {
115115
}
116116

117117
type TraceConfig struct {
118-
ChainID *hexutil.Big `json:"chain_id"`
118+
ChainID uint64 `json:"chain_id"`
119119
// HistoryHashes contains most recent 256 block hashes in history,
120120
// where the lastest one is at HistoryHashes[len(HistoryHashes)-1].
121121
HistoryHashes []*hexutil.Big `json:"history_hashes"`
@@ -130,7 +130,7 @@ func newUint64(val uint64) *uint64 { return &val }
130130

131131
func Trace(config TraceConfig) ([]*ExecutionResult, error) {
132132
chainConfig := params.ChainConfig{
133-
ChainID: toBigInt(config.ChainID),
133+
ChainID: new(big.Int).SetUint64(config.ChainID),
134134
HomesteadBlock: big.NewInt(0),
135135
DAOForkBlock: big.NewInt(0),
136136
DAOForkSupport: true,

0 commit comments

Comments
 (0)