Skip to content
Smart contracts Audit finding Intermediate

Incorrect erc7201 storage implementation in core factory contracts

The ArcTokenFactory and RestrictionsFactory contracts claim ERC7201 namespaced storage but compute the storage slot with a plain keccak256 of the namespace instead of the ERC7201 formula. This could allow storage collisions with inherited library slots during upgrades, potentially corrupting state or breaking token creation and restriction module mappings.

AasifUsmani Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

50284 sc insight incorrect erc7201 storage implementation in core factory contracts

Submitted on Jul 23rd 2025 at 12:17:16 UTC by @AasifUsmani for Attackathon | Plume Network

Description

Brief/Intro

The ArcTokenFactory and RestrictionsFactory contracts claim to implement ERC7201 namespaced storage via @custom:storage-location erc7201: annotations but use incorrect storage slot calculations that violate the ERC7201 specification. This creates potential storage collision risks and is a standards compliance issue in core Plume Chain infrastructure contracts.

Vulnerability Details

Root Cause Analysis

Both factory contracts contain identical violations of the ERC7201 standard.

  1. ArcTokenFactory.sol (simplified excerpt):
Solidity
/// @custom:storage-location erc7201:arc.factory.storage
struct FactoryStorage {
    // ... storage fields
}

// ❌ VIOLATION: Uses simple keccak256 instead of ERC7201 formula
bytes32 private constant FACTORY_STORAGE_LOCATION = keccak256("arc.factory.storage");

function _getFactoryStorage() private pure returns (FactoryStorage storage fs) {
    bytes32 position = FACTORY_STORAGE_LOCATION;
    assembly {
        fs.slot := position
    }
}
  1. RestrictionsFactory.sol (simplified excerpt):
Solidity
/// @custom:storage-location erc7201:restrictions.factory.storage
struct FactoryStorage {
    // ... storage fields  
}

// ❌ VIOLATION: Uses simple keccak256 instead of ERC7201 formula
bytes32 private constant FACTORY_STORAGE_LOCATION = keccak256("restrictions.factory.storage");

function _getFactoryStorage() private pure returns (FactoryStorage storage fs) {
    bytes32 position = FACTORY_STORAGE_LOCATION;
    assembly {
        fs.slot := position
    }
}

ERC7201 Standard Requirements

According to EIP-7201, the correct storage slot calculation must be:

Solidity
// Correct ERC7201 implementation:
bytes32 private constant FACTORY_STORAGE_LOCATION = 
    keccak256(abi.encode(uint256(keccak256("arc.factory.storage")) - 1)) & ~bytes32(uint256(0xff));

The ERC7201 formula ensures collision resistance through:

  • Double hashing: keccak256(abi.encode(uint256(keccak256(namespace)) - 1))
  • Byte masking: & ~bytes32(uint256(0xff)) ensures the last byte is 0x00
  • Offset subtraction: -1 prevents direct collision with the inner hash

Impact Details

Storage Collision Risks

Because the contracts use a plain keccak256(namespace) as the storage slot:

  • It can collide with storage slots used by common libraries (e.g., OpenZeppelin AccessControlUpgradeable, UUPSUpgradeable, Initializable).
  • During upgrades, overlapping slots could corrupt state leading to broken behavior or loss of funds.

System-Level Impact

These are core infrastructure contracts:

  • ArcTokenFactory manages creation and upgrades of ARC tokens.
  • RestrictionsFactory manages restriction module deployments.

Storage corruption in either can:

  • Break token creation/upgrades
  • Corrupt restriction module mappings
  • Cause system-wide degradation and require emergency migrations

Standards Compliance Issue

Contracts claim ERC7201 compliance via annotations but do not implement its slot calculation correctly. This misleads developers/auditors and breaks tooling that expects ERC7201 namespaces.

Required Actions

{% stepper %} {% step %}

Correct storage slot calculation

Immediately correct the storage slot calculations to follow the ERC-7201 formula (double-hash + offset + byte mask) for each @custom:storage-location erc7201: namespace. {% endstep %}

{% step %}

Align annotations with actual implementation

If ERC7201 is not being implemented, remove or correct the @custom:storage-location erc7201: annotations so documentation and code are consistent. {% endstep %} {% endstepper %}

References

  1. ArcTokenFactory: https://github.com/immunefi-team/attackathon-plume-network/blob/580cc6d61b08a728bd98f11b9a2140b84f41c802/arc/src/ArcTokenFactory.sol#L62
  2. RestrictionsFactory: https://github.com/immunefi-team/attackathon-plume-network/blob/580cc6d61b08a728bd98f11b9a2140b84f41c802/arc/src/restrictions/RestrictionsFactory.sol#L43
  3. EIP - 7201 documentation and mandates: https://eips.ethereum.org/EIPS/eip-7201

Proof of Concept

<details> <summary>PoC solidity test demonstrating slot differences (click to expand)</summary>

To run the PoC, create a new file in arc/tests/EIPTests.t.sol and copy/paste the following. Run: forge test --mt test_StorageSlotCalculationComparison -vvvv --via-ir

Solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import "forge-std/Test.sol";
import "forge-std/console.sol";

contract ERC7201ViolationTest is Test {
    
    function test_StorageSlotCalculationComparison() public view {
        // Current implementation (INCORRECT)
        bytes32 currentArcFactory = keccak256("arc.factory.storage");
        bytes32 currentRestrictionsFactory = keccak256("restrictions.factory.storage");
        
        // Correct ERC7201 implementation
        bytes32 correctArcFactory = keccak256(
            abi.encode(uint256(keccak256("arc.factory.storage")) - 1)
        ) & ~bytes32(uint256(0xff));
        
        bytes32 correctRestrictionsFactory = keccak256(
            abi.encode(uint256(keccak256("restrictions.factory.storage")) - 1)
        ) & ~bytes32(uint256(0xff));
        
        console.log("=== Storage Slot Comparison ===");
        console.log("ArcTokenFactory:");
        console.logBytes32(currentArcFactory);
        console.log("Should be:");
        console.logBytes32(correctArcFactory);
        
        console.log("RestrictionsFactory:");
        console.logBytes32(currentRestrictionsFactory);
        console.log("Should be:");
        console.logBytes32(correctRestrictionsFactory);
        
        // Demonstrate they are different
        assert(currentArcFactory != correctArcFactory);
        assert(currentRestrictionsFactory != correctRestrictionsFactory);
        
        // Show ERC7201 slots always end in 0x00
        assert(uint8(uint256(correctArcFactory)) == 0);
        assert(uint8(uint256(correctRestrictionsFactory)) == 0);
        
        console.log("ERC7201 violation confirmed: slots do not match standard");
    }
}
</details>

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

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

Likely the developers used a plain keccak256 hash of the namespace string as the storage slot instead of the ERC7201 double-hash, offset and byte-mask formula.

Impact

Storage slots could collide with common upgradeable libraries, and during upgrades overlapping slots could corrupt state, break token creation or restriction mappings, and require emergency migrations.

What the attacker needed

Contracts are upgradeable; storage layout overlaps with a library

The fix

The storage slot calculation should be corrected to follow the ERC7201 formula, or the ERC7201 annotations should be removed if the standard is not implemented.

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.

Smart contracts store data in numbered slots. A namespaced storage pattern gives a contract its own private area so it does not clash with data from libraries it inherits. The contracts here said they used the official ERC7201 way to pick that area, but they used a simpler calculation, so the area might overlap with another library's data and corrupt it.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by AasifUsmani

View all

8 more disclosed reports, best first.

More from Plume Network

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.