Skip to content

Commit 99f0d0b

Browse files
Add *StateDB.TxHash for usage with Warp (#204)
## Why this should be merged Coreth and Subnet-EVM require access to the current tx hash in the Warp precompile (for selecting the correct predicate results). This can not be exposed as a wrapper through the `OverrideEVMResetArgs` because `SetTxContext` is called _prior_ to resetting the EVM instance. Therefore, the `SetTxContext` function on any DB wrapper would never be called. ## How this works Exposes the existing `txHash` through a `TxHash()` function. ## How this was tested Added a trivial unit test.
1 parent 08e2b6d commit 99f0d0b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

core/state/statedb.libevm.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ import (
2424
"github.com/ava-labs/libevm/libevm/stateconf"
2525
)
2626

27+
// TxHash returns the current transaction hash set by [StateDB.SetTxContext].
28+
func (s *StateDB) TxHash() common.Hash {
29+
return s.thash
30+
}
31+
2732
// SnapshotTree mirrors the functionality of a [snapshot.Tree], allowing for
2833
// drop-in replacements. This is intended as a temporary feature as a workaround
2934
// until a standard Tree can be used.

core/state/statedb.libevm_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ import (
3636
"github.com/ava-labs/libevm/triedb/hashdb"
3737
)
3838

39+
func TestTxHash(t *testing.T) {
40+
db := NewDatabase(rawdb.NewMemoryDatabase())
41+
state, err := New(types.EmptyRootHash, db, nil)
42+
require.NoError(t, err)
43+
44+
assert.Zero(t, state.TxHash(), "Tx hash should initially be uninitialized")
45+
46+
hash := common.Hash{1}
47+
state.SetTxContext(hash, 3)
48+
assert.Equal(t, hash, state.TxHash(), "Tx hash should have been updated")
49+
}
50+
3951
func TestStateDBCommitPropagatesOptions(t *testing.T) {
4052
memdb := rawdb.NewMemoryDatabase()
4153
trieRec := &triedbRecorder{Database: hashdb.New(memdb, nil, &trie.MerkleResolver{})}

0 commit comments

Comments
 (0)