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

Commit a381021

Browse files
committed
some refactor around From Felt
1 parent c839f61 commit a381021

File tree

4 files changed

+14
-24
lines changed

4 files changed

+14
-24
lines changed

crates/ef-testing/src/evm_sequencer/evm_state/v0.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ impl Evm for KakarotSequencer {
169169
.state_mut()
170170
.get_storage_at(starknet_address, key_high)?;
171171

172-
let low = U256::from_be_bytes(Into::<Felt>::into(low).to_bytes_be());
173-
let high = U256::from_be_bytes(Into::<Felt>::into(high).to_bytes_be());
172+
let low = U256::from_be_bytes(low.to_bytes_be());
173+
let high = U256::from_be_bytes(high.to_bytes_be());
174174

175175
Ok(high << 128 | low)
176176
}
@@ -182,7 +182,7 @@ impl Evm for KakarotSequencer {
182182
let key = get_storage_var_address(ACCOUNT_NONCE, &[]);
183183
let nonce = self.state_mut().get_storage_at(starknet_address, key)?;
184184

185-
Ok(U256::from_be_bytes(Into::<Felt>::into(nonce).to_bytes_be()))
185+
Ok(U256::from_be_bytes(nonce.to_bytes_be()))
186186
}
187187

188188
/// Returns the bytecode of the given address. For an EOA, the bytecode_len_ storage variable will return 0,
@@ -213,7 +213,7 @@ impl Evm for KakarotSequencer {
213213
}
214214

215215
let remainder = bytecode_len % 31;
216-
let key = StorageKey::from(num_chunks);
216+
let key: StorageKey = StorageKey::from(num_chunks);
217217
let code = self.state_mut().get_storage_at(starknet_address, key)?;
218218
bytecode.append(&mut felt_to_bytes(&code, (32 - remainder) as usize).to_vec());
219219

@@ -228,8 +228,8 @@ impl Evm for KakarotSequencer {
228228
.state_mut()
229229
.get_fee_token_balance(starknet_address, *ETH_FEE_TOKEN_ADDRESS)?;
230230

231-
let low = U256::from_be_bytes(Into::<Felt>::into(low).to_bytes_be());
232-
let high = U256::from_be_bytes(Into::<Felt>::into(high).to_bytes_be());
231+
let low = U256::from_be_bytes(low.to_bytes_be());
232+
let high = U256::from_be_bytes(high.to_bytes_be());
233233

234234
Ok(high << 128 | low)
235235
}

crates/ef-testing/src/evm_sequencer/evm_state/v1.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ impl Evm for KakarotSequencer {
174174
.state_mut()
175175
.get_storage_at(starknet_address, key_high)?;
176176

177-
let low = U256::from_be_bytes(Into::<Felt>::into(low).to_bytes_be());
178-
let high = U256::from_be_bytes(Into::<Felt>::into(high).to_bytes_be());
177+
let low = U256::from_be_bytes(low.to_bytes_be());
178+
let high = U256::from_be_bytes(high.to_bytes_be());
179179

180180
Ok(high << 128 | low)
181181
}
@@ -193,7 +193,7 @@ impl Evm for KakarotSequencer {
193193
)
194194
.unwrap();
195195

196-
Ok(U256::from_be_bytes(Into::<Felt>::into(nonce).to_bytes_be()))
196+
Ok(U256::from_be_bytes(nonce.to_bytes_be()))
197197
}
198198

199199
/// Returns the bytecode of the given address. For an EOA, the bytecode_len_ storage variable will return 0,
@@ -256,8 +256,8 @@ impl Evm for KakarotSequencer {
256256
.state_mut()
257257
.get_fee_token_balance(starknet_address, *ETH_FEE_TOKEN_ADDRESS)?;
258258

259-
let low = U256::from_be_bytes(Into::<Felt>::into(low).to_bytes_be());
260-
let high = U256::from_be_bytes(Into::<Felt>::into(high).to_bytes_be());
259+
let low = U256::from_be_bytes(low.to_bytes_be());
260+
let high = U256::from_be_bytes(high.to_bytes_be());
261261

262262
Ok(high << 128 | low)
263263
}

crates/ef-testing/src/models/case.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,8 @@ impl Case for BlockchainTestCase {
259259
let prev_randao: U256 = sealed_header.mix_hash.into();
260260
let base_fee = U256::from(sealed_header.base_fee_per_gas.unwrap_or_default());
261261
let block_gas_limit = U256::from(sealed_header.gas_limit);
262-
263262
let block_number = U256::from(sealed_header.number);
264-
let block_number = TryInto::<u64>::try_into(block_number).unwrap_or_default();
265-
266263
let block_timestamp = U256::from(sealed_block.timestamp);
267-
let block_timestamp = TryInto::<u64>::try_into(block_timestamp).unwrap_or_default();
268264

269265
let kakarot_environment = KakarotEnvironment::new(
270266
*KAKAROT_ADDRESS,
@@ -277,8 +273,8 @@ impl Case for BlockchainTestCase {
277273
kakarot_environment,
278274
coinbase_address,
279275
CHAIN_ID,
280-
block_number,
281-
block_timestamp,
276+
block_number.try_into().unwrap_or_default(),
277+
block_timestamp.try_into().unwrap_or_default(),
282278
);
283279

284280
sequencer.setup_state(base_fee, prev_randao, block_gas_limit)?;

crates/sequencer/src/transaction.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,7 @@ impl BroadcastedTransactionWrapper {
4343
),
4444
nonce: Nonce(invoke_v1.nonce),
4545
sender_address: invoke_v1.sender_address.try_into()?,
46-
calldata: Calldata(Arc::new(
47-
invoke_v1
48-
.calldata
49-
.iter()
50-
.map(|x| Into::<Felt>::into(*x))
51-
.collect(),
52-
)),
46+
calldata: Calldata(Arc::new(invoke_v1.calldata.to_vec())),
5347
}),
5448
only_query: false,
5549
tx_hash: TransactionHash(compute_transaction_hash(

0 commit comments

Comments
 (0)