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

FixedPricePassThruGate.sol All the msg.value should be pass thru to gate.beneficiary instead of gate.ethCost #154

Closed
code423n4 opened this issue May 8, 2022 · 3 comments
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate This issue or pull request already exists

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/FixedPricePassThruGate.sol#L46-L56

Vulnerability details

In FixedPricePassThruGate.sol#passThruGate(), at L48 the msg.value is checked to be >= gate.ethCost instead of == gate.ethCost, which makes it possible for the caller to send more than gate.ethCost.

However, at L53 only the amount of gate.ethCost is passed thru to gate.beneficiary instead of all the msg.value.

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/FixedPricePassThruGate.sol#L46-L56

function passThruGate(uint index, address) override external payable {
    Gate memory gate = gates[index];
    require(msg.value >= gate.ethCost, 'Please send more ETH');

    // pass thru ether
    if (msg.value > 0) {
        // use .call so we can send to contracts, for example gnosis safe, re-entrance is not a threat here
        (bool sent, bytes memory data) = gate.beneficiary.call{value: gate.ethCost}("");
        require(sent, 'ETH transfer failed');
    }
}

As a result, any surplus funds sent by the caller will be stuck in the contract forever, and there is no way for anyone to retrieve them.

Recommendation

Change to:

(bool sent, bytes memory data) = gate.beneficiary.call{value: msg.value}("");

See also: the implementation of SpeedBumpPriceGate.sol correctly forwarded all the msg.value.

https://github.com/code-423n4/2022-05-factorydao/blob/db415804c06143d8af6880bc4cda7222e5463c0e/contracts/SpeedBumpPriceGate.sol#L65-L82

function passThruGate(uint index, address) override external payable {
    uint price = getCost(index);
    require(msg.value >= price, 'Please send more ETH');

    // bump up the price
    Gate storage gate = gates[index];
    // multiply by the price increase factor
    gate.lastPrice = (price * gate.priceIncreaseFactor) / gate.priceIncreaseDenominator;
    // move up the reference
    gate.lastPurchaseBlock = block.number;

    // pass thru the ether
    if (msg.value > 0) {
        // use .call so we can send to contracts, for example gnosis safe, re-entrance is not a threat here
        (bool sent, bytes memory data) = gate.beneficiary.call{value: msg.value}("");
        require(sent, 'ETH transfer failed');
    }
}
@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 May 8, 2022
code423n4 added a commit that referenced this issue May 8, 2022
@illuzen
Copy link
Collaborator

illuzen commented May 11, 2022

Duplicate #49

@illuzen illuzen closed this as completed May 11, 2022
@illuzen illuzen added the duplicate This issue or pull request already exists label May 11, 2022
@gititGoro gititGoro added 3 (High Risk) Assets can be stolen/lost/compromised directly and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Jun 14, 2022
@gititGoro
Copy link
Collaborator

Upgrated severity: lost funds

@gititGoro
Copy link
Collaborator

Duplicate of #48

@gititGoro gititGoro marked this as a duplicate of #48 Jun 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants