Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No Storage Gap for Upgradable Contracts #300

Closed
code423n4 opened this issue Dec 30, 2022 · 7 comments
Closed

No Storage Gap for Upgradable Contracts #300

code423n4 opened this issue Dec 30, 2022 · 7 comments
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue fix token (sponsor) Token related fix, should be fixed prior to launch grade-c primary issue Highest quality submission among a set of duplicates QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-12-gogopool/blob/main/contracts/contract/tokens/upgradeable/ERC20Upgradeable.sol#L10
https://github.com/code-423n4/2022-12-gogopool/blob/main/contracts/contract/tokens/upgradeable/ERC4626Upgradeable.sol#L11

Vulnerability details

Impact

The ERC20Upgradable.sol and ERC4626Upgradable.sol contracts are abstract, upgradable contracts where inheriting may introduce new storage variables. In order to safely upgrade the contracts which may include adding new storage variables, a storage gap should be added to both abstract contracts. The OpenZeppelin TimelockControllerUpgradable.sol contract demonstrates how this can be done.

If no storage gap is added and if the upgradable contracts introduce new variables, this may cause storage collisions which will result in the overriding of existing variables in the inheriting contract.

Proof of Concept

Recommended Mitigation Steps

It's recommended that the upgradable contracts ERC20Upgradable.sol and ERC4626Upgradable.sol include a storage gap similar to the following either at the foot or the head of the contract as a storage variable:

abstract contract ERC20Upgradeable is Initializable {

============================ SNIP ============================

	mapping(address => uint256) public balanceOf;

	mapping(address => mapping(address => uint256)) public allowance;

	/*//////////////////////////////////////////////////////////////
                            EIP-2612 STORAGE
    //////////////////////////////////////////////////////////////*/

	uint256 internal INITIAL_CHAIN_ID;

	bytes32 internal INITIAL_DOMAIN_SEPARATOR;

	mapping(address => uint256) public nonces;

	uint256[48] private __storageGap;

============================ SNIP ============================

	
@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Dec 30, 2022
code423n4 added a commit that referenced this issue Dec 30, 2022
C4-Staff added a commit that referenced this issue Jan 6, 2023
@c4-judge
Copy link
Contributor

c4-judge commented Jan 8, 2023

GalloDaSballo marked the issue as primary issue

@c4-judge c4-judge added the primary issue Highest quality submission among a set of duplicates label Jan 8, 2023
@GalloDaSballo
Copy link

Better because of suggested remediation

@emersoncloud
Copy link

This is a fair point, but only an issue if we intend to modify ERC20Upgradeable or ERC4626Upgradeable implementation contract behind a proxy.

@emersoncloud emersoncloud added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Jan 17, 2023
@0xju1ie 0xju1ie added the fix token (sponsor) Token related fix, should be fixed prior to launch label Jan 20, 2023
@GalloDaSballo
Copy link

After consulting the Rulebook

Am downgrading to Low Severity.

The Sponsor may not extend storage of child contracts, that is not inherently a vulnerability but a risk we're flagging as QA - Low Severity

@GalloDaSballo
Copy link

L

@c4-judge c4-judge added downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Feb 2, 2023
@c4-judge
Copy link
Contributor

c4-judge commented Feb 2, 2023

GalloDaSballo changed the severity to QA (Quality Assurance)

@c4-judge
Copy link
Contributor

c4-judge commented Feb 8, 2023

GalloDaSballo marked the issue as grade-c

@c4-judge c4-judge closed this as completed Feb 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue fix token (sponsor) Token related fix, should be fixed prior to launch grade-c primary issue Highest quality submission among a set of duplicates QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

5 participants