This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 562
Set an upper bound to gasWanted to prevent DoS attack #991
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now, we are back to the issue where the proposed block includes many transactions that will never get executed. E.g. I ran the test with 50 tx of ~700k gas, all of them were included in the first block, but only 12 were executed.
I do not have a solution yet for solving both these problems, but I am thinking about:
gasUsed
for thisgasWanted
limit in the ante handlergasWanted
works in general for the cosmos sdk. I am wondering if this issue (ddos vs. including too many tx because of gasWanted) is a general cosmos sdk problem and if not, why not.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just saw the list of proposals here #989 (comment) and the long term solution sounds right
This temporary fix is ok from my side.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cosmos-sdk don't refund unused gases, so it's not an issue there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although this is treated as a temporary fix, I want to propose this idea for further discussion that if we can make this slightly smarter. For example
data
field of the EVM Tx, if it is a simple transfer with no data,gasWanted
is 21000gasWanted
gasWanted
asMIN(21000, gasLimit / n)
where n can be further decided.For 2-ii, an attacker could still specify a very large gas limit with this, so this approach would potentially require to charge the sender the
MAX(gasWanted, gasLimit/n)
to create a base line of defence ... something borrowed from #989.However, this requires a change of the gas refund approach, which is a bigger decision to make than the tx inclusion logic. Charging the user the
gasPrice*gasLimit
is common on Cosmos world but probably not on ETH world.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how about still use the
gasLimit
but put a maximum limitation so that there is still a "minimum" of transaction that can be accepted?Someone wouldnt be able to DOS without spending fair amount of gas in that case?
I guess if someone really send a transaction that consume gas over this limit, then we will still have the previous issues of transactions being included but not be executed.
Depending on the value of the max limitation, only one case could be mitigated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put a maximum limitation to
gasLimit
sounds good.pick an arbitrary value:
500000
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this potentially breaking? In a theoretical world there could be a codepath that requires more than 500k gas to execute. If a chain upgrades to this version of ethermint it could fully brick someones smart contract.
Temporarily I guess it's fine though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn't affect the tx execution, because the gas meter is infinite (with limit), so only affects the
gasWanted
returned to tendermint which uses it to decide the tx inclusion.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh yes true, the evm uses infinite, thanks yihuang