## Why this should be merged
Required for
[ACP-194](https://github.com/avalanche-foundation/ACPs/tree/main/ACPs/194-streaming-asynchronous-execution#gas-charged)
$\lambda$ bound on gas consumption.
## How this works
Hook into `core.StateTransition.TransitionDb()` as this is the bottom of
all execution paths (e.g. `core.ApplyTransaction()` as used in SAE,
`core.StateProcessor.Process(*Block,...)`, etc.). Once consumed gas is
no longer changing (i.e. after all spends and refunds), the transaction
limit is passed to the hook to determine the minimum consumption, which
is applied.
## How this was tested
Unit test via `core.ApplyTransaction()` as this is our entry point in
SAE.
---------
Signed-off-by: Arran Schlosberg <519948+ARR4N@users.noreply.github.com>
Co-authored-by: Stephen Buttolph <stephen@avalabs.org>
> [!NOTE]
> This will be merged into `main` once the current target branch has
been merged.
## Why this should be merged
My original implementation was back to front and it's been bugging me.
## How this works
Originally `params.LibEVMVersion` was a `var` (because it needed to be
computed) and the test used a `const`. This change simply inverts the
two and moves some code around without any change in logic.
I bumped the minor version to 2 (a no-op when not on a release branch)
to bring it in line with the latest release candidate and to avoid
forgetting to do so when performing an actual release.
## How this was tested
Unit test of version-string constant.
## Why this should be merged
Safer release process by enforcing invariants of `release/*` branches as
automated in #137 to fulfil #25.
## How this works
New test for `go_tooling` CI job.
If the PR target branch is `main` then only the `params.ReleaseType` is
checked. If the target is neither `main` nor a release branch then the
test is skipped. The checks performed on `release/*` branches are
described in the test.
## How this was tested
Locally against a dummy release branch with deliberate problems created
by (a) including this PR's changes in the final commit and (b) not
updating the libevm version.
```
$ go test -v ./... --target_branch="release/v1.13.14-0.1.0.rc.3"
=== RUN TestCherryPicksFormat
--- PASS: TestCherryPicksFormat (0.39s)
=== RUN TestBranchProperties
=== RUN TestBranchProperties/branch_name
release_test.go:172:
Error Trace: .../ava-labs/libevm/libevm/tooling/release/release_test.go:172
Error: Not equal:
expected: "release/v1.13.14-0.1.0.beta"
actual : "release/v1.13.14-0.1.0.rc.3"
Diff:
--- Expected
+++ Actual
@@ -1 +1 @@
-release/v1.13.14-0.1.0.beta
+release/v1.13.14-0.1.0.rc.3
Test: TestBranchProperties/branch_name
release_test.go:175: On release branch; params.LibEVMReleaseType = "beta", which is unsuitable for release branches
=== RUN TestBranchProperties/commit_history
release_test.go:192: Forked from "main" at commit 4c6e50e7d1 (chore: module-renaming workflow inverts between `libevm` and `geth` (#152))
release_test.go:314: ### History since fork from default branch (8 commits):
release_test.go:316: internal/build, rpc: add missing HTTP response body Close() calls (#29223) by Shiming Zhang <wzshiming@hotmail.com>
release_test.go:316: core/state: fix bug in statedb.Copy and remove unnecessary preallocation (#29563) by Aaron Chen <aaronchen.lisp@gmail.com>
release_test.go:316: params: print time value instead of pointer in ConfigCompatError (#29514) by Nathan <Nathan.l@nodereal.io>
release_test.go:316: eth/gasprice: add query limit for FeeHistory to defend DDOS attack (#29644) by Nathan <Nathan.l@nodereal.io>
release_test.go:316: core/state/snapshot: add a missing lock (#30001) by maskpp <maskpp266@gmail.com>
release_test.go:316: crypto: add IsOnCurve check (#31100) by Felix Lange <fjl@twurst.com>
release_test.go:316: internal/ethapi: fix panic in debug methods (#31157) by Sina M <1591639+s1na@users.noreply.github.com>
release_test.go:316: x by Arran Schlosberg <me@arranschlosberg.com>
=== RUN TestBranchProperties/commit_history/cherry_picked_commits
release_test.go:314: ### Expected cherry-picks (7 commits):
release_test.go:316: internal/build, rpc: add missing HTTP response body Close() calls (#29223) by Shiming Zhang <wzshiming@hotmail.com>
release_test.go:316: core/state: fix bug in statedb.Copy and remove unnecessary preallocation (#29563) by Aaron Chen <aaronchen.lisp@gmail.com>
release_test.go:316: params: print time value instead of pointer in ConfigCompatError (#29514) by Nathan <Nathan.l@nodereal.io>
release_test.go:316: eth/gasprice: add query limit for FeeHistory to defend DDOS attack (#29644) by Nathan <Nathan.l@nodereal.io>
release_test.go:316: core/state/snapshot: add a missing lock (#30001) by maskpp <maskpp266@gmail.com>
release_test.go:316: crypto: add IsOnCurve check (#31100) by Felix Lange <fjl@twurst.com>
release_test.go:316: internal/ethapi: fix panic in debug methods (#31157) by Sina M <1591639+s1na@users.noreply.github.com>
=== RUN TestBranchProperties/commit_history/final_commit
release_test.go:365: Modified disallowed file "go.yml"
release_test.go:365: Modified disallowed file "go.mod"
release_test.go:365: Modified disallowed file "go.sum"
release_test.go:365: Modified disallowed file "release_test.go"
--- FAIL: TestBranchProperties (2.07s)
--- FAIL: TestBranchProperties/branch_name (0.00s)
--- FAIL: TestBranchProperties/commit_history (2.07s)
--- PASS: TestBranchProperties/commit_history/cherry_picked_commits (1.81s)
--- FAIL: TestBranchProperties/commit_history/final_commit (0.01s)
FAIL
FAIL github.com/ava-labs/libevm/libevm/tooling/release 2.712s
FAIL
```
## Why this should be merged
Adds logging of `libevm` modification of default behaviour.
## How this works
1. Introduces `log.Lazy` functions to allow expensive logging operations
to be computed i.f.f. required by the logging level.
2. Adds `Info` logging for registration of types and `Debug` logging for
all else.
3. Only paths that change behaviour in a potentially unpredictable
manner are logged; of note, RLP / JSON encoding is _not_ considered
unpredictable given that registered extras are logged.
4. The minimal viable package, `set`, was necessary because we don't
want to depend on `avalanchego` and the `hashicorp/go-set` latest
version requires a later version of Go. #153 tracks a swap to the latter
when possible.
The `eth/tracers/internal/tracetest` test flaked at least twice
(unrelated to these changes) so I've marked it as such since it's not
worth a separate PR.
## How this was tested
New unit test on `log.Lazy` + `set` methods. Existing CI for the rest as
it's a refactor.
- Allow wallets and other clients to parse blocks from both coreth and subnet-evm without registering extra types
- Allow wallets and other clients to make their genesis/chain configurations without registering extra types
## Why this should be merged
The `types.Header` fields of both
[`coreth`](https://pkg.go.dev/github.com/ava-labs/coreth/core/types#Header)
and
[`subnet-evm`](https://pkg.go.dev/github.com/ava-labs/subnet-evm/core/types#Header)
have been modified such that their RLP encodings (i.e. block hashes)
aren't compatible with vanilla `geth` nor each other. This PR adds
support for arbitrary RLP encoding coupled with type-safe extra
payloads.
## How this works
Equivalent to #1 (`params`) and #44 (`types.StateAccount`) registration
of pseudo-generic payloads. The only major difference is the guarantee
of a non-nil payload pointer, which means that the payload hooks are
never called on nil pointers as this would make it difficult to decode
RLP into them.
## How this was tested
Round-trip RLP {en,de}coding via a registered stub hook.
---------
Signed-off-by: Arran Schlosberg <519948+ARR4N@users.noreply.github.com>
Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>
## Why this should be merged
There are 3 places at which we perform the same, sensitive logic to
access registered payloads and as we modify more types this is likely to
expand. (e.g. `types.Header`).
## How this works
Introduces `pseudo.Accessor` to abstract the reusable code.
## How this was tested
Existing unit tests. Note that the `types.StateAccount` tests needed a
minor refactor to provide the assertions with access to the
`ExtraPayloads[T]` without introducing generic types anywhere.
## Why this should be merged
Consolidates duplicated logic. Similar rationale to #84.
## How this works
New `register.AtMostOnce[T]` type is responsible for limiting calls to
`Register()`.
## How this was tested
Existing unit tests of `params`. Note that the equivalent functionality
in `types` wasn't tested but now is.
## Why this should be merged
I messed up the format of `rc` version tags, resulting in `rc.1` being
considered a later version that `rc.2`.
## How this works
The [release tagging](https://github.com/ava-labs/libevm/discussions/37)
pattern that includes a combination of `geth` and `libevm` semver
triplets (e.g. `1.13.14-0.1.0`) doesn't work well with extra identifiers
like `rc` because more pre-release identifiers (those after `-`) take
higher precedence if all those before them match. We therefore have to
use a `release` suffix (`"release" > "rc"` in ASCII).
This all became too much to expect to be done manually so I chucked it
in code instead.
## How this was tested
Unit test demonstrates expectation of version ordering.
## Why this should be merged
Cleans up loose ends after renaming the Go module. Also adds an
introduction to the README to explain the purpose of libevm.
## How this works
The changed hash in the workflow is just a fix (although a no-op). The
spaces after the copyright headers are to stop them from [showing up in
documentation](https://pkg.go.dev/github.com/ava-labs/libevm@v1.13.14-0.1.0-rc.1/params).
## How this was tested
n/a
* refactor: abstract `testonly` package
* test: `StateAccount.Extra` via `trie.StateTrie.{Update,Get}Account()`
* chore: `types.TestOnlyClearRegisteredExtras()` at beginning of tests
This is a purely defensive approach in case future tests forget to clean up.
* chore: placate the linter
* refactor!: `RulesHooks.CanCreateContract()` via `defer`
`TestCanCreateContract` is unchanged and merely moved to the appropriate file.
* feat!: `RulesHooks.CanCreateContract()` accepts and returns gas
* chore: move `TestCanCreateContract` to original file
Simplifies code review
* chore: pacify linter
* refactor!: revert to non-deferred call (not at start)
* chore: `golangci-lint` CI workflow
* fix: make `golangci-lint` happy
* chore: bump `actions/{checkout,setup-go}` versions
* chore: overhaul `.golanci.yml` config
* fix: all linter issues
* chore: exclude non-libevm linters + change deprecated option
* fix: add overflow check in example
* fix: try again; different local version?
* chore: this is trying my patience
* chore: enable `gci` and fix ordering
* chore: mark `ethclient/gethclient` test as flaky
* chore: mark `eth/catalyst` test as flaky
* refactor: extra types `C` + `R` are never plumbed as `*C` / `*R`
* refactor: force use of `pseudo.Constructor.Zero()` instead of `NilPointer()`
* feat: `pseudo.PointerTo()`
* feat: `params.ExtraPayloadGetter[C,R].PointerFromChainConfig(...) *C` and `Rules => *R` equiv
* test: shallow copy of `ChainConfig`/`Rules` includes extras
* feat: `params.ChainConfig` extra payload can use root JSON
* refactor: simplify `ChainConfig.UnmarshalJSON()` branches
* fix: change redundant `assert` to `require` for simplicity
* feat: pseudo-generic extra payloads in `params.ChainConfig` and `params.Rules`
* feat: `params.ExtraPayloadGetter` for end-user type safety
* refactor: payloads only available through `params.ExtraPayloadGetter`
* chore: make `libevm/examples/extraparams` a `params` testable example
* doc: `libevm/pseudo` package comments and improved readability
* doc: `params.*Extra*` comments and improved readability
* doc: `params.ExtraPayloadGetter` comments and improved readability
* doc: `params/config.libevm_test.go` comments and improved readability
* refactor: simplify `params.ChainConfig.UnmarshalJSON()`
* refactor: abstract new/nil-pointer creation into `pseudo.Constructor`s
* feat: precompile override via `params.Extras` hooks
* doc: flesh out `PrecompileOverride()` in example
* doc: complete commentary and improve readability
* refactor: `ChainConfig.Hooks()` + `Rules` equivalent
* chore: rename precompiles test file in keeping with geth equivalent
* feat: stateful precompiles + allowlist hooks
The allowlist hooks are included in this commit because they allow for the same functionality as stateful precompiles in `ava-labs/coreth` and `ava-labs/subnet-evm`.
* fix: `StateTransition.canExecuteTransaction()` used `msg.From` instead of `To`
* test: `params.RulesHooks.CanCreateContract` integration
* test: `params.RulesHooks.CanExecuteTransaction` integration
* test: `vm.NewStatefulPrecompile()` integration
* refactor: simplify test of `CanCreateContract`
* refactor: abstract generation of random `Address`/`Hash` values
* doc: full documentation + readability refactoring/renaming
* fix: remove circular dependency in tests
This PR fixes an overflow which can could happen if inconsistent blockchain rules were configured. Additionally, it tries to prevent such inconsistencies from occurring by making sure that merge cannot be enabled unless previous fork(s) are also enabled.
This PR introduces a few changes with respect to payload verification in fcu and new payload requests:
* First of all, it undoes the `verifyPayloadAttributes(..)` simplification I attempted in #27872.
* Adds timestamp validation to fcu payload attributes [as required](https://github.com/ethereum/execution-apis/blob/main/src/engine/cancun.md#specification-1) (section 2) by the Engine API spec.
* For the new payload methods, I also update the verification of the executable data. For `newPayloadV2`, it does not currently ensure that cancun values are `nil`. Which could make it possible to submit cancun payloads through it.
* On `newPayloadV3` the same types of checks are added. All shanghai and cancun related fields in the executable data must be non-nil, with the addition that the timestamp is _only_ with cancun.
* Finally it updates a newly failing catalyst test to call the correct fcu and new payload methods depending on the fork.
The code to compute a versioned hash was duplicated a couple times, and also had a small
issue: if we ever change params.BlobTxHashVersion, it will most likely also cause changes
to the actual hash computation. So it's a bit useless to have this constant in params.
EIP-4844 adds a new transaction type for blobs. Users can submit such transactions via `eth_sendRawTransaction`. In this PR we refrain from adding support to `eth_sendTransaction` and in fact it will fail if the user passes in a blob hash.
However since the chain can handle such transactions it makes sense to allow simulating them. E.g. an L2 operator should be able to simulate submitting a rollup blob and updating the L2 state. Most methods that take in a transaction object should recognize blobs. The change boils down to adding `blobVersionedHashes` and `maxFeePerBlobGas` to `TransactionArgs`. In summary:
- `eth_sendTransaction`: will fail for blob txes
- `eth_signTransaction`: will fail for blob txes
The methods that sign txes does not, as of this PR, add support the for new EIP-4844 transaction types. Resuming the summary:
- `eth_sendRawTransaction`: can send blob txes
- `eth_fillTransaction`: will fill in a blob tx. Note: here we simply fill in normal transaction fields + possibly `maxFeePerBlobGas` when blobs are present. One can imagine a more elaborate set-up where users can submit blobs themselves and we fill in proofs and commitments and such. Left for future PRs if desired.
- `eth_call`: can simulate blob messages
- `eth_estimateGas`: blobs have no effect here. They have a separate unit of gas which is not tunable in the transaction.