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

set lastFee in initialize() function #94

Open
code423n4 opened this issue Sep 21, 2021 · 1 comment
Open

set lastFee in initialize() function #94

code423n4 opened this issue Sep 21, 2021 · 1 comment
Labels
bug Warden finding 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

itsmeSTYJ

Vulnerability details

Impact

Gas optimisation

Recommended Mitigation Steps

The if branch in the handleFee() function is only there to handle the very first time handleFees are called. Thereafter, this condition will always fail so it makes more sense to initialize it with the initialize() function.

function initialize(IFactory.Proposal memory proposal, IAuction auction_) public override {
    publisher = proposal.proposer;
    licenseFee = proposal.licenseFee;
    factory = IFactory(msg.sender);
    auction = auction_;
    ibRatio = BASE;
    tokens = proposal.tokens;
    weights = proposal.weights;
		lastFee = block.timestamp;      // updated lastFee here
    approveUnderlying(address(auction));

    __ERC20_init(proposal.tokenName, proposal.tokenSymbol);
}
...

function handleFees() private {
    // if (lastFee == 0) {            // delete this
    //     lastFee = block.timestamp; // delete this
    // } else {                       // delete this
    uint256 startSupply = totalSupply();

    uint256 timeDiff = (block.timestamp - lastFee);
    uint256 feePct = timeDiff * licenseFee / ONE_YEAR;
    uint256 fee = startSupply * feePct / (BASE - feePct);

    _mint(publisher, fee * (BASE - factory.ownerSplit()) / BASE);
    _mint(Ownable(address(factory)).owner(), fee * factory.ownerSplit() / BASE);
    lastFee = block.timestamp;

    uint256 newIbRatio = ibRatio * startSupply / totalSupply();
    ibRatio = newIbRatio;

    emit NewIBRatio(ibRatio);
    // }                              // delete this
}
code423n4 added a commit that referenced this issue Sep 21, 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

Agree with finding, simplifies code and streamlines the logic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Warden finding 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