Skip to content
This repository was archived by the owner on Jul 10, 2026. It is now read-only.

Commit d958a15

Browse files
committed
set code size for precompile
1 parent 7aed5c2 commit d958a15

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

frame/evm/src/lib.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,24 @@ impl<T: Config> Pallet<T> {
10521052
/// Get the account metadata (hash and size) from storage if it exists,
10531053
/// or compute it from code and store it if it doesn't exist.
10541054
pub fn account_code_metadata(address: H160) -> CodeMetadata {
1055+
const EMPTY_CODE_HASH: [u8; 32] =
1056+
hex_literal::hex!("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
1057+
1058+
let is_precompile = match T::PrecompilesValue::get().is_precompile(address, 0) {
1059+
IsPrecompileResult::Answer { is_precompile, .. } => is_precompile,
1060+
IsPrecompileResult::OutOfGas => false,
1061+
};
1062+
1063+
// If the address is a precompile, we return size 1 and empty hash.
1064+
// Then the contract call bypass the code size check for precompile calls.
1065+
// It will make the call like IPrecompile.call successful.
1066+
if is_precompile {
1067+
return CodeMetadata {
1068+
size: 1,
1069+
hash: EMPTY_CODE_HASH.into(),
1070+
};
1071+
}
1072+
10551073
if let Some(meta) = <AccountCodesMetadata<T>>::get(address) {
10561074
return meta;
10571075
}
@@ -1061,9 +1079,6 @@ impl<T: Config> Pallet<T> {
10611079
// If code is empty we return precomputed hash for empty code.
10621080
// We don't store it as this address could get code deployed in the future.
10631081
if code.is_empty() {
1064-
const EMPTY_CODE_HASH: [u8; 32] = hex_literal::hex!(
1065-
"c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"
1066-
);
10671082
return CodeMetadata {
10681083
size: 0,
10691084
hash: EMPTY_CODE_HASH.into(),

0 commit comments

Comments
 (0)