Commit graph

14993 commits

Author SHA1 Message Date
Arran Schlosberg
0ed61356ed
refactor(params): make LibEVMVersion a constant (#162)
> [!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.
2025-03-17 19:29:16 +00:00
Arran Schlosberg
08490a9b76
test: branch properties of main and release/* (#145)
## 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
```
2025-03-17 16:55:39 +00:00
Arran Schlosberg
433c6069e2
feat(core/types): export rlpHash() (#163)
## Why this should be merged

Allows `core/types/hashing.go` to be deleted from `coreth`.

## How this works

Exported function acts as a proxy for unexported upstream function.

## How this was tested

NA
2025-03-13 18:44:20 +00:00
Arran Schlosberg
b0332b5168
chore(ci): add merge_group trigger to required workflows (#160)
## Why this should be merged

Allows ruleset-required workflows to be triggered by a merge queue, not
just the PR for the merge. Although `main` isn't a particularly "busy"
branch, a merge queue will ensure that CI passes on the exact version of
code that is about to be merged; i.e. (from the [docs]):

> The merge queue provides the same benefits as the **Require branches
to be up to date before merging** branch protection, but does not
require a pull request author to update their pull request branch and
wait for status checks to finish before trying to merge.

[docs]:
https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/managing-a-merge-queue#about-merge-queues

## How this works

Adds `merge_group` workflow trigger with [recommended
type](https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#merge_group).

## How this was tested

N/A (worst-case it has to be reverted and another PR is temporarily
blocked).
2025-03-11 13:57:57 +00:00
Arran Schlosberg
4c6e50e7d1
chore: module-renaming workflow inverts between libevm and geth (#152)
## Why this should be merged

Originally I'd planned on doing an upstream sync by running the rename
workflow on the incoming commit and then merging it to `main` however
this resulted in hundreds of merge commits that were solely due to Go
imports. Renaming the module from `ava-labs/libevm` to
`ethereum/go-ethereum` removed 90% of conflicts (H/T @darioush). The
module will then need to be named `ava-labs/libevm` again, so the commit
history will probably[^1] look like this after an update:

```mermaid
---
config:
  gitGraph:
    mainBranchName: main
    parallelCommits: true
---
gitGraph TB:
    branch geth order:2
    commit id:"geth@v1.15.2"
    checkout main
    commit id:"libevm@v1.13.14"
    branch sync/v1.15.2
    commit id:"[AUTO] rename to ethereum/go-ethereum"
    merge geth
    commit id:"[AUTO] rename to ava-labs/libevm"
    checkout main
    merge sync/v1.15.2 id:"libevm@v1.15.2"
```

[^1]: Specifics of and rationale behind the merge strategy are beyond
the scope of this PR.

## How this works

The current module name is determined with `go list -m` and the rename
from/to patterns are no longer hard-coded.

## How this was tested

Inspection of runs and resulting branch. Although these were the
bc8e5015694707ff682c444afff52a3801b35a53 workflow, the only other commit
in this PR is cosmetic (as seen in [this
run](https://github.com/ava-labs/libevm/actions/runs/13433886428) to
create f2cecaff9c01c86053644aafc9b7196229a84cbc).

1. Run on `main` @ d32c7e0090 changes from
`libevm` to `go-ethereum`:
a.
[Run](https://github.com/ava-labs/libevm/actions/runs/13432588947/job/37527588744)
b.
[Commit](6288df93f7)
  c. Created branch `arr4n/auto/test-invertible-rename`
2. Re-run on `arr4n/auto/test-invertible-rename` changes back to
`libevm`:
  a. [Run](https://github.com/ava-labs/libevm/actions/runs/13432810657)
b.
[Commit](6f4f94edd9)
c. [Auto-generated branch is identical to `main` at the time of
running](d32c7e0090...6f4f94edd9)
2025-03-07 13:23:11 +00:00
Quentin McGaw
739ba847f6
feat(rlp/rlpgen): support alias types (#154)
## Why this should be merged

To be able to generate RLP code using type aliases (defined e.g. in
`coreth`).
This can and should be PR-ed upstream as well I think.

## How this works

Call `types.Unalias()` at the start of `buildContext.makeOp()`. The
alternative of adding a `case` to the switch statement adds unnecessary
recursive calls while `types.Unalias()` is a no-op if not an alias.

## How this was tested

New `rlpgen` unit test with aliases of well-known types that have
special handling—these make their proper handling easy to spot when
inspecting generated code. A recursive alias in the same test also
demonstrates full alias resolution.

---------

Co-authored-by: Arran Schlosberg <me@arranschlosberg.com>
2025-02-27 11:13:11 +00:00
Arran Schlosberg
9f410ecc7e
chore: go@1.23 (#156)
## Why this should be merged

We'll be building with Go 1.23 via `avalanchego` so should align
versions. Also unblocks #154.

## How this works

Bump `go.mod` version and run `go mod tidy`.

## How this was tested

CI on existing tests.
2025-02-25 16:46:04 +00:00
Arran Schlosberg
24d7bdeae6
chore!: remove memsize (#155)
## Why this should be merged

`memsize` blocks usage of Go 1.23. We'll be building with 1.23 via
`avalanchego` anyway (which doesn't transitively import `memsize`) so we
want to run tests with the correct version. It will also unblock #154.

## How this works

✂️ 

We already cherry-pick the upstream commit
(e4675771ed) that removes `memsize` when
on release branches so we instead do it ourselves and no longer
cherry-pick. To avoid conflicts at the next `geth` sync, this PR should
be reverted before performing the merge. See #128.

## How this was tested

Existing tests.
2025-02-25 16:12:58 +00:00
Arran Schlosberg
02110d3f34
chore: logging (#151)
## 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.
2025-02-24 16:53:21 +00:00
Arran Schlosberg
d32c7e0090
chore: remove module retractions in lieu of bumping minor (#147)
## Why this should be merged

Both #141 and #81 attempted to fix my lack of planning with release
versioning however Go modules [require a higher-precedence version for
retract statements to be
honoured](https://go.dev/ref/mod#go-mod-file-retract:~:text=The%20new%20version%20must%20be%20higher%20than%20other%20release%20or%20pre%2Drelease%20versions%3B%20that%20is%2C%20the%20%40latest%20version%20query%20should%20resolve%20to%20the%20new%20version%20before%20retractions%20are%20considered.).
The only way we can get that with our [versioning
rules](32e7dafe1c/params/version.libevm.go (L30))
is to bump the minor version. This will negate the need for explicit
retraction so I'm removing it as a cleanup.

## How this works

n/a

## How this was tested

[Effect of bumping
minor](https://semvercompare.azurewebsites.net/?version=1.13.14-0.1.0.rc.3&version=1.13.14-0.1.0.rc-2&version=1.13.14-0.1.0-rc.1&version=1.13.14-0.2.0.rc.1):


![image](https://github.com/user-attachments/assets/d8eb3508-9c62-4864-b0ba-19b8f5f218f1)
2025-02-17 17:49:44 +00:00
Arran Schlosberg
32e7dafe1c
chore: release branches remove memsize (#146)
## Why this should be merged

A separately cherry-picked commit, the fix for `StateDB.Copy()`,
requires Go 1.23 for use of the `maps` package. This, however, breaks
`memsize`, which was later removed later from `geth` for the same
reason.

## How this works

All release branches will now cherry-pick ethereum/go-ethereum#30253.

## How this was tested

Updated list of cherry-picks applied to #142, which [passed
tests](https://github.com/ava-labs/libevm/actions/runs/13371460014/job/37340683594).
2025-02-17 14:02:02 +00:00
Quentin McGaw
1344d20908
chore(ci): disable lint goheader step on non-pull-request events (#143)
- Pin golangci-lint action to v6 now that goheader doesn't run on the default branch pushes
- This addresses the goheader step misbehaving and linting all files on pushes
2025-02-17 11:34:52 +00:00
Arran Schlosberg
53867ac3f1
chore: retract v1.13.14-0.1.0.rc-2 (#141)
## Why this should be merged

Our initial release tags weren't well-formed for our needs. Although the
format was locked in in #81, I still stuffed up rc2. With the upcoming
rc3 release, we want to ensure that Go tooling picks it up as the
latest, which requires retracting rc2 as its format means it will take
higher precedence.

## How this works

`go.mod` `retract`

## How this was tested

n/a
2025-02-14 18:09:50 +00:00
Arran Schlosberg
f7a3a4f548
chore(ci): add go catch-all job (#140)
## Why this should be merged

New jobs are easily forgotten in the GitHub rules so we will only gate
on `go` and have all others added as dependencies.

## How this works

Same as #139 

## How this was tested

Inspection of CI run:

![image](https://github.com/user-attachments/assets/f76ce720-a5ed-49e6-b000-265f3660ce8f)
2025-02-14 12:56:51 -05:00
Arran Schlosberg
bc42e5f29c
chore(ci): consolidate linters (#139)
## Why this should be merged

Branch-protection rules only require the Go linter (erroneously called
`lint`) by mistake. All linters are now dependencies of a single `lint`
job that remains as a PR gate. New linters will now be enforced by
default.

Closes #138 

## How this works

GitHub Actions `need` configuration. The path limitation of running
`yamllint` is removed because it's such a cheap job so is ok to always
run.

## How this was tested

Inspection of CI run and PR's required jobs:


![image](https://github.com/user-attachments/assets/9454ca35-8a7f-4393-bdd8-5029cfaaf7e6)


![image](https://github.com/user-attachments/assets/e92b964d-5a64-415d-b8a3-1e9c84af3060)
2025-02-14 11:48:55 -05:00
Arran Schlosberg
00c10cf539
feat: release-branch automation (#137)
## Why this should be merged

Closes #25 

## How this works

See https://github.com/ava-labs/libevm/discussions/126.

The code is in a new module to (a) avoid polluting the root `go.mod`
file and (b) because `go-git` requires a newer version of Go.
Unfortunately `go-git` doesn't support cherry-picking yet so a Bash
script had to be used for that bit `#!/sad`.

## How this was tested

Inspection of output when running `cherrypick.sh` (with `set -x` added)
from the current branch.

```
...
...
+ CHERRY_PICKS='2bd6bd01d2e8561dd7fc21b631f4a34ac16627a1
99bbbc0277
1e9bf2a09e
69f815f6f5
e4b8058d5a
34b46a2f75
159fb1a1db
da71839a270a353bac92e3108e4b74fb0eefec29'
...
Skipping 2bd6bd01d2 already in history
...
Cherry-picking 99bbbc0277
...
Cherry-picking 1e9bf2a09e
...
Cherry-picking 69f815f6f5
...
Cherry-picking e4b8058d5a
...
Cherry-picking 34b46a2f75
...
Cherry-picking 159fb1a1db
...
Cherry-picking da71839a27
...
+ git cherry-pick 99bbbc0277 1e9bf2a09e 69f815f6f5 e4b8058d5a 34b46a2f75 159fb1a1db da71839a27
```
2025-02-14 16:09:41 +00:00
Arran Schlosberg
3ab3cd2c2b
feat(core/types): Block RLP overriding (#133)
## Why this should be merged

Support for configurable `core/types.Block` with RLP encoding, including
interplay with `Body`.

## How this works

`Block` doesn't export most of its fields so relies on an internal type,
`extblock`, for RLP encoding. This type is modified to implement the
`rlp.Encoder` and `Decoder` methods as a point to inject hooks using
`rlp.Fields` (as in #120 for `Body`).

`Block` shares the same registered extra type as `Body`. Unlike
`Header`, which has its own field in a `Block`, the fields in `Body` are
promoted to be carried directly. This suggests that (at least for pure
data payloads) the modifications might be equivalent (and
`ava-labs/coreth` evidences this). Should different payloads be
absolutely required in the future, we can split the types—the
`RegisterExtras` signature is already too verbose though 😢.

## How this was tested

Explicit inclusion of a backwards-compatibility test for
`NOOPBlockBodyHooks` + implicit testing via the multiple upstream tests
in `block_test.go`. Re implicit testing: default behaviour is now to use
the noop hooks even when no registration is performed, but if we change
this then the tests in `block_test.go` can still be called as subtests
from a test that explicitly registers noops.

---------

Signed-off-by: Arran Schlosberg <519948+ARR4N@users.noreply.github.com>
Co-authored-by: Quentin McGaw <quentin.mcgaw@avalabs.org>
2025-02-13 16:20:17 +00:00
Quentin McGaw
0eb029ad49
chore(core/types): restructure libevm hooks code (#135)
Co-authored-by: Arran Schlosberg <519948+ARR4N@users.noreply.github.com>
2025-02-13 11:32:50 +00:00
Arran Schlosberg
c78db425b8
doc(core/rawdb): fix outdated comment (#134)
Missed in earlier PR:
https://github.com/ava-labs/libevm/pull/132#discussion_r1952593121

Signed-off-by: Arran Schlosberg <519948+ARR4N@users.noreply.github.com>
2025-02-12 17:41:41 +00:00
Quentin McGaw
0c905680f3
chore(core/rawdb): InspectDatabase can receive multiple times the same option (#132) 2025-02-12 12:55:40 +00:00
Quentin McGaw
b2c38ce397
feat(core/types): body RLP hooks registration (#130)
Allow to register body extras in consumers of libevm.

Co-authored-by: Arran Schlosberg <519948+ARR4N@users.noreply.github.com>
2025-02-12 11:38:28 +00:00
Arran Schlosberg
80fbed641e
refactor(core/types): Body backwards-compatibility out of package types_test (#131)
## Why this should be merged

Simplify testing in #130.

## How this works

Backwards-compatibility tests were originally created in `package
types_test` because the first one uses `ethtest` and would have caused a
circular dependency. None of the later tests have this issue so they
were moved into `package types`. The `cmpeth` test utility isn't
currently needed anywhere else so its functionality is collapsed inside
this new file.

## How this was tested

N/A as simply moving existing tests to different files.
2025-02-12 11:04:22 +00:00
Quentin McGaw
67f879ac18
refactor!(core/types): Block method WithBody(Body) signature (#110)
Breaking change refactoring `core/types.Block.WithBody()` method from signature
WithBody(transactions []*Transaction, uncles []*Header) *Block
to signature
WithBody(body Body) *Block
such that block and body extras can be used within `WithBody`.
Note `geth` made the same change in method signature so the deltas introduced in this PR will disappear once we sync.
2025-02-11 14:29:34 +00:00
Quentin McGaw
2580bd1d05
chore(ci): add go_tidy job to go workflow (#127) 2025-02-11 15:28:33 +01:00
Arran Schlosberg
94383c77ad
chore: add label "Priority: With next Geth sync" (#129)
## Why this should be merged

#110 introduces changes that we want to revert as part of the next Geth
sync. This label will be applied to issues that track similar tasks.

## How this works

Magic 🧙 

## How this was tested

Inspecting [CI dry run, which creates the new
label](https://github.com/ava-labs/libevm/actions/runs/13261362433/job/37018526246?pr=129#step:3:99).

Signed-off-by: Arran Schlosberg <519948+ARR4N@users.noreply.github.com>
2025-02-11 12:41:12 +01:00
Quentin McGaw
f6832f23bc
chore!(core/types): change method names of JSON header hooks (#125)
- MarshalJSON -> EncodeJSON
- UnmarshalJSON -> DecodeJSON
- Placates the gopls forced linter
- Aligns with EncodeRLP and DecodeRLP hook functions
2025-02-10 16:48:50 +00:00
Quentin McGaw
9125583d8e
chore(ci): pin goheader golangci-lint action to v6.2.0 (#124)
The action pinned as v6 uses v6.3.1 which is currently misbehaving on the main branch linting all files instead of just the files from the current commit.
2025-02-10 14:05:16 +00:00
Arran Schlosberg
c74b645360
feat: rawdb.InspectDatabaseOption (#111)
## Why this should be merged

Allows for `ava-labs/coreth` equivalent modifications of
`rawdb.InspectDatabase()` through external logic injection.

## How this works

Variadic options to:

1. Record a database statistic;
2. Mark a database statistic as metadata;
3. Filter statistics for printing.

## How this was tested

Testable example acting as a unit test.

---------

Signed-off-by: Arran Schlosberg <519948+ARR4N@users.noreply.github.com>
Co-authored-by: Quentin McGaw <quentin.mcgaw@avalabs.org>
2025-02-07 17:32:51 +00:00
Arran Schlosberg
d210cc4fce
refactor(core/types): simplify Body RLP override (#120)
## Why this should be merged

Simplification of `types.Body` RLP overriding, resulting in reduced code
at both the implementation and consumer ends.

## How this works

Introduction of `rlp.Fields` type, to mirror regular RLP encoding of a
struct. The RLP override hook now only needs to return the fields of
interest, which MAY come from either the `Body` or the registered extra.

This pattern allows for arbitrary modification of upstream fields via
(1) reordering; (2) addition; (3) deletion; and (4) inverting required
vs optional status. While less important for `Body`, this allows for
complete support of `ava-labs/coreth` `Header` modifications, which make
use of 1-3.

## How this was tested

Existing backwards-compatibility tests + new unit tests for introduced
functionality.

---------

Signed-off-by: Arran Schlosberg <519948+ARR4N@users.noreply.github.com>
Co-authored-by: Quentin McGaw <quentin.mcgaw@avalabs.org>
2025-02-07 15:42:25 +00:00
Arran Schlosberg
761c4b40de
fix(ci): module-renaming workflow includes .go.tpl and .proto (#122)
## Why this should be merged

Introduction of breaking upstream changes (inclusion of `.go.tpl` files)
since the workflow was written. Resulted in [failed smoke
tests](https://github.com/ava-labs/libevm/actions/runs/13198798601) due
to ABI-binding templates not being updated.

## How this works

Only (1) is necessary for the fix but the others were added for
convenience as relevant to this PR:

1. Replace module name in `*.go.tpl` files;
2. As above for `*.proto` files (`go_package` option);
3. Remove concurrency limitations as they're unnecessary with a manually
triggered workflow; and
4. Display all tags that point to the source commit as they're useful
for inspection of version.

## How this was tested

[Successful workflow
run](https://github.com/ava-labs/libevm/actions/runs/13199663099/job/36848609786)
at upstream v1.15.0.

For the modifications, respectively:

1. Smoke tests pass and no `.go.tpl` files in [Remnant
references](https://github.com/ava-labs/libevm/actions/runs/13199663099/job/36848609786#step:9:1);
2. As above re remnant references;
3. N/A; and
4. Inspection of [step
output](https://github.com/ava-labs/libevm/actions/runs/13199663099/job/36848609786#step:6:5).
2025-02-07 15:28:53 +00:00
Quentin McGaw
f906679f6f
fix(libevm/legacy): PrecompiledStatefulContract gas and remaining gas handling (#114)
- remaining gas higher than the input gas is not allowed (otherwise it would overflow as well)
- remaining gas can be equal to the input gas
- add new test and `vm.PrecompileEnvironment` stub
2025-02-07 14:29:33 +01:00
Quentin McGaw
a8df623269
chore(ci): restrict each job concurrency except for main branch (#117)
- save some compute minutes 🌱
- Limit concurrency by workflow + ref (except for main branch)
2025-02-06 11:03:26 +00:00
Quentin McGaw
80bdfe7243
chore(ci): use the Go version found in go.mod (#118) 2025-02-06 10:52:45 +00:00
Arran Schlosberg
eda3b59f67
feat(core/types): fine-grained Body RLP override (#109)
## Why this should be merged

Allows for modification of `types.Body` payload data + RLP encoding
without placing the entire RLP burden on the `libevm` user as we did
with `types.HeaderHooks`.

## How this works

RLP encoding of a struct is simply a concatenation of RLP encodings of
fields, encompassed by an RLP "list". The
`AppendRLPFields(rlp.EncoderBuffer, ...)` hook exploits this and plugs
in before all `rlp:"optional"`-tagged fields to allow for inclusion of
any new fields. The `EncoderBuffer` SHOULD be used as the `io.Writer`
passed when encoding each field: `rlp.Encode(buffer, fieldValue)`.

`Body` doesn't have `{En,De}codeRLP` methods so they are implemented to
identically replicate original behaviour when a no-op hook is present.

This pattern is sufficient for the `ava-labs/coreth` modifications of
`Body` but can be modified / extended for more complex scenarios, like
`Header`.

> [!NOTE]
> This PR does not include registration of the hooks as that was not the
initial goal and adding them would create too much PR bloat. There is a
placeholder `var todoRegisteredBodyHooks` global variable that can only
be set in tests.

## How this was tested

- Backwards compatibility: the new methods are fuzzed against a `type
withoutMethods Body` passed directly to `rlp.{En,De}code()`
- `coreth` compatibility: unit test of a local implementation of
`BodyHooks` demonstrating reproducibility of RLP encoding.

---------

Signed-off-by: Arran Schlosberg <519948+ARR4N@users.noreply.github.com>
Co-authored-by: Quentin McGaw <quentin.mcgaw@avalabs.org>
2025-02-05 10:52:28 +00:00
Quentin McGaw
be6e93eedb
chore(ci): linting job changes regarding goheader (#116)
`goheader` only needs to be run on files changed in the current PR as it will otherwise suggest updating copyright years on untouched files. The other linters, however, should be run in the same manner as a local invocation
2025-02-05 09:10:57 +01:00
Quentin McGaw
ee93f60829
feat(core/types): Header hook PostCopy (#106) 2025-02-04 16:56:08 +01:00
Quentin McGaw
e2b0abbe53
chore(ci): automate detection of last auto-rename commit(#99) 2025-01-13 18:12:33 +01:00
Quentin McGaw
d08d0f0510
feat(params): UnmarshalChainJSONConfig and MarshalChainConfigJSON (#92)
- 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
2025-01-12 18:35:14 +01:00
Quentin McGaw
c996175b46
chore(ci): yaml linter workflow and fix yaml files (#98)
- New workflow triggering only on yaml file changes using the built-in `yamllint`
- `.yamllint.yml` configuration added at the root of the project
- Fix existing yml files to satisfy ymllint
- Ignore go-ethereum original yml files
2025-01-12 13:56:08 +00:00
Quentin McGaw
ce2cde5662
docs(linter): comment why goheader is only enabled in the CI (#101) 2025-01-09 14:17:06 +01:00
Quentin McGaw
efa14ab5d0
chore(ci): goheader linting only runs in CI on changed or new files (#100) 2025-01-08 08:38:50 +00:00
Quentin McGaw
9e452f2960
chore(github): issue template configuration and update issue templates (#96) 2024-12-30 18:00:05 +01:00
Quentin McGaw
bee85d6171
chore(ci): define Github labels as code with a workflow (#93) 2024-12-23 15:02:52 +01:00
Arran Schlosberg
4575ced555
feat: types.HeaderHooks JSON round-trip support (#94)
## Why this should be merged

JSON equivalent of #89.

## How this works

The check for registered extras, previously used in `{En,De}codeRLP()`
methods is abstracted into a `Header.hooks() HeaderHooks` method that
either returns (a) an instance of the registered type or (b) a
`NOOPHeaderHooks` if no registration was performed. This is then used
for all hooks, new (JSON) and old (RLP).

## How this was tested

Extension of existing unit tests.
2024-12-19 16:30:04 +00:00
Arran Schlosberg
44f23c8869
refactor: PrecompileEnvironment.{,Use,Refund}Gas() in lieu of args (#73)
## Why this should be merged

Aligns precompiled contracts with the pattern used in
`vm.EVMInterpreter` for regular contracts and simplifies gas accounting
by using existing mechanisms. The most notable simplification occurs
when there are multiple error paths that return early and have to
account for consumed gas (any local solution would likely just mirror
this one).

This forms part of a broader, long-term direction of feature parity
between precompiled and bytecode contracts, exposed via
`vm.PrecompileEnvironment`.

The `vm.Contract.Value()` method is also exposed as a natural
accompaniment to this change.

## How this works

The original signature for `vm.PrecompiledStatefulContract` received the
amount of gas available and then returned the amount remaining; this has
been removed in lieu of exposing the existing `vm.Contract.UseGas()`
method via the `vm.PrecompileEnvironment`. A new `legacy` package wraps
the old signature and converts it to a new one so `ava-labs/coreth`
doesn't need to be refactored.

```go
func oldPrecompile(env vm.PrecompileEnvironment, input []byte, gas uint64) ([]byte, uint64, error) {
  // ...
  if err != nil {
    return nil, gas - gasCost, err // pattern susceptible to bugs; should it be `nil, gas, err` ?
  }
  // ...
  return output, gas - gasCost, nil  
}

func newPrecompile(env vm.PrecompileEnvironment, input []byte) ([]byte, error) {
  // The original `gas` argument is still available as `env.Gas()`
  // ...
  if !env.UseGas(gasCost) { // an explicit point at which gas is consumed
    return nil, vm.ErrOutOfGas
  }
  // ...
  if err != nil {
    return nil, err
  }
  // ...
  return output, nil
}
```

## How this was tested

Existing unit test modified to use the `legacy` adaptor.

---------

Signed-off-by: Arran Schlosberg <519948+ARR4N@users.noreply.github.com>
Co-authored-by: Quentin McGaw <quentin.mcgaw@gmail.com>
2024-12-18 13:54:51 +00:00
Arran Schlosberg
43878f4fab
feat: internalise command (#90)
## Why this should be merged

Replaces #86. That approach couldn't be replicated for generated JSON
marshalling, and this once also reduces the upstream delta.

## How this works

AST manipulation of a specified file, which finds specified methods and
modifies their names to be unexported.

## How this was tested

Inspection of the output (`core/types/gen_header_rlp.go` remains
unchanged).
2024-12-17 17:20:02 +01:00
Arran Schlosberg
dc7e27aff4
feat: types.HeaderHooks for RLP overrides (#89)
## 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>
2024-12-17 13:54:58 +00:00
Arran Schlosberg
bd44839170
test: lock in types.Header RLP encoding (#87)
## Why this should be merged

We're making changes to very sensitive code that, if broken, can result
in block hashes being different.

## How this works

Change-detector test.

## How this was tested

A randomly filled `types.Header` with expected RLP locked as a constant
in the test.
2024-12-12 13:00:02 +00:00
Arran Schlosberg
aa183c52be
refactor: generate internal Header.encodeRLP() for override (#86)
## Why this should be merged

This is a precursor to being able to override `types.Header` RLP
{en,de}coding. As there is already a `Header.EncodeRLP()` method we
either have to modify the generated code or rename the generated
method—this PR does the latter.

## How this works

The `rlpgen -internal_methods` flag changes the generated methods from
`EncodeRLP()` and `DecodeRLP()` to `encodeRLP()` and `decodeRLP()`,
respectively. A new CI job checks that generated code is up to date. We
can then implement our own `Header.EncodeRLP()` that either overrides or
falls back on the original.

It appears that `core/gen_genesis.go` was out of date but only because
of formatting.

## How this was tested

I deliberately excluded the change to `core/types/gen_header_rlp.go` to
confirm that the new workflow
[detects](https://github.com/ava-labs/libevm/actions/runs/12259667481/job/34202386378?pr=86#step:5:92)
the change and fails. The actual change can be inspected via the code
diff.
2024-12-11 10:20:58 +00:00
Arran Schlosberg
380aa319f9
refactor!: consolidate params and types payload access (#84)
## 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.
2024-12-09 18:32:15 +00:00