Commit graph

472 commits

Author SHA1 Message Date
Matthieu Vachon
3abff91f34 Merge branch 'feature/gas-full-cycle-and-reason' into feature/firehose-extended-tracer 2023-09-11 11:22:00 -04:00
Matthieu Vachon
06badab596 Inverted GasChangeCallLeftOverRefunded and GasChangeCallLeftOverReturned 2023-09-11 11:21:45 -04:00
Matthieu Vachon
31f1a01ec5 Merge branch 'feature/gas-full-cycle-and-reason' into feature/firehose-extended-tracer
# Conflicts:
#	core/blockchain.go
#	core/state_transition.go
#	core/vm/contracts.go
#	core/vm/evm.go
#	core/vm/instructions.go
#	core/vm/interpreter.go
#	core/vm/logger.go
#	core/vm/operations_acl.go
#	eth/backend.go
#	eth/tracers/logger/access_list_tracer.go
#	eth/tracers/logger/logger.go
#	eth/tracers/logger/logger_json.go
2023-09-11 10:27:01 -04:00
Matthieu Vachon
8f17c19c63 Fixed wrong split of trx and call 2023-09-06 17:05:02 -04:00
Matthieu Vachon
da14392fc6 Merge remote-tracking branch 's1na/extended-tracer' into feature/gas-full-cycle-and-reason 2023-09-06 11:40:01 -04:00
Sina Mahmoodi
651c438621 fix runtime tests 2023-09-04 17:55:01 +02:00
Matthieu Vachon
aad080db33 Normalized GasChange constats, emit Refund/BuyBack only if doing something, updated comments 2023-09-01 09:32:19 -04:00
Matthieu Vachon
d0dbbaf6a5 Change OnGasConsumed(gas, cost uint64, reason) to OnGasChange(old, new uint64, reason)
This way, we avoid having a `cost` that is negative which does not make sense for a `uint64`. Having the `old, new` also yields correct value and the delta can then be negative and be holded in a `int64`.

# Conflicts:
#	core/vm/evm.go
2023-08-28 19:20:01 -04:00
Matthieu Vachon
01ccd7126e Change OnGasConsumed(gas, cost uint64, reason) to OnGasChange(old, new uint64, reason)
This way, we avoid having a `cost` that is negative which does not make sense for a `uint64`. Having the `old, new` also yields correct value and the delta can then be negative and be holded in a `int64`.
2023-08-28 15:30:10 -04:00
Matthieu Vachon
e0af166ffa Full OnGasConsumed loop and added GasChangeReason
With this change, the full gas loop of a transaction can be tracked going from initial balance (`gasLimit`) back down to 0.

I validated on my regression test suite that those conditions applied to all transactions I have:
- First `OnGasConsumed` is always going from 0 -> `trx.gasLimit`
- Last `OnGasConsumed` "new value" is always 0
- trx.gasLimit - last balance of last `OnGasConsumed` is equal to `trx.gasUsed`

The addition of `reason` make it possible for a logger to filter out unwanted signal, for example one could want to drop all OpCode related gas change and only cares about "transaction" level. The reason is also a good thing for visibility and for creating powerful debug tools for Ethereum transaction execution.

Also, I would like that we change the `OnGasConsumed` logic from `OnGasConsumed(actual, cost uint64, reason)` to `OnGasConsumed(old, new uint64, reason)`. With the new tracing I've done, we now have negative `cost` that needs to be passed around but the `cost` is `uint64` so it creates overflow. Everything works fine if you record the new/old value `gas-cost` as the final value goes back to a valid range. But it's weird for consumer that would log `cost` that it's `18127127187219...`. An alternative would be to accept a `int64` for the cost which is also valid, not full coverage theorically but I don't see why an operation would cost more than i64 max value. Maybe it make more sense than to have signature `OnGasConsumed(gas uint64, cost int64, reason)`, I'm fine with it also, I leave the decision to you.
2023-08-28 15:30:10 -04:00
Matthieu Vachon
09df0e0c95 Merge branch 'extended-tracer' into feature/firehose-extended-tracer
# Conflicts:
#	core/vm/evm.go
2023-08-02 09:49:36 -04:00
Matthieu Vachon
32c14945da Full OnGasConsumed loop and added GasChangeReason
With this change, the full gas loop of a transaction can be tracked going from initial balance (`gasLimit`) back down to 0.

I validated on my regression test suite that those conditions applied to all transactions I have:
- First `OnGasConsumed` is always going from 0 -> `trx.gasLimit`
- Last `OnGasConsumed` "new value" is always 0
- trx.gasLimit - last balance of last `OnGasConsumed` is equal to `trx.gasUsed`

The addition of `reason` make it possible for a logger to filter out unwanted signal, for example one could want to drop all OpCode related gas change and only cares about "transaction" level. The reason is also a good thing for visibility and for creating powerful debug tools for Ethereum transaction execution.
2023-08-02 09:16:45 -04:00
Matthieu Vachon
d723124530 Added IsPrecompileAddr on EVM to let tracer easily determine if an address is a precompiled address 2023-07-28 17:03:59 -04:00
Matthieu Vachon
5952799988 Fixed wrong EVM call tracing code 2023-07-27 16:32:03 -04:00
Sina Mahmoodi
f9f377d64f capture call validation errors 2023-07-27 21:57:40 +02:00
Matthieu Vachon
9af0334dff Use leftOverGas instead of gas as it's sure to respect Go rules for defer to have latest returned value 2023-07-27 15:37:09 -04:00
Matthieu Vachon
4e834c10d0 Merge remote-tracking branch 's1na/extended-tracer' into feature/firehose-extended-tracer
# Conflicts:
#	core/state/state_object.go
#	core/state/statedb_test.go
#	core/state_transition.go
#	core/txpool/legacypool/legacypool_test.go
#	core/vm/evm.go
#	core/vm/instructions.go
#	eth/api_debug_test.go
#	eth/tracers/js/tracer_test.go
#	go.sum
2023-07-27 11:47:40 -04:00
Sina Mahmoodi
b2b32e6ff6 fix merge conflict 2023-07-27 14:41:47 +02:00
Sina Mahmoodi
2faf3dbfd6 emit err on tx validation failure 2023-07-26 20:07:13 +02:00
Matthieu Vachon
5466fa3133
Capture balance reason (#12) 2023-07-26 10:49:04 +02:00
Matthieu Vachon
dd86f19df4 Move up CaptureStart/CaptureEnd as well as CaptureEnter/CaptureExit higher directly when function starts 2023-07-25 14:35:59 -04:00
Matthieu Vachon
75e8c96f4e WIP 2023-07-25 10:40:30 -04:00
jwasinger
988d84aa7c
core/state, core/vm: implement EIP 6780 (#27189)
EIP-6780: SELFDESTRUCT only in same transaction

>     SELFDESTRUCT will recover all funds to the caller but not delete the account, except when called in the same transaction as creation

---------

Co-authored-by: Martin Holst Swende <martin@swende.se>
2023-07-17 13:02:18 -04:00
Martin Holst Swende
b058cf454b
core, tests: EIP-4844 transaction processing logic (#27721)
This updates the reference tests to the latest version and also adds logic
to process EIP-4844 blob transactions into the state transition. We are now
passing most Cancun fork tests.

Co-authored-by: Marius van der Wijden <m.vanderwijden@live.de>
Co-authored-by: Felix Lange <fjl@twurst.com>
2023-07-15 23:27:36 +02:00
ucwong
99e000cb13
core/vm: use types.EmptyCodeHash (#27729) 2023-07-15 17:45:57 +02:00
jwasinger
d233b6b23a
core: replace instances of 'suicide' with 'selfdestruct' to improve code consistency. (#27716)
---------

Co-authored-by: Martin Holst Swende <martin@swende.se>
Co-authored-by: lightclient <14004106+lightclient@users.noreply.github.com>
2023-07-15 10:35:30 -04:00
Charles Cooper
5c9cbc218a
core/vm: implement EIP-5656, mcopy instruction (#26181)
Implements [EIP 5656](https://eips.ethereum.org/EIPS/eip-5656), MCOPY instruction, and enables it for Cancun. 

---------

Co-authored-by: Martin Holst Swende <martin@swende.se>
2023-07-11 03:55:34 -04:00
Martin Holst Swende
af8b138c1a
core/vm: define cancun + enable 1153 (tstore/tload) in cancun (#27663) 2023-07-10 14:40:31 -04:00
Sina Mahmoodi
54171ee4a8 pass env in TxStart 2023-06-28 21:58:38 +02:00
Sina Mahmoodi
378781654f Upgrade TxStart and TxEnd hooks 2023-06-28 13:28:53 +02:00
Guillaume Ballet
85b8d1c06c
params, trie: add verkle fork management + upgrade go-verkle (#27464)
* params, trie: add verkle fork management + upgrade go-verkle

* remove the two verkle files

* core, eth, params: add missing function

* Gary's feedback

* remove trie/utils/verkle.go

* add verkle block override

---------

Co-authored-by: Gary Rong <garyrong0905@gmail.com>
2023-06-28 12:08:48 +03:00
Marius van der Wijden
d7ea278fe3
core/vm: move TSTORE,TLOAD to correct opcode nums (#27613)
* core/vm: move TSTORE,TLOAD to correct opcode nums

* core/vm: cleanup
2023-06-27 03:25:08 -04:00
Sina Mahmoodi
ee791b2b20 add gas consumption hook 2023-06-23 16:40:58 +02:00
Marius van der Wijden
091c25d983
go.mod: update kzg libraries to use big-endian (#27510)
* go.mod: update kzg libraries to use big-endian

* go.sum: ran go mod tidy

* core/testdata/precompiles: fix blob verification test

* core/testdata/precompiles: fix blob verification test
2023-06-19 15:08:13 +03:00
Sina Mahmoodi
e25065bfc3 capture keccak preimage 2023-06-15 18:42:57 +02:00
Marius van der Wijden
c537ace249
core: 4844 opcode and precompile (#27356)
* core: crypto: implement BLOBHASH and pointEval precompile

* core: crypto: fixed nitpicks, moved precompile return value

* core/vm: fix review comments
2023-06-05 16:43:25 +03:00
rjl493456442
a14301823e
all: new empty trie with types.EmptyRootHash instead of null (#27230) 2023-05-11 10:19:42 +03:00
Alex Beregszaszi
3f7afc3f57
core/vm: order opcodes properly (#27113) 2023-04-20 02:52:00 -04:00
Delweng
5e4d726e2a
params: remove EIP150Hash from chainconfig (#27087)
The EIP150Hash was an idea where, after the fork, we hardcoded the forked hash as an extra defensive mechanism. It wasn't really used, since forks weren't contentious and for all the various testnets and private networks it's been a hassle to have around. 

This change removes that config field. 

---------

Signed-off-by: jsvisa <delweng@gmail.com>
2023-04-18 03:49:09 -04:00
Martin Holst Swende
ab1a404b01
all: remove debug-field from vm config (#27048)
This PR removes the Debug field from vmconfig, making it so that if a tracer is set, debug=true is implied.

---------

Co-authored-by: 0xTylerHolmes <tyler@ethereum.org>
Co-authored-by: Sina Mahmoodi <1591639+s1na@users.noreply.github.com>
2023-04-04 09:50:13 -04:00
joohhnnn
9b1a82c600
core/vm: clarify comment (#27045) 2023-04-04 02:59:40 -04:00
s7v7nislands
881fed032c
core/vm: use atomic.Bool (#26951)
Make use of new atomic types
---------

Co-authored-by: Felix Lange <fjl@twurst.com>
Co-authored-by: Martin Holst Swende <martin@swende.se>
2023-03-27 09:40:20 -04:00
Martin Holst Swende
b3f43c89b3
core/vm: expose jumptable constructors (#26880)
When interacting with geth as a library to e.g. produce state tests, it is desirable to obtain the consensus-correct jumptable definition for a given fork. This changes adds accessors so the instructionset can be obtained and characteristics about opcodes can be inspected.
2023-03-21 07:14:47 -04:00
rjl493456442
bba2a1bac5
core: show db error-info in case of mismatched hash root (#26870)
When a database failure occurs, bubble it up a into statedb, and report it in suitable places, such as during a 'bad block' report.
2023-03-16 03:12:34 -04:00
xiyang
ca61048178
code/vm: fix comment typo (#26865)
it should be constantinople rather than contantinople
2023-03-13 09:30:32 +02:00
xiyang
1bf1168432
core/vm: fix typo in comment (#26838)
fixes eip 220 ->  2200
2023-03-09 04:39:17 -05:00
Martin Holst Swende
b80f05bde2
core/vm: use golang native big.Int (#26834)
reverts #26021, to use the upstream bigint instead.
2023-03-08 13:12:53 -05:00
Chris Ziogas
b0cd8c4a5c
core/vm: set tracer-observable value of a delegatecall to match parent value (#26632)
This is a breaking change in the tracing hooks API as well as semantics of the callTracer:

- CaptureEnter hook provided a nil value argument in case of DELEGATECALL. However to stay consistent with how delegate calls behave in EVM this hook is changed to pass in the value of the parent call.
- callTracer will return parent call's value for DELEGATECALL frames.

---------

Co-authored-by: Sina Mahmoodi <itz.s1na@gmail.com>
2023-02-10 10:26:43 +01:00
raulk
918aed4e31
core/vm: add bn256ScalarMul testcase for zero scalar value (#26607)
EIP-196 allows a zero value in the scalar argument to precompile `0x07`. This change adds a test for that case.
2023-02-06 07:41:29 -05:00
lmittmann
877d2174fb
core/vm: improve EVM instance reusability (#26341)
This change improves reusability of the EVM struct. Two methods are added:

- SetBlockContext(...)
- SetTracer(...)

Other attributes like the TransactionContext and the StateDB can already be updated.
BlockContext and Tracer are partially not updateable right now. This change fixes it and
opens the potential to reuse an EVM struct in more ways.

Co-authored-by: Felix Lange <fjl@twurst.com>
2023-02-05 15:11:25 +01:00