Skip to content

Commit

Permalink
Feat: Implementation EIP-3607 (#930)
Browse files Browse the repository at this point in the history
## Description

➡️ Implementation of [EIP-3607](https://eips.ethereum.org/EIPS/eip-3607)
- reject transaction for accounts with not empty code.
  • Loading branch information
mrLSD authored and aleksuss committed Oct 10, 2024
1 parent 07e9957 commit 01881db
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
5 changes: 3 additions & 2 deletions engine-tests/src/tests/promise_results_precompile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,15 @@ fn test_promise_result_gas_cost() {

let total_gas1 = y1 + baseline.all_gas();
let total_gas2 = y2 + baseline.all_gas();

assert!(
utils::within_x_percent(15, evm1, total_gas1 / NEAR_GAS_PER_EVM),
utils::within_x_percent(17, evm1, total_gas1 / NEAR_GAS_PER_EVM),
"Incorrect EVM gas used. Expected: {} Actual: {}",
evm1,
total_gas1 / NEAR_GAS_PER_EVM
);
assert!(
utils::within_x_percent(15, evm2, total_gas2 / NEAR_GAS_PER_EVM),
utils::within_x_percent(17, evm2, total_gas2 / NEAR_GAS_PER_EVM),
"Incorrect EVM gas used. Expected: {} Actual: {}",
evm2,
total_gas2 / NEAR_GAS_PER_EVM
Expand Down
4 changes: 2 additions & 2 deletions engine-tests/src/tests/repro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn repro_FRcorNv() {
block_timestamp: 1_650_960_438_774_745_116,
input_path: "src/tests/res/input_FRcorNv.hex",
evm_gas_used: 1_239_721,
near_gas_used: 170,
near_gas_used: 171,
});
}

Expand All @@ -88,7 +88,7 @@ fn repro_5bEgfRQ() {
block_timestamp: 1_651_073_772_931_594_646,
input_path: "src/tests/res/input_5bEgfRQ.hex",
evm_gas_used: 6_414_105,
near_gas_used: 655,
near_gas_used: 656,
});
}

Expand Down
2 changes: 1 addition & 1 deletion engine-tests/src/tests/uniswap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn test_uniswap_input_multihop() {

let (_amount_out, _evm_gas, profile) = context.exact_input(&tokens, INPUT_AMOUNT.into());

assert_eq!(109, profile.all_gas() / 1_000_000_000_000);
assert_eq!(110, profile.all_gas() / 1_000_000_000_000);
}

#[test]
Expand Down
11 changes: 8 additions & 3 deletions engine/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ pub enum EngineErrorKind {
NotOwner,
NonExistedKey,
Erc20FromNep141,
RejectCallerWithCode,
}

impl EngineErrorKind {
Expand Down Expand Up @@ -143,6 +144,7 @@ impl EngineErrorKind {
Self::NotOwner => errors::ERR_NOT_OWNER,
Self::NonExistedKey => errors::ERR_FUNCTION_CALL_KEY_NOT_FOUND,
Self::Erc20FromNep141 => errors::ERR_GETTING_ERC20_FROM_NEP141,
Self::RejectCallerWithCode => errors::ERR_REJECT_CALL_WITH_CODE,
Self::EvmFatal(_) | Self::EvmError(_) => unreachable!(), // unused misc
}
}
Expand Down Expand Up @@ -1032,6 +1034,8 @@ pub fn submit_with_alt_modexp<
tx.try_into()
.map_err(|_e| EngineErrorKind::InvalidSignature)?
};
// Retrieve the signer of the transaction:
let sender = transaction.address;

let fixed_gas = silo::get_fixed_gas(&io);

Expand All @@ -1045,9 +1049,6 @@ pub fn submit_with_alt_modexp<
}
}

// Retrieve the signer of the transaction:
let sender = transaction.address;

sdk::log!("signer_address {:?}", sender);

check_nonce(&io, &sender, &transaction.nonce)?;
Expand Down Expand Up @@ -1075,6 +1076,10 @@ pub fn submit_with_alt_modexp<

let mut engine: Engine<_, _, M> =
Engine::new_with_state(state, sender, current_account_id, io, env);
// EIP-3607
if !engine.code(sender.raw()).is_empty() {
return Err(EngineErrorKind::RejectCallerWithCode.into());
}
let max_gas_price = args.max_gas_price.map(Into::into);
let prepaid_amount = match engine.charge_gas(&sender, &transaction, max_gas_price, fixed_gas) {
Ok(gas_result) => gas_result,
Expand Down
1 change: 1 addition & 0 deletions engine/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,4 @@ pub const ERR_ALLOWED_IN_SILO_MODE_ONLY: &[u8] = b"ERR_ALLOWED_IN_SILO_MODE_ONLY
pub const ERR_INVALID_NEP141_ACCOUNT_ID: &[u8] = b"ERR_INVALID_NEP141_ACCOUNT_ID";
pub const ERR_NEP141_NOT_FOUND: &[u8] = b"ERR_NEP141_NOT_FOUND";
pub const ERR_NEP141_TOKEN_ALREADY_REGISTERED: &[u8] = b"ERR_NEP141_TOKEN_ALREADY_REGISTERED";
pub const ERR_REJECT_CALL_WITH_CODE: &[u8] = b"ERR_REJECT_CALL_WITH_CODE";

0 comments on commit 01881db

Please sign in to comment.