Giter Club home page Giter Club logo

contracts's People

Contributors

hcaw avatar nateawelch avatar

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

contracts's Issues

Certain Executions of performSwap will break with Istanbul hard fork

Background

The upcoming Istanbul Ethereum hardfork contains the EIP-1884. EIP-1884 will, besides other things, raise the gas cost of the EVM SLOAD instruction from 200 to 800 gas.

Issue Description

When the TotlePrimary contract executes the performSwap function, it might execute the minimumRateFailed function, which internally calls getDecimals on the target token contract. As part of this call, getDecimals only passes 5000 gas:

let success := call(
5000, // Amount of gas
token, // Address to call
0, // ether to send
ptr, // ptr to input data
functionSigLength, // size of data
ptr, // where to store output data (overwrite input)
wordLength // size of output data (32 bytes)
)

If this the target token is Augur's REP token, then the Delegator will be called. This call currently consumes 4511 gas and successfully returns 18.

However, this call also contains three invocations of SLOAD, so it will cost 6311 after the activation of the Istanbul hard fork. Then, the call will fail (as it is out-of-gas). TotlePrimary will interpret the falling call as 0 decimals:

switch success
case 0 {
decimals := 0 // If the token doesn't implement `decimals()`, return 0 as default
}
case 1 {
decimals := mload(ptr) // Set decimals to return data from call
}
mstore(0x40,add(ptr,0x04)) // Reset the free memory pointer to the next known free location

As the decimals are used to calculate token quantities, incorrect token quantities will be computed. Hence, users would be as the security check for the minimum rate could be circumvented.

Example

The scenario described above recently took place in the following transaction.
This trade converted 0.06978 Ether into 1.497 Reputation (REP) tokens.

Additional Information

ChainSecurity has conducted some analysis on the effects of EIP-1884. The intermediate results can be found here.

Martin Holst Swende has collected information on the effects of EIP-1884 here.

Contact

Feel free to contact [email protected] or @HRitzdorf on Telegram in case of questions or comments.

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.