-
Notifications
You must be signed in to change notification settings - Fork 263
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
63/64 Rule and its role in preventing call depth attacks #36
Comments
Since the actual vulnerability referenced here, call depth attacks, has effectively been prevented since EIP-150, I would consider this as more of a heuristic, so not sure how it would fit in to this repo. Might be useful to include a note about 63/64 if relevant for any existing issues though? |
True, call depth attacks have been effectively prevented since EIP-150, but the 63/64 rule has clearly been leveraged in the bug reports linked above to cause some interesting vulnerabilities due to assumptions made about gas calculations. It obviously doesn't classify as a vulnerability on its own(you could argue the same about open redirects vulnerabilities in web2) but can lead to bugs if not taken into consideration when your protocol depends on gas calculation. I do find it relevant to this repository as it is a way to improve the value of this repo. |
@indeqs, I don't disagree. Perhaps we can expand the repo to include heuristics that are relevant to security researchers? I'm not set on this idea, but curious what others think. Perhaps would be worth opening an issue to discuss this |
@kadenzipfel perhaps the below might be a better classification of the vulnerabilities listed in this repo. I also included more vulnerabilities as seen here by @ShieldifyAnon on X/Twitter Gas Management Issues
Reentrancy
Front-running
Flash Loans
Denial of Service (DoS)
Arithmetic Issues
Cryptographic Issues
Price Oracle Manipulation
Cross-Chain Issues
Token Supply Issues
DeFi Specific Vulnerabilities
Malicious Contracts
Unsafe Calls
Social Engineering and Phishing
Ether Handling Issues
Block Attributes and Timing Issues
Function Validation and Standards
Storage and Visibility Issues
Data Handling Issues
Heuristic
Other Issues
This categorization is by no means exhaustive but something we can work with for starters |
@indeqs, this is really useful and I think would be good to open up an issue to discuss taxonomy of vulnerabilities with this being an excellent starting point. Definitely also a ton of findings here that are not already included in this repo, so lots to add! This being said, I don't feel like heuristics really fits in as a category here so not sure how the 63/64 rule will fit into the repo in general. Will leave this open for discussion though |
Also leaving this open for discussion. |
closing this as it is now issue#41 |
Understanding the 63/64 Rule and its Role in Preventing Call Depth Attacks
Introduction
The 63/64 rule was introduced with Ethereum Improvement Proposal (EIP) 150. This rule states that when one contract calls another, a part of the available gas (1/64) will remain in the calling contract, while the rest (63/64) will be forwarded. For instance, if contract A has 64K gas and calls contract B, then contract B will receive 63K gas.
The Problem Addressed by the 63/64 Rule
To understand the reason behind this rule, it is crucial to know about the problem it aims to solve: the "Call Depth Attack."
Call Stack Limit
Ethereum has a call stack limit of 1024. This means no more than 1023 nested calls can be made by a contract before the Ethereum Virtual Machine (EVM) reverts. For example, if we have five contracts calling each other, we would have a call depth of 5:
Call Depth Attack Example
Before EIP-150, this stack limit could be exploited in what was known as the "Call Depth Attack." Consider the following Solidity contract:
The
bid()
function could be exploited by a malicious contract that would initiate a recursive call to itself, causing the stack depth to increase to 1023 before callingbid()
. For instance, a contract B which calls the functionbid()
in contract Auction can recursively call a function within itself 1023 times before calling the functionbid()
. As a result, the.send(highestBid)
call would fail silently, and no refund would happen.How EIP-150 Prevents Call Depth Attacks
This attack is no longer possible after EIP-150, because the forwarded gas (63/64) in each call is reduced exponentially the deeper the stack gets. The available gas at different stack depths is calculated as follows:
gasleft() * (63/64)^0
gasleft() * (63/64)^1
gasleft() * (63/64)^N
This exponential reduction in gas makes it impossible to reach the stack limit, effectively preventing the "Call Depth Attack."
Implications for Protocol Logic and Gas Calculation
It is essential to be aware of this rule if your protocol logic depends on gas calculations, especially if you are using the built-in Solidity
gasleft()
function.References
Most of the above findings are relatively recent (less than a year ago), while EIP-150 has been around for the past 8+ years.
The text was updated successfully, but these errors were encountered: