Skip to content

Add std::evm::erc20::Erc20 token component with permit - #1675

Draft
cburgdorf wants to merge 3 commits into
masterfrom
std-erc20
Draft

cburgdorf wants to merge 3 commits into
masterfrom
std-erc20

Conversation

@cburgdorf

Copy link
Copy Markdown
Collaborator

THIS IS JUST FOOD FOR THOUGHT!

Port Solady's ERC20 as a storage component instead of a base contract. A contract keeps an Erc20 in a field and answers the standard messages IErc20 and IErc20Permit by delegating to it; customization happens in the contract's own handlers around the component's methods, so there are no virtual hooks. The effects on each method show what it touches, and mint and burn perform no access control so the contract decides who reaches them.

Semantics follow Solady: its custom errors, true on success, a u256::max() allowance is never spent, transfers to the zero address are allowed. The storage layout is Fe's own.

The permit is split into verify_permit, which checks the deadline and the signature against the current nonce and returns a VerifiedPermit that only std can construct, and permit, which consumes the nonce and sets the allowance and accepts nothing else. The split also sidesteps a borrow checker false positive: a precompile STATICCALL (ecrecover, sha256, modexp) inside a mut self method on a contract field struct with a scalar field is rejected as a conflicting borrow. Malleable signatures are rejected through std's canonical ecrecover.

The component's mut self methods write StorageMap fields of a struct with a scalar field, which needs #1659; with #1659 merged the fixture passes, including a permit signed with cast.

@cburgdorf
cburgdorf force-pushed the std-erc20 branch 3 times, most recently from a9dc20c to 4b9633c Compare October 4, 2026 22:00
Port Solady's ERC20 as a storage component instead of a base contract.
A contract keeps an Erc20 in a field and answers the standard messages
IErc20 and IErc20Permit by delegating to it; customization happens in
the contract's own handlers around the component's methods, so there are
no virtual hooks. The effects on each method show what it touches, and
mint and burn perform no access control so the contract decides who
reaches them.

Semantics follow Solady: its custom errors, true on success, a
u256::max() allowance is never spent, transfers to the zero address are
allowed. The storage layout is Fe's own.

The permit is split into verify_permit, which checks the deadline and
the signature against the current nonce and returns a VerifiedPermit
that only std can construct, and permit, which consumes the nonce and
sets the allowance and accepts nothing else. The split also sidesteps a
borrow checker false positive: a precompile STATICCALL (ecrecover,
sha256, modexp) inside a mut self method on a contract field struct
with a scalar field is rejected as a conflicting borrow. Malleable
signatures are rejected through std's canonical ecrecover.

The fixture covers a permit signed with cast.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant