Part 2

Zaros
PerpetualsDEXFoundrySolidity
70,000 USDC
View results
Submission Details
Severity: low
Valid

Several libraries are not ERC7201 compliant

Summary

Several libraries don't follow strictly the ERC7201 formula.

Vulnerability Details

The AssetSwapPath, Collateral, CreditDelegation, DexSwapStrategy, LiveMarkets, Market, MarketMakingEngineConfiguration, Swap, UsdTokenSwapConfig, Vault, WithdrawalRequest libraries don't follow exactly the formula prescribed by ERC-7201: keccak256(abi.encode(uint256(keccak256(bytes(id))) - 1)) & ~bytes32(uint256(0xff)).

If we consider the storage location from DexSwapStretegy library:

bytes32 internal constant DEX_SWAP_STRATEGY_LOCATION =
keccak256(abi.encode(uint256(keccak256("fi.zaros.market-making.DexSwapStrategy")) - 1));

this will give the following result: 0xf3be8de7606a57190c7fdb4ad92f0badfc4dbea37908a77169bed41d0057c840.

If we apply the exact ERC7201 formula:

bytes32 internal constant DEX_SWAP_STRATEGY_LOCATION =
keccak256(abi.encode(uint256(keccak256(bytes(id))) - 1)) & ~bytes32(uint256(0xff))

Then the result will be: 0xf3be8de7606a57190c7fdb4ad92f0badfc4dbea37908a77169bed41d0057c800.

Impact

The omitted part of the ERC7201 formula: & ~bytes32(uint256(0xff)) guarantees the last byte is 0x00 and this ensures proper storage alignment in future upgrades. The current version ignores this and the created slots don't end with 00 as the rightmost bytes. The protocol is expected to be ERC-7201 compatible, several libraries are prone to storage collision if not follow the specification. Failure to comply with ERC712 can lead to integration issues.

Tools Used

Manual Review

Recommendations

Used the exact ERC7201 formula to calculate the required storage slot in the AssetSwapPath, Collateral, CreditDelegation, DexSwapStrategy, LiveMarkets, Market, MarketMakingEngineConfiguration, Swap, UsdTokenSwapConfig, Vault, WithdrawalRequest libraries.

Updates

Lead Judging Commences

inallhonesty Lead Judge 10 months ago
Submission Judgement Published
Validated
Assigned finding tags:

ERC7201 implemented incorrectly

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.

Give us feedback!