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

Basket.sol#initialize() Remove redundant assertion can save gas #67

Closed
code423n4 opened this issue Oct 10, 2021 · 1 comment
Closed
Labels
bug Warden finding duplicate Another warden found this issue G (Gas Optimization) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")

Comments

@code423n4
Copy link
Contributor

Handle

WatchPug

Vulnerability details

https://github.com/code-423n4/2021-10-defiprotocol/blob/7ca848f2779e2e64ed0b4756c02f0137ecd73e50/contracts/contracts/Basket.sol#L41-L57

function initialize(IFactory.Proposal memory proposal, IAuction auction_) external override {
    require(address(factory) == address(0));
    require(!initialized);

    publisher = proposal.proposer;
    licenseFee = proposal.licenseFee;
    factory = IFactory(msg.sender);
    auction = auction_;
    ibRatio = BASE;
    tokens = proposal.tokens;
    weights = proposal.weights;
    approveUnderlying(address(auction));

    __ERC20_init(proposal.tokenName, proposal.tokenSymbol);

    initialized = true;
}

factory will never be address(0) if initialized == true as it's been set to msg.sender when initialize() being called.

Removing require(address(factory) == address(0)); can make the code simpler and save some gas.

Recommendation

Remove the redundant assertion.

code423n4 added a commit that referenced this issue Oct 10, 2021
@frank-beard frank-beard added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Nov 6, 2021
@GalloDaSballo
Copy link
Collaborator

Duplicate of #29

@GalloDaSballo GalloDaSballo marked this as a duplicate of #29 Dec 19, 2021
@GalloDaSballo GalloDaSballo added the duplicate Another warden found this issue label Dec 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Warden finding duplicate Another warden found this issue G (Gas Optimization) sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Projects
None yet
Development

No branches or pull requests

3 participants