-
Notifications
You must be signed in to change notification settings - Fork 132
feat: Add Gas dimension tracers #457
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
Conversation
We require contributors to sign our Contributor License Agreement. In order for us to review and merge your code, please sign the linked documents below to get yourself added. https://na3.docusign.net/Member/PowerFormSigning.aspx?PowerFormId=b15c81cc-b5ea-42a6-9107-3992526f2898&env=na3&acct=6e152afc-6284-44af-a4c1-d8ef291db402&v=2 |
|
Support live tracing and by RPC, support all pure-CPU opcodes. Support the simple state access opcodes. Rest still TODO
1. EXTCODECOPY with no memory expansion, and warm storage access 2. EXTCODECOPY with memory expansion and warm storage access 3. EXTCODECOPY with memory expansion and cold storage access 4. EXTCODECOPY with no memory expansion and cold storage access
Cold access list SLOAD Warm access list SLOAD
all of the LOG opcodes with both indexed and unindexed data
Selfdestruct to: * cold, empty account target, sender has balance * warm, empty account target, sender has balance * warm, code/value at target, sender has balance * warm, code/value at target, no money to send * cold, code/value at target, sender has balance
Tested: * calling to a contract that is cold but has code * calling to a contract that is cold and has no code
Tested: * calling to a contract that is warm and has code * calling to a contract that is cold and has code * calling to a contract that is warm and has no code * calling to a contract that is cold and has no code
Tested by hand: * Delegatecall to warm address, to a contract with code * Delegatecall to cold address, to a contract with code * Delegatecall to cold address, to a contract with no code * Delegatecall to warm address, to a contract with no code
Tested by Hand: * warm access list+ target has code + zero value * warm access list+ target has code + positive value * warm access list+ target has no code + zero value * warm access list+ target has no code + positive value * cold access list+ target has code + zero value * cold access list+ target has code + positive value * cold access list+ target has no code + zero value * cold access list+ target has no code + positive value
Tested By hand: * CREATE * CREATE2 * CREATE sending value * CREATE2 sending value sending value does not affect gas dimensions but I tested it anyways
Tested by hand in variations: * writing to a new slot * writing to the same slot twice with the same value * writing to the same slot twice with a different value * writing to a slot that was uninitialized and setting it back to zero * writing to a slot that was cold but set to non-zero and setting it to nonzero
CALL, DELEGATECALL, EXTCODECOPY, etc. Tested by hand.
This PR exposes the GasUsed, L1GasUsed, and L2GasUsed from the transaction reciept directly in the tracer response. It also changes the tracers for CALL, CALLCODE, STATICCALL, DELEGATECALL, CREATE and CREATE2 to explicitly return the gas consumed by the child execution of the call when the call stack depth is increased by those opcodes.
36931d0
to
9be9106
Compare
We require contributors to sign our Contributor License Agreement. In order for us to review and merge your code, please sign the linked documents below to get yourself added. https://na3.docusign.net/Member/PowerFormSigning.aspx?PowerFormId=b15c81cc-b5ea-42a6-9107-3992526f2898&env=na3&acct=6e152afc-6284-44af-a4c1-d8ef291db402&v=2 |
We require contributors to sign our Contributor License Agreement. In order for us to review and merge your code, please sign the linked documents below to get yourself added. https://na3.docusign.net/Member/PowerFormSigning.aspx?PowerFormId=b15c81cc-b5ea-42a6-9107-3992526f2898&env=na3&acct=6e152afc-6284-44af-a4c1-d8ef291db402&v=2 |
Closing in favor of #459 |
This PR introduces two native and two live tracers,
txGasDimensionLogger
andtxGasDimensionByOpcode
, that on a per-opcode basis track the consumption of gas across multiple dimensions:txGasDimensionLogger
The logger is based off the default geth opcode struct logger. It will return each opcode, and its associated gas dimensional consumption, e.g.
txGasDimensionByOpcode
The transaction gas dimensions by opcode tracer returns the total sum of gas consumed by each different opcode, split out by dimension, e.g:
Tracer Invocation
The tracers need to have a parameter of a transaction hash to operate upon. If you have that and your node either is an archive node with the state or the transaction hash you're tracing is in the last 128 blocks then you can run the tracer like so:
Live Tracers
The live tracers are identical use the native tracers under the hood. The difference with the live tracers is that they dump the output of the tracer to disk in protobuf format to then in in order to save on storage space relative to json. Python or whatever can then generate serialization code from the .proto file to ingest the protobuf output.
Live Tracer Invocation
The live tracers can be run like so:
For example, this will create a directory called
gas-dimension-logs
in the root of the repo that will have each block as a subfolder, and a protobuf dumped file for the gas dimensions by transaction. The tracer expects a chain configuration because I was unable to get the chain configuration in the tracer creation context without having a bigger diff. So it expects it to be passed in by json - you can use the nitro repository's chain info as a reference for a chain configuration if you don't have one.