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

Move from a pull to a push pattern for sending fees to the FeeSplitter #34

Open
code423n4 opened this issue Nov 13, 2021 · 0 comments
Open
Labels
bug Something isn't working G (Gas Optimization) sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons

Comments

@code423n4
Copy link
Contributor

Handle

TomFrench

Vulnerability details

Impact

Gas costs

Proof of Concept

In certain circumstances NestedFactory has to send some fees to the FeeSplitter

To do so it currently does:

  1. Gives FeeSplitter an unlimited approval on the relevant token
  2. Calls FeeSplitter.sendFees telling the FeeSplitter how much and which token has been paid in fees.
    a. Using this, FeeSplitter performs a transferFrom to take these funds from the NestedFactory

https://github.com/code-423n4/2021-11-nested/blob/5d113967cdf7c9ee29802e1ecb176c656386fe9b/contracts/NestedFactory.sol#L491-L503

https://github.com/code-423n4/2021-11-nested/blob/5d113967cdf7c9ee29802e1ecb176c656386fe9b/contracts/FeeSplitter.sol#L220-L235

This requires an SSTORE to set the unlimited approval and then all the relevant SLOADS and SSTORES in order to perform the transferFrom

Instead the NestedFactory could simply transfer the tokens to the FeeSplitter and then simply tell it how much has been paid in fees. This avoids all the costs associated with setting/reading approvals.

The downside is this either:
a. makes FeeSplitter a permissioned function as it needs to trust the caller is a honest
b. makes FeeSplitter need to perform some simple internal accounting when transferring tokens so that the difference between this and the contract's balance can be treated as the newly paid fees.

I'm fairly sure that option b turns out cheaper overall as fees are paid into the splitter much more regularly than they are paid out so increasing the costs of claiming for the benefit of paying is preferable.

Recommended Mitigation Steps

Consider a push pattern for fees with internal accounting of token balances.

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Nov 13, 2021
code423n4 added a commit that referenced this issue Nov 13, 2021
@adrien-supizet adrien-supizet self-assigned this Nov 18, 2021
@adrien-supizet adrien-supizet removed their assignment Nov 23, 2021
@adrien-supizet adrien-supizet added the sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons label Nov 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working G (Gas Optimization) sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Projects
None yet
Development

No branches or pull requests

2 participants