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

Use proxy clones to create Synths & LPTokens #21

Open
code423n4 opened this issue Nov 10, 2021 · 0 comments
Open

Use proxy clones to create Synths & LPTokens #21

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

Comments

@code423n4
Copy link
Contributor

Handle

nathaniel

Vulnerability details

Impact

In SynthFactory, the number of Synths will likely be equal to the number of unique foreign tokens in the protocol. Using proxy clones instead of deploying the entire contract can greatly reduce gas fees (~860,000 -> ~150,000 by my estimate testing with Remix). The change is as follows:

  • Change the Synth base contract from ERC20 to ERC20Upgradeable.
  • Replace the Synth constructor with an initialize function.
  • In createSynth, leverage openZeppelins proxy clone to clone the Synth contract and then immediately run the initializer on the clone synthClone.initialize(token)
    The same pattern could be implemented for LPTokens.

Proof of Concept

https://github.com/code-423n4/2021-11-vader/blob/main/contracts/dex-v2/synths/SynthFactory.sol#L31
https://github.com/code-423n4/2021-11-vader/blob/main/contracts/dex-v2/wrapper/LPWrapper.sol#L29
https://docs.openzeppelin.com/contracts/4.x/api/proxy#Clones

Tools Used

manual review

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Nov 10, 2021
code423n4 added a commit that referenced this issue Nov 10, 2021
@SamSteinGG SamSteinGG added the sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons label Nov 25, 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) LPWrapper sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons SynthFactory
Projects
None yet
Development

No branches or pull requests

3 participants