Skip to content

Ceyonur/v1.13.14 0.3.0.rc.2 #202

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Required for go-header check https://github.com/golangci/golangci-lint/issues/2470#issuecomment-1473658471
- uses: actions/setup-go@v5
with:
go-version-file: "go.mod"
Expand Down
2 changes: 1 addition & 1 deletion .yamllint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ rules:
ignore:
# Upstream geth files that we don't want to modify unnecessarily.
- .travis.yml
- crypto/secp256k1/libsecp256k1/.travis.yml
- crypto/secp256k1/libsecp256k1/*
2 changes: 1 addition & 1 deletion core/state/state.libevm_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 the libevm authors.
// Copyright 2024-2025 the libevm authors.
//
// The libevm additions to go-ethereum are free software: you can redistribute
// them and/or modify them under the terms of the GNU Lesser General Public License
Expand Down
2 changes: 1 addition & 1 deletion core/state/state_object.libevm_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 the libevm authors.
// Copyright 2024-2025 the libevm authors.
//
// The libevm additions to go-ethereum are free software: you can redistribute
// them and/or modify them under the terms of the GNU Lesser General Public License
Expand Down
9 changes: 6 additions & 3 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,18 +341,20 @@ func (s *StateDB) GetCodeHash(addr common.Address) common.Hash {
}

// GetState retrieves a value from the given account's storage trie.
func (s *StateDB) GetState(addr common.Address, hash common.Hash) common.Hash {
func (s *StateDB) GetState(addr common.Address, hash common.Hash, opts ...stateconf.StateDBStateOption) common.Hash {
stateObject := s.getStateObject(addr)
if stateObject != nil {
hash = transformStateKey(addr, hash, opts...)
return stateObject.GetState(hash)
}
return common.Hash{}
}

// GetCommittedState retrieves a value from the given account's committed storage trie.
func (s *StateDB) GetCommittedState(addr common.Address, hash common.Hash) common.Hash {
func (s *StateDB) GetCommittedState(addr common.Address, hash common.Hash, opts ...stateconf.StateDBStateOption) common.Hash {
stateObject := s.getStateObject(addr)
if stateObject != nil {
hash = transformStateKey(addr, hash, opts...)
return stateObject.GetCommittedState(hash)
}
return common.Hash{}
Expand Down Expand Up @@ -412,9 +414,10 @@ func (s *StateDB) SetCode(addr common.Address, code []byte) {
}
}

func (s *StateDB) SetState(addr common.Address, key, value common.Hash) {
func (s *StateDB) SetState(addr common.Address, key, value common.Hash, opts ...stateconf.StateDBStateOption) {
stateObject := s.getOrNewStateObject(addr)
if stateObject != nil {
key = transformStateKey(addr, key, opts...)
stateObject.SetState(key, value)
}
}
Expand Down
28 changes: 28 additions & 0 deletions core/state/statedb.libevm.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 the libevm authors.

Check failure on line 1 in core/state/statedb.libevm.go

View workflow job for this annotation

GitHub Actions / golangci-lint

Pattern ((20\d\d\-2025)|(2025)) doesn't match. (goheader)
//
// The libevm additions to go-ethereum are free software: you can redistribute
// them and/or modify them under the terms of the GNU Lesser General Public License
Expand All @@ -21,6 +21,7 @@

"github.com/ava-labs/libevm/common"
"github.com/ava-labs/libevm/core/state/snapshot"
"github.com/ava-labs/libevm/libevm/register"
"github.com/ava-labs/libevm/libevm/stateconf"
)

Expand Down Expand Up @@ -52,3 +53,30 @@
}
return snaps
}

type StateDBHooks interface {
TransformStateKey(common.Address, common.Hash) common.Hash
}

func RegisterExtras(s StateDBHooks) {
registeredExtras.MustRegister(s)
}

func TestOnlyClearRegisteredExtras() {
registeredExtras.TestOnlyClear()
}

var registeredExtras register.AtMostOnce[StateDBHooks]

func transformStateKey(addr common.Address, key common.Hash, opts ...stateconf.StateDBStateOption) common.Hash {
r := &registeredExtras
if !r.Registered() || !stateconf.ShouldTransformStateKey(opts...) {
return key
}
return r.Get().TransformStateKey(addr, key)
}

// GetTxHash returns the current tx hash on the StateDB set by SetTxContext.
func (s *StateDB) GetTxHash() common.Hash {
return s.thash
}
53 changes: 52 additions & 1 deletion core/state/statedb.libevm_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 the libevm authors.
// Copyright 2024-2025 the libevm authors.
//
// The libevm additions to go-ethereum are free software: you can redistribute
// them and/or modify them under the terms of the GNU Lesser General Public License
Expand Down Expand Up @@ -126,3 +126,54 @@ func (r *triedbRecorder) Update(
func (r *triedbRecorder) Reader(_ common.Hash) (database.Reader, error) {
return r.Database.Reader(common.Hash{})
}

type highByteFlipper struct{}

func flipHighByte(h common.Hash) common.Hash {
h[0] = ^h[0]
return h
}

func (highByteFlipper) TransformStateKey(_ common.Address, key common.Hash) common.Hash {
return flipHighByte(key)
}

func TestTransformStateKey(t *testing.T) {
cache := NewDatabase(rawdb.NewMemoryDatabase())
sdb, err := New(types.EmptyRootHash, cache, nil)
require.NoErrorf(t, err, "New()")

addr := common.Address{1}
regularKey := common.Hash{0, 'k', 'e', 'y'}
flippedKey := flipHighByte(regularKey)
regularVal := common.Hash{'r', 'e', 'g', 'u', 'l', 'a', 'r'}
flippedVal := common.Hash{'f', 'l', 'i', 'p', 'p', 'e', 'd'}

sdb.SetState(addr, regularKey, regularVal)
sdb.SetState(addr, flippedKey, flippedVal)

assertEq := func(t *testing.T, key, want common.Hash, opts ...stateconf.StateDBStateOption) {
t.Helper()
assert.Equal(t, want, sdb.GetState(addr, key, opts...))
}

assertEq(t, regularKey, regularVal)
assertEq(t, flippedKey, flippedVal)

// Typically the hook would be registered before any state access or
// setting, but doing it here aids testing by showing the before-and-after
// effects.
RegisterExtras(highByteFlipper{})
t.Cleanup(TestOnlyClearRegisteredExtras)

noTransform := stateconf.SkipStateKeyTransformation()
assertEq(t, regularKey, flippedVal)
assertEq(t, regularKey, regularVal, noTransform)
assertEq(t, flippedKey, regularVal)
assertEq(t, flippedKey, flippedVal, noTransform)

updatedVal := common.Hash{'u', 'p', 'd', 'a', 't', 'e', 'd'}
sdb.SetState(addr, regularKey, updatedVal)
assertEq(t, regularKey, updatedVal)
assertEq(t, flippedKey, updatedVal, noTransform)
}
2 changes: 1 addition & 1 deletion core/state_transition.libevm.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 the libevm authors.
// Copyright 2024-2025 the libevm authors.
//
// The libevm additions to go-ethereum are free software: you can redistribute
// them and/or modify them under the terms of the GNU Lesser General Public License
Expand Down
2 changes: 1 addition & 1 deletion core/state_transition.libevm_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 the libevm authors.
// Copyright 2024-2025 the libevm authors.
//
// The libevm additions to go-ethereum are free software: you can redistribute
// them and/or modify them under the terms of the GNU Lesser General Public License
Expand Down
2 changes: 1 addition & 1 deletion core/types/block.libevm_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 the libevm authors.
// Copyright 2024-2025 the libevm authors.
//
// The libevm additions to go-ethereum are free software: you can redistribute
// them and/or modify them under the terms of the GNU Lesser General Public License
Expand Down
2 changes: 1 addition & 1 deletion core/types/rlp_payload.libevm.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 the libevm authors.
// Copyright 2024-2025 the libevm authors.
//
// The libevm additions to go-ethereum are free software: you can redistribute
// them and/or modify them under the terms of the GNU Lesser General Public License
Expand Down
2 changes: 1 addition & 1 deletion core/types/state_account.libevm_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 the libevm authors.
// Copyright 2024-2025 the libevm authors.
//
// The libevm additions to go-ethereum are free software: you can redistribute
// them and/or modify them under the terms of the GNU Lesser General Public License
Expand Down
2 changes: 1 addition & 1 deletion core/types/state_account_storage.libevm_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 the libevm authors.
// Copyright 2024-2025 the libevm authors.
//
// The libevm additions to go-ethereum are free software: you can redistribute
// them and/or modify them under the terms of the GNU Lesser General Public License
Expand Down
2 changes: 1 addition & 1 deletion core/vm/contracts.libevm.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 the libevm authors.
// Copyright 2024-2025 the libevm authors.
//
// The libevm additions to go-ethereum are free software: you can redistribute
// them and/or modify them under the terms of the GNU Lesser General Public License
Expand Down
9 changes: 6 additions & 3 deletions core/vm/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/ava-labs/libevm/common"
"github.com/ava-labs/libevm/core/types"
"github.com/ava-labs/libevm/libevm/stateconf"
"github.com/ava-labs/libevm/params"
"github.com/holiman/uint256"
)
Expand All @@ -45,9 +46,9 @@ type StateDB interface {
SubRefund(uint64)
GetRefund() uint64

GetCommittedState(common.Address, common.Hash) common.Hash
GetState(common.Address, common.Hash) common.Hash
SetState(common.Address, common.Hash, common.Hash)
GetCommittedState(common.Address, common.Hash, ...stateconf.StateDBStateOption) common.Hash
GetState(common.Address, common.Hash, ...stateconf.StateDBStateOption) common.Hash
SetState(common.Address, common.Hash, common.Hash, ...stateconf.StateDBStateOption)

GetTransientState(addr common.Address, key common.Hash) common.Hash
SetTransientState(addr common.Address, key, value common.Hash)
Expand Down Expand Up @@ -79,6 +80,8 @@ type StateDB interface {

AddLog(*types.Log)
AddPreimage(common.Hash, []byte)

GetTxHash() common.Hash
}

// CallContext provides a basic interface for the EVM calling conventions. The EVM
Expand Down
4 changes: 2 additions & 2 deletions crypto/secp256k1/ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ int secp256k1_ext_scalar_mul(const secp256k1_context* ctx, unsigned char *point,
ARG_CHECK(scalar != NULL);
(void)ctx;

secp256k1_fe_set_b32(&feX, point);
secp256k1_fe_set_b32(&feY, point+32);
secp256k1_fe_set_b32_limit(&feX, point);
secp256k1_fe_set_b32_limit(&feY, point+32);
secp256k1_ge_set_xy(&ge, &feX, &feY);
secp256k1_scalar_set_b32(&s, scalar, &overflow);
if (overflow || secp256k1_scalar_is_zero(&s)) {
Expand Down
101 changes: 101 additions & 0 deletions crypto/secp256k1/libsecp256k1/.cirrus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
env:
### cirrus config
CIRRUS_CLONE_DEPTH: 1
### compiler options
HOST:
WRAPPER_CMD:
# Specific warnings can be disabled with -Wno-error=foo.
# -pedantic-errors is not equivalent to -Werror=pedantic and thus not implied by -Werror according to the GCC manual.
WERROR_CFLAGS: -Werror -pedantic-errors
MAKEFLAGS: -j4
BUILD: check
### secp256k1 config
ECMULTWINDOW: 15
ECMULTGENKB: 22
ASM: no
WIDEMUL: auto
WITH_VALGRIND: yes
EXTRAFLAGS:
### secp256k1 modules
EXPERIMENTAL: no
ECDH: no
RECOVERY: no
EXTRAKEYS: no
SCHNORRSIG: no
MUSIG: no
ELLSWIFT: no
### test options
SECP256K1_TEST_ITERS: 64
BENCH: yes
SECP256K1_BENCH_ITERS: 2
CTIMETESTS: yes
# Compile and run the tests
EXAMPLES: yes

cat_logs_snippet: &CAT_LOGS
always:
cat_tests_log_script:
- cat tests.log || true
cat_noverify_tests_log_script:
- cat noverify_tests.log || true
cat_exhaustive_tests_log_script:
- cat exhaustive_tests.log || true
cat_ctime_tests_log_script:
- cat ctime_tests.log || true
cat_bench_log_script:
- cat bench.log || true
cat_config_log_script:
- cat config.log || true
cat_test_env_script:
- cat test_env.log || true
cat_ci_env_script:
- env

linux_arm64_container_snippet: &LINUX_ARM64_CONTAINER
env_script:
- env | tee /tmp/env
build_script:
- DOCKER_BUILDKIT=1 docker build --file "ci/linux-debian.Dockerfile" --tag="ci_secp256k1_arm"
- docker image prune --force # Cleanup stale layers
test_script:
- docker run --rm --mount "type=bind,src=./,dst=/ci_secp256k1" --env-file /tmp/env --replace --name "ci_secp256k1_arm" "ci_secp256k1_arm" bash -c "cd /ci_secp256k1/ && ./ci/ci.sh"

task:
name: "ARM64: Linux (Debian stable)"
persistent_worker:
labels:
type: arm64
env:
ECDH: yes
RECOVERY: yes
EXTRAKEYS: yes
SCHNORRSIG: yes
MUSIG: yes
ELLSWIFT: yes
matrix:
# Currently only gcc-snapshot, the other compilers are tested on GHA with QEMU
- env: { CC: 'gcc-snapshot' }
<< : *LINUX_ARM64_CONTAINER
<< : *CAT_LOGS

task:
name: "ARM64: Linux (Debian stable), Valgrind"
persistent_worker:
labels:
type: arm64
env:
ECDH: yes
RECOVERY: yes
EXTRAKEYS: yes
SCHNORRSIG: yes
MUSIG: yes
ELLSWIFT: yes
WRAPPER_CMD: 'valgrind --error-exitcode=42'
SECP256K1_TEST_ITERS: 2
matrix:
- env: { CC: 'gcc' }
- env: { CC: 'clang' }
- env: { CC: 'gcc-snapshot' }
- env: { CC: 'clang-snapshot' }
<< : *LINUX_ARM64_CONTAINER
<< : *CAT_LOGS
2 changes: 2 additions & 0 deletions crypto/secp256k1/libsecp256k1/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
src/precomputed_ecmult.c linguist-generated
src/precomputed_ecmult_gen.c linguist-generated
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: "Install Valgrind"
description: "Install Homebrew's Valgrind package and cache it."
runs:
using: "composite"
steps:
- run: |
brew tap LouisBrunner/valgrind
brew fetch --HEAD LouisBrunner/valgrind/valgrind
echo "CI_HOMEBREW_CELLAR_VALGRIND=$(brew --cellar valgrind)" >> "$GITHUB_ENV"
shell: bash

- run: |
sw_vers > valgrind_fingerprint
brew --version >> valgrind_fingerprint
git -C "$(brew --cache)/valgrind--git" rev-parse HEAD >> valgrind_fingerprint
cat valgrind_fingerprint
shell: bash

- uses: actions/cache@v4
id: cache
with:
path: ${{ env.CI_HOMEBREW_CELLAR_VALGRIND }}
key: ${{ github.job }}-valgrind-${{ hashFiles('valgrind_fingerprint') }}

- if: steps.cache.outputs.cache-hit != 'true'
run: |
brew install --HEAD LouisBrunner/valgrind/valgrind
shell: bash

- if: steps.cache.outputs.cache-hit == 'true'
run: |
brew link valgrind
shell: bash
Loading
Loading