diff --git a/core/types/data_blob_tx.go b/core/types/data_blob_tx.go index c356331dbc5c..81b52f0ebb86 100644 --- a/core/types/data_blob_tx.go +++ b/core/types/data_blob_tx.go @@ -10,7 +10,6 @@ import ( "github.com/holiman/uint256" "github.com/protolambda/ztyp/codec" "github.com/protolambda/ztyp/conv" - "github.com/protolambda/ztyp/tree" . "github.com/protolambda/ztyp/view" ) @@ -58,12 +57,6 @@ func (*AddressSSZ) FixedLength() uint64 { return 20 } -func (addr *AddressSSZ) HashTreeRoot(hFn tree.HashFn) tree.Root { - var out tree.Root - copy(out[0:20], addr[:]) - return out -} - // AddressOptionalSSZ implements Union[None, Address] type AddressOptionalSSZ struct { Address *AddressSSZ @@ -112,14 +105,6 @@ func (*AddressOptionalSSZ) FixedLength() uint64 { return 0 } -func (ao *AddressOptionalSSZ) HashTreeRoot(hFn tree.HashFn) tree.Root { - if ao.Address == nil { - return hFn(tree.Root{}, tree.Root{0: 0}) - } else { - return hFn(ao.Address.HashTreeRoot(hFn), tree.Root{0: 1}) - } -} - type TxDataView []byte func (tdv *TxDataView) Deserialize(dr *codec.DecodingReader) error { @@ -138,10 +123,6 @@ func (tdv *TxDataView) FixedLength() uint64 { return 0 } -func (tdv TxDataView) HashTreeRoot(hFn tree.HashFn) tree.Root { - return hFn.ByteListHTR(tdv, MAX_CALLDATA_SIZE) -} - func (tdv TxDataView) MarshalText() ([]byte, error) { return conv.BytesMarshalText(tdv[:]) } @@ -214,16 +195,6 @@ func (vhv *VersionedHashesView) FixedLength() uint64 { return 0 // it's a list, no fixed length } -func (vhv VersionedHashesView) HashTreeRoot(hFn tree.HashFn) tree.Root { - length := uint64(len(vhv)) - return hFn.ComplexListHTR(func(i uint64) tree.HTR { - if i < length { - return (*tree.Root)(&vhv[i]) - } - return nil - }, length, MAX_VERSIONED_HASHES_LIST_SIZE) -} - type StorageKeysView []common.Hash func (skv *StorageKeysView) Deserialize(dr *codec.DecodingReader) error { @@ -242,16 +213,6 @@ func (skv *StorageKeysView) FixedLength() uint64 { return 0 // it's a list, no fixed length } -func (skv StorageKeysView) HashTreeRoot(hFn tree.HashFn) tree.Root { - length := uint64(len(skv)) - return hFn.ComplexListHTR(func(i uint64) tree.HTR { - if i < length { - return (*tree.Root)(&skv[i]) - } - return nil - }, length, MAX_ACCESS_LIST_STORAGE_KEYS) -} - type AccessTupleView AccessTuple func (atv *AccessTupleView) Deserialize(dr *codec.DecodingReader) error { @@ -270,10 +231,6 @@ func (atv *AccessTupleView) FixedLength() uint64 { return 0 } -func (atv *AccessTupleView) HashTreeRoot(hFn tree.HashFn) tree.Root { - return hFn.HashTreeRoot((*AddressSSZ)(&atv.Address), (*StorageKeysView)(&atv.StorageKeys)) -} - type AccessListView AccessList func (alv *AccessListView) Deserialize(dr *codec.DecodingReader) error { @@ -301,16 +258,6 @@ func (alv *AccessListView) FixedLength() uint64 { return 0 } -func (alv AccessListView) HashTreeRoot(hFn tree.HashFn) tree.Root { - length := uint64(len(alv)) - return hFn.ComplexListHTR(func(i uint64) tree.HTR { - if i < length { - return (*AccessTupleView)(&alv[i]) - } - return nil - }, length, MAX_ACCESS_LIST_SIZE) -} - type BlobTxMessage struct { ChainID Uint256View Nonce Uint64View @@ -350,10 +297,6 @@ func (stx *SignedBlobTx) FixedLength() uint64 { return 0 } -func (tx *BlobTxMessage) HashTreeRoot(hFn tree.HashFn) tree.Root { - return hFn.HashTreeRoot(&tx.ChainID, &tx.Nonce, &tx.GasTipCap, &tx.GasFeeCap, &tx.Gas, &tx.To, &tx.Value, &tx.Data, &tx.AccessList, &tx.MaxFeePerDataGas, &tx.BlobVersionedHashes) -} - // copy creates a deep copy of the transaction data and initializes all fields. func (tx *BlobTxMessage) copy() *BlobTxMessage { cpy := &BlobTxMessage{ diff --git a/core/types/hashing.go b/core/types/hashing.go index c54f44ee5a66..0bc049206dc5 100644 --- a/core/types/hashing.go +++ b/core/types/hashing.go @@ -23,7 +23,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/rlp" - "github.com/protolambda/ztyp/tree" + "github.com/protolambda/ztyp/codec" "golang.org/x/crypto/sha3" ) @@ -59,15 +59,14 @@ func prefixedRlpHash(prefix byte, x interface{}) (h common.Hash) { return h } -// prefixedSSZHash writes the prefix into the hasher before SSZ hash-tree-root-ing x. -// It's used for typed transactions. -func prefixedSSZHash(prefix byte, x tree.HTR) (h common.Hash) { +// prefixedSSZHash writes the prefix into the hasher before SSZ encoding x. It's used for +// computing the tx id & signing hashes of signed blob transactions. +func prefixedSSZHash(prefix byte, obj codec.Serializable) (h common.Hash) { sha := hasherPool.Get().(crypto.KeccakState) defer hasherPool.Put(sha) sha.Reset() sha.Write([]byte{prefix}) - htr := x.HashTreeRoot(tree.GetHashFn()) - sha.Write(htr[:]) + EncodeSSZ(sha, obj) sha.Read(h[:]) return h } diff --git a/core/types/transaction.go b/core/types/transaction.go index 808fc81d2de1..7adc0682a88c 100644 --- a/core/types/transaction.go +++ b/core/types/transaction.go @@ -503,7 +503,7 @@ func (tx *Transaction) Hash() common.Hash { case BlobTxType: // TODO(eip-4844): We should remove this ugly switch by making hash() // a part of the TxData interface - h = prefixedSSZHash(tx.Type(), &tx.inner.(*SignedBlobTx).Message) + h = prefixedSSZHash(tx.Type(), tx.inner.(*SignedBlobTx)) default: h = prefixedRlpHash(tx.Type(), tx.inner) } diff --git a/go.mod b/go.mod index a0c506b9e121..82cc93a253f6 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,6 @@ require ( github.com/gorilla/websocket v1.4.2 github.com/graph-gophers/graphql-go v1.3.0 github.com/hashicorp/go-bexpr v0.1.10 - github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d github.com/herumi/bls-eth-go-binary v1.28.1 // indirect github.com/holiman/big v0.0.0-20221017200358-a027dc42d04e github.com/holiman/bloomfilter/v2 v2.0.3 diff --git a/go.sum b/go.sum index e3ab3f1c308e..afa21fa748b1 100644 --- a/go.sum +++ b/go.sum @@ -220,8 +220,6 @@ github.com/hashicorp/go-bexpr v0.1.10 h1:9kuI5PFotCboP3dkDYFr/wi0gg0QVbSNz5oFRpx github.com/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d h1:dg1dEPuWpEqDnvIw251EVy4zlP8gWbsGj4BsUKCRpYs= -github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= github.com/herumi/bls-eth-go-binary v1.28.1 h1:fcIZ48y5EE9973k05XjE8+P3YiQgjZz4JI/YabAm8KA= github.com/herumi/bls-eth-go-binary v1.28.1/go.mod h1:luAnRm3OsMQeokhGzpYmc0ZKwawY7o87PUEP11Z7r7U= github.com/holiman/big v0.0.0-20221017200358-a027dc42d04e h1:pIYdhNkDh+YENVNi3gto8n9hAmRxKxoar0iE6BLucjw= @@ -366,10 +364,6 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/tsdb v0.7.1 h1:YZcsG11NqnK4czYLrWd9mpEuAJIHVQLwdrleYfszMAA= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= -github.com/protolambda/go-kzg v0.0.0-20221121235515-3f3e1ef6beb7 h1:yzqsT6UIT17bmesiG9iB6+3cQkmMAtFjUffx5KrXgkk= -github.com/protolambda/go-kzg v0.0.0-20221121235515-3f3e1ef6beb7/go.mod h1:7EhkBJFo/qJ9sToiW5baPqbyPo/TadVHn4iNdpwEW/w= -github.com/protolambda/go-kzg v0.0.0-20221122014024-bb3fa3695412 h1:MQBDul/k5XDDYF5fVn18lNwkWKxpK93FbYeaum1b1UE= -github.com/protolambda/go-kzg v0.0.0-20221122014024-bb3fa3695412/go.mod h1:7EhkBJFo/qJ9sToiW5baPqbyPo/TadVHn4iNdpwEW/w= github.com/protolambda/go-kzg v0.0.0-20221129234330-612948a21fb0 h1:DDaoou46n4krrbtDkymmqFAx2iqxatt2Sk+B1ZOM45A= github.com/protolambda/go-kzg v0.0.0-20221129234330-612948a21fb0/go.mod h1:7EhkBJFo/qJ9sToiW5baPqbyPo/TadVHn4iNdpwEW/w= github.com/protolambda/ztyp v0.2.1 h1:+rfw75/Zh8EopNlG652TGDXlLgJflj6XWxJ9yCVpJws= @@ -556,7 +550,6 @@ golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210420205809-ac73e9fd8988/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20211020174200-9d6173849985/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220818161305-2296e01440c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A= golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=