Coder Social home page Coder Social logo

pimlicolabs / erc20-paymaster Goto Github PK

View Code? Open in Web Editor NEW
64.0 64.0 17.0 920 KB

An ERC-4337 Paymaster contract by Pimlico that is able to sponsor gas fees in exchange for ERC-20 tokens

Home Page: https://pimlico.io

License: MIT License

Solidity 100.00%

erc20-paymaster's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

erc20-paymaster's Issues

Potential risk of unlimited UserOP gas fee

Hi,

There is not limit on the gas fee of one UserOP. A malicious user can compose an UserOP with very high preVerificationGas or maxPriorityFeePerGas, making the gas fee high enough to drain all the eth of the Paymaster. Note in this case the malicious user can bundle this UserOP with his own bundler, so that the profit is returned to himself. This means malicious user only lose the actual gas fee (which is low) of executing the UserOP.

This can be expolited for below purpose:

  1. Attack Paymaster to make it unavailable: Drain all the eth from paymaster in a low cost.
  2. Swap ERC20 token to eth in a favorable price: The token price is read from Oracle and is updated in postOp. It's possible that the price deviates from the actual price in extreme cases. The malicious user can compose an UserOP with high gas fee, use TokenPaymaster and bundle it with his own bundler. In this case the malicious user pay ERC20 token and get eth in a favorable price.

Update `Magic Numbers` with `constants` and Update `public` variables with `private` for gas-efficiency

This codebase currently uses magic numbers in certain areas. Replacing these magic numbers with descriptive constants will significantly improve code readability and maintainability.

uint256 public constant PRICE_DENOMINATOR = 1e6;

1e6 magic number can be updated with PRICE_DENOMINATOR in the below line

if (_priceMarkup < 1e6) {
revert PriceMarkupTooLow();
}

if (_tokenOracle.decimals() != 8 || _nativeAssetOracle.decimals() != 8) {
revert OracleDecimalsInvalid();
}

The above lines can be updated with the below lines of code.

uint256 private constant DECIMAL_PRECISION = 8;

.
.
.

if (_tokenOracle.decimals() != DECIMAL_PRECISION || _nativeAssetOracle.decimals() != DECIMAL_PRECISION) { 
     revert OracleDecimalsInvalid(); 
 } 

some more magic numbers are used. It can be updated with constants

Also, Instead of declaring all variables as public. All variables can be declared as private and we can write external getter functions to get the values. Which can prove to be gas-efficient.

-  uint256 public constant PRICE_DENOMINATOR = 1e6; 
+ uint256 private constant PRICE_DENOMINATOR = 1e6; 

External Getter function

function getPriceDenominator() external view returns(uint256){
     return PRICE_DENOMINATOR;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.