Skip to content

Commit 3eacbf5

Browse files
github-actions[bot]ZhiyuCircle
authored andcommitted
chore: sync from main@f621f21c4656064a0f77b5247d1bb00ca31d7bbe
Source commit : f621f21c4656064a0f77b5247d1bb00ca31d7bbe Source run : https://github.com/crcl-main/circle-chain-reth/actions/runs/24247056963
1 parent 2378b19 commit 3eacbf5

2 files changed

Lines changed: 61 additions & 4 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ git config fetch.recurseSubmodules on-demand
5454

5555
### Prerequisites
5656

57+
- [Rust](https://rustup.rs/)
58+
- [Docker](https://docs.docker.com/get-started/get-docker/)
5759
- [Node.js](https://nodejs.org/)
5860
- [Foundry](https://getfoundry.sh/)
5961
- [Hardhat](https://hardhat.org/)
@@ -178,7 +180,7 @@ For more details, see our [Contributing Guide](CONTRIBUTING.md).
178180
## Resources
179181

180182
- [Arc Network](https://www.arc.network/) - Official Arc Network website
181-
- [Arc Documentation](https://www.arc.network/) - Official Arc developer documentation
183+
- [Arc Documentation](https://docs.arc.network/) - Official Arc developer documentation
182184
- [Reth](https://github.com/paradigmxyz/reth) - The underlying execution layer framework
183185
- [Malachite](https://github.com/circlefin/malachite) - BFT consensus engine
184186
- [Local Documentation](docs/) - Implementation guides and references

crates/evm/src/handler.rs

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,9 @@ where
8989
let beneficiary = ctx.block().beneficiary();
9090
let basefee = ctx.block().basefee() as u128;
9191
let effective_gas_price = ctx.tx().effective_gas_price(basefee);
92-
let gas_used = exec_result.gas().used() as u128;
92+
let gas_used = exec_result.gas().used();
9393

94-
// Calculate total fee (base fee + priority fee) instead of just priority fee
95-
let total_fee_amount = U256::from(effective_gas_price * gas_used);
94+
let total_fee_amount = U256::from(effective_gas_price) * U256::from(gas_used);
9695

9796
// Transfer the total fee to the beneficiary (both base fee and priority fee)
9897
evm.ctx_mut()
@@ -505,6 +504,62 @@ mod tests {
505504
);
506505
}
507506

507+
#[test]
508+
fn test_reward_beneficiary_large_values_no_overflow() {
509+
let beneficiary = address!("1100000000000000000000000000000000000011");
510+
let caller = address!("2200000000000000000000000000000000000022");
511+
// Values that would overflow u128 when multiplied: (u128::MAX / 1000) * 2000 > u128::MAX
512+
let gas_price = u128::MAX / 1000;
513+
let gas_used = 2000u64;
514+
515+
let db: CacheDB<EmptyDBTyped<Infallible>> = CacheDB::new(EmptyDB::default());
516+
let mut evm = Context::mainnet().with_db(db).build_mainnet();
517+
518+
evm.block.beneficiary = beneficiary;
519+
evm.block.basefee = 0;
520+
evm.tx.caller = caller;
521+
evm.tx.gas_price = gas_price;
522+
523+
let interpreter_result = InterpreterResult::new(
524+
InstructionResult::Return,
525+
alloy_primitives::Bytes::new(),
526+
Gas::new_spent(gas_used),
527+
);
528+
let call_outcome = CallOutcome::new(interpreter_result, 0..0);
529+
let mut exec_result = FrameResult::Call(call_outcome);
530+
531+
let initial_balance = evm
532+
.journaled_state
533+
.load_account(beneficiary)
534+
.unwrap()
535+
.info
536+
.balance;
537+
538+
let handler: ArcEvmHandler<_, EVMError<Infallible>> =
539+
ArcEvmHandler::new(ArcHardforkFlags::default());
540+
let result = handler.reward_beneficiary(&mut evm, &mut exec_result);
541+
542+
assert!(
543+
result.is_ok(),
544+
"reward_beneficiary should succeed with large values"
545+
);
546+
547+
let expected_fee = U256::from(gas_price) * U256::from(gas_used);
548+
549+
let final_balance = evm
550+
.journaled_state
551+
.load_account(beneficiary)
552+
.unwrap()
553+
.info
554+
.balance;
555+
let balance_increase = final_balance - initial_balance;
556+
557+
assert_eq!(
558+
balance_increase, expected_fee,
559+
"Beneficiary should receive correct fee even with large values that would overflow u128"
560+
);
561+
}
562+
508563
#[derive(Debug)]
509564
struct BlocklistTestCase {
510565
name: &'static str,

0 commit comments

Comments
 (0)