Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/ev-precompiles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface INativeToken {
function burn(address from, uint256 amount) external;
function addToAllowList(address account) external;
function removeFromAllowList(address account) external;
function allowlist(address account) external view returns (bool);
}
```

Expand Down
11 changes: 10 additions & 1 deletion crates/ev-precompiles/src/mint.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Mint precompile

use alloy::{sol, sol_types::SolInterface};
use alloy::{
sol,
sol_types::{SolInterface, SolValue},
};
use alloy_evm::{
precompiles::{Precompile, PrecompileInput},
revm::precompile::{PrecompileError, PrecompileId, PrecompileResult},
Expand All @@ -16,6 +19,7 @@ sol! {
function burn(address from, uint256 amount) external;
function addToAllowList(address account) external;
function removeFromAllowList(address account) external;
function allowlist(address account) external view returns (bool);
}
}

Expand Down Expand Up @@ -232,6 +236,11 @@ impl Precompile for MintPrecompile {
Self::set_allowlisted(internals, call.account, false)?;
Ok(PrecompileOutput::new(0, Bytes::new()))
}
INativeToken::INativeTokenCalls::allowlist(call) => {
let is_allowed = Self::is_allowlisted(internals, call.account)?;
let result = is_allowed.abi_encode();
Ok(PrecompileOutput::new(0, result.into()))
}
Comment on lines +239 to +243

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The allowlist function is declared as view in the Solidity interface, which implies it must not modify blockchain state. The current implementation calls Self::is_allowlisted, which in turn calls Self::ensure_account_created. This can cause a state modification by creating the precompile's account if it doesn't already exist. This side effect violates the read-only guarantee of a view function and can lead to inconsistent behavior across different EVM clients and tools.

To fix this, the read-only logic from is_allowlisted should be inlined here, avoiding the state-mutating call. For consistent logging, you should also duplicate the tracing::debug! call from is_allowlisted.

            INativeToken::INativeTokenCalls::allowlist(call) => {
                // This is a view function; avoid state modifications from `is_allowlisted`.
                let key = Self::allowlist_key(call.account);
                let value = internals
                    .sload(MINT_PRECOMPILE_ADDR, key)
                    .map_err(Self::map_internals_error)?;
                let is_allowed = !value.is_zero();
                let result = is_allowed.abi_encode();
                Ok(PrecompileOutput::new(0, result.into()))
            }

}
}

Expand Down
1 change: 1 addition & 0 deletions docs/adr/ADR-0002-native-minting-precompile.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ interface INativeToken {
function burn(address from, uint256 amount) external;
function addToAllowList(address account) external;
function removeFromAllowList(address account) external;
function allowlist(address account) external view returns (bool);
}
```

Expand Down
Loading