Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 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
87 changes: 0 additions & 87 deletions core/types/account.go

This file was deleted.

73 changes: 0 additions & 73 deletions core/types/gen_account.go

This file was deleted.

66 changes: 0 additions & 66 deletions core/types/hashes.go

This file was deleted.

7 changes: 7 additions & 0 deletions core/types/hashes_ext.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// (c) 2025, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package types

// EmptyExtDataHash is the known hash of empty extdata bytes.
var EmptyExtDataHash = rlpHash([]byte(nil))
63 changes: 0 additions & 63 deletions core/types/hashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
package types

import (
"bytes"
"sync"

"github.com/ava-labs/libevm/common"
Expand All @@ -41,11 +40,6 @@ var hasherPool = sync.Pool{
New: func() interface{} { return sha3.NewLegacyKeccak256() },
}

// encodeBufferPool holds temporary encoder buffers for DeriveSha and TX encoding.
var encodeBufferPool = sync.Pool{
New: func() interface{} { return new(bytes.Buffer) },
}

// rlpHash encodes x and hashes the encoded bytes.
func rlpHash(x interface{}) (h common.Hash) {
sha := hasherPool.Get().(crypto.KeccakState)
Expand All @@ -55,60 +49,3 @@ func rlpHash(x interface{}) (h common.Hash) {
sha.Read(h[:])
return h
}

// TrieHasher is the tool used to calculate the hash of derivable list.
// This is internal, do not use.
type TrieHasher interface {
Reset()
Update([]byte, []byte) error
Hash() common.Hash
}

// DerivableList is the input to DeriveSha.
// It is implemented by the 'Transactions' and 'Receipts' types.
// This is internal, do not use these methods.
type DerivableList interface {
Len() int
EncodeIndex(int, *bytes.Buffer)
}

func encodeForDerive(list DerivableList, i int, buf *bytes.Buffer) []byte {
buf.Reset()
list.EncodeIndex(i, buf)
// It's really unfortunate that we need to perform this copy.
// StackTrie holds onto the values until Hash is called, so the values
// written to it must not alias.
return common.CopyBytes(buf.Bytes())
}

// DeriveSha creates the tree hashes of transactions, receipts, and withdrawals in a block header.
func DeriveSha(list DerivableList, hasher TrieHasher) common.Hash {
hasher.Reset()

valueBuf := encodeBufferPool.Get().(*bytes.Buffer)
defer encodeBufferPool.Put(valueBuf)

// StackTrie requires values to be inserted in increasing hash order, which is not the
// order that `list` provides hashes in. This insertion sequence ensures that the
// order is correct.
//
// The error returned by hasher is omitted because hasher will produce an incorrect
// hash in case any error occurs.
var indexBuf []byte
for i := 1; i < list.Len() && i <= 0x7f; i++ {
indexBuf = rlp.AppendUint64(indexBuf[:0], uint64(i))
value := encodeForDerive(list, i, valueBuf)
hasher.Update(indexBuf, value)
}
if list.Len() > 0 {
indexBuf = rlp.AppendUint64(indexBuf[:0], 0)
value := encodeForDerive(list, 0, valueBuf)
hasher.Update(indexBuf, value)
}
for i := 0x80; i < list.Len(); i++ {
indexBuf = rlp.AppendUint64(indexBuf[:0], uint64(i))
value := encodeForDerive(list, i, valueBuf)
hasher.Update(indexBuf, value)
}
return hasher.Hash()
}
18 changes: 17 additions & 1 deletion core/types/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@ import (
)

// The following types are used directly as their upstream definitions.
// So we list them all here to avoid having many individual files.
type (
AccessList = ethtypes.AccessList
AccessListTx = ethtypes.AccessListTx
AccessTuple = ethtypes.AccessTuple
Account = ethtypes.Account
BlobTx = ethtypes.BlobTx
BlobTxSidecar = ethtypes.BlobTxSidecar
Block = ethtypes.Block
BlockNonce = ethtypes.BlockNonce
Blocks = ethtypes.Blocks
Bloom = ethtypes.Bloom
Body = ethtypes.Body
DerivableList = ethtypes.DerivableList
DynamicFeeTx = ethtypes.DynamicFeeTx
GenesisAlloc = ethtypes.GenesisAlloc
Header = ethtypes.Header
HomesteadSigner = ethtypes.HomesteadSigner
LegacyTx = ethtypes.LegacyTx
Log = ethtypes.Log
Receipt = ethtypes.Receipt
ReceiptForStorage = ethtypes.ReceiptForStorage
Receipts = ethtypes.Receipts
Expand All @@ -32,6 +35,7 @@ type (
StateAccount = ethtypes.StateAccount
Transaction = ethtypes.Transaction
Transactions = ethtypes.Transactions
TrieHasher = ethtypes.TrieHasher
TxByNonce = ethtypes.TxByNonce
TxData = ethtypes.TxData
)
Expand All @@ -50,13 +54,24 @@ const (
LegacyTxType = ethtypes.LegacyTxType
)

// The following variables are used directly as their upstream definitions.
var (
EmptyRootHash = ethtypes.EmptyRootHash
EmptyUncleHash = ethtypes.EmptyUncleHash
EmptyCodeHash = ethtypes.EmptyCodeHash
EmptyTxsHash = ethtypes.EmptyTxsHash
EmptyReceiptsHash = ethtypes.EmptyReceiptsHash
EmptyVerkleHash = ethtypes.EmptyVerkleHash
)

// The following functions are used directly as their upstream definitions.
var (
BloomLookup = ethtypes.BloomLookup
BytesToBloom = ethtypes.BytesToBloom
CalcUncleHash = ethtypes.CalcUncleHash
CopyHeader = ethtypes.CopyHeader
CreateBloom = ethtypes.CreateBloom
DeriveSha = ethtypes.DeriveSha
EncodeNonce = ethtypes.EncodeNonce
FullAccount = ethtypes.FullAccount
FullAccountRLP = ethtypes.FullAccountRLP
Expand All @@ -67,6 +82,7 @@ var (
NewReceipt = ethtypes.NewReceipt
NewTransaction = ethtypes.NewTransaction
SlimAccountRLP = ethtypes.SlimAccountRLP
TrieRootHash = ethtypes.TrieRootHash

// Signers
LatestSigner = ethtypes.LatestSigner
Expand Down
Loading
Loading