-
Notifications
You must be signed in to change notification settings - Fork 293
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
article: Efficient gas calculation algorithm for EVM #123
Conversation
Codecov Report
@@ Coverage Diff @@
## master #123 +/- ##
=========================================
Coverage ? 99.88%
=========================================
Files ? 5
Lines ? 839
Branches ? 109
=========================================
Hits ? 838
Misses ? 1
Partials ? 0 |
A _basic block_ is a sequence of instructions that are executed "straight-line" | ||
without being interrupted by jumps. I.e. they are nodes in the _control flow graph_. | ||
|
||
The name "basic block" has been taken from LLVM. Other names are: just "block" |
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 just the generic term in compiler theory?
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 never had proper education in this field. If the term is well known, I should simplify this paragraph.
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.
Not sure about the well-known-ness, but llvm certainly did not introduce it :)
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'd prefer if you called it 'basic segment', and talk about segments. Because we're talking about blockchains here, and in extension maybe doing paralell gas-calculation of future blocks, and things become a bit messy if we have two definitions for 'block'.
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.
This is pretty concrete term: https://en.wikipedia.org/wiki/Basic_block.
Maybe "basic instruction block" then?
- `RETURN`, | ||
- `REVERT`, | ||
- `SELFDESTRUCT`, | ||
- an instruction directly preceding `JUMPDEST`. |
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.
- an instruction directly preceding `JUMPDEST`. | |
- the last instruction in the program | |
- an invalid instruction |
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.
We actually ignore invalid instructions by assuming they cost 0.
- an instruction directly preceding `JUMPDEST`. | ||
|
||
2. The following instructions _start_ a basic block: | ||
- `JUMPDEST`, |
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.
- `JUMPDEST`, |
(this should be redundant together with the two rules below)
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 don't believe this is true. You can have a JUMPDEST
anywhere.
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.
sure, but you say: a basic block starts right before ... an instruction directly after an intruction that has ended the previous basic block. And above: a basic block ends after ... an instruction directly preceding "jumpdest". Maybe just nitpicking :)
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'm wondering about the attackability of this -- in hte case where a contract consists of 24k JUMPDEST
s. I guess that's up to the implementation.
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 have a test/benchmark for this one. Other variations about it are definitely needed.
evmone's top speed is ~1Ggas/s. In this case where we do gas/stack checking for every instruction the execution is ~0.5Ggas/s.
The bigger problem is the analysis of this code takes ~0.1 ms what means it should cost ~1000 gas. This is the biggest concern so far.
Co-Authored-By: chriseth <chris@ethereum.org> Co-Authored-By: Andrei Maiboroda <andrei@ethereum.org>
8a700a5
to
1e703dd
Compare
TODO: