-
Notifications
You must be signed in to change notification settings - Fork 765
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
Add EIP-1884 support for Istanbul #581
Merged
Merged
Changes from all commits
Commits
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const tape = require('tape') | ||
const BN = require('bn.js') | ||
const Common = require('ethereumjs-common').default | ||
const VM = require('../../../dist/index').default | ||
const PStateManager = require('../../../dist/state/promisified').default | ||
const { ERROR } = require('../../../dist/exceptions') | ||
const { createAccount } = require('../utils') | ||
|
||
const testCases = [ | ||
{ chain: 'mainnet', hardfork: 'istanbul', selfbalance: '0xf1' }, | ||
{ chain: 'mainnet', hardfork: 'constantinople', err: ERROR.INVALID_OPCODE } | ||
] | ||
|
||
// SELFBALANCE PUSH8 0x00 MSTORE8 PUSH8 0x01 PUSH8 0x00 RETURN | ||
const code = ['47', '60', '00', '53', '60', '01', '60', '00', 'f3'] | ||
tape('Istanbul: EIP-1884: SELFBALANCE', async (t) => { | ||
const addr = Buffer.from('00000000000000000000000000000000000000ff', 'hex') | ||
const runCodeArgs = { | ||
code: Buffer.from(code.join(''), 'hex'), | ||
gasLimit: new BN(0xffff), | ||
address: addr | ||
} | ||
|
||
for (const testCase of testCases) { | ||
const common = new Common(testCase.chain, testCase.hardfork) | ||
const vm = new VM({ common }) | ||
const state = new PStateManager(vm.stateManager) | ||
const account = createAccount('00', testCase.selfbalance) | ||
await state.putAccount(addr, account) | ||
try { | ||
const res = await vm.runCode(runCodeArgs) | ||
if (testCase.err) { | ||
t.equal(res.exceptionError.error, testCase.err) | ||
} else { | ||
t.assert(res.exceptionError === undefined) | ||
t.assert(new BN(Buffer.from(testCase.selfbalance.slice(2), 'hex')).eq(new BN(res.returnValue))) | ||
} | ||
} catch (e) { | ||
t.fail(e.message) | ||
} | ||
} | ||
|
||
t.end() | ||
}) |
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.
Hmm, this breaks with the concept of having gas price changes collected in the Common library (e.g. for SLOAD), I only expected the Istanbul opcode list to include the newly introduced opcodes (
SELFBALANCE
).For the moment this would introduce a lot of inconsistency - we also have added other gas price changes for Istanbul in the istanbul.json file.
Do you have a bigger plan for a complete transition here respectively a strong reasoning for this break apart? Otherwise I would very much suggest we add the price changes to the Common library.
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.
Hmm, I didn't know the base cost of opcodes are also updated in Common (in addition to extra gas parameters like
ecAdd
). If that has been the intention, there's no corresponding code in the VM to read those base gas costs from Common:https://github.com/ethereumjs/ethereumjs-vm/blob/edffcde9696283799efc4ab17d0c3e481618c727/lib/evm/interpreter.ts#L105-L112
If we want to keep base gas costs in Common we'd have to:
Common
(not the case now, searchingswap
in ethereumjs-common returned empty)opcodes.ts
to only have one source of truthInterpreter
to read costs from CommonThere 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.
Hmm, maybe we are talking side by side a bit? What is with
SLOAD
e.g. - the EIP is stating that this is changing gas costs from 200 to 800 - and the 200 price is just "normally" defined in the tangerine whistle json file in the Common library (see link above).This is just a "normal" gas price change, isn't 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.
Ah, just had another look. See the point, these gas costs are not taken by Common at all atm. Maybe this is just more of some inconsistency/incompleteness in the Common library.
Anyhow, you are right. Will approve here.