Skip to content

Commit e605d07

Browse files
authored
core: remove unused interoptypes (#601)
1 parent 3d7afdc commit e605d07

File tree

2 files changed

+0
-272
lines changed

2 files changed

+0
-272
lines changed

core/types/interoptypes/interop.go

Lines changed: 0 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,132 +1,16 @@
11
package interoptypes
22

33
import (
4-
"encoding/binary"
54
"encoding/json"
65
"errors"
76
"fmt"
8-
"math"
9-
10-
"github.com/holiman/uint256"
117

128
"github.com/ethereum/go-ethereum/common"
139
"github.com/ethereum/go-ethereum/common/hexutil"
1410
"github.com/ethereum/go-ethereum/core/types"
15-
"github.com/ethereum/go-ethereum/crypto"
1611
"github.com/ethereum/go-ethereum/params"
1712
)
1813

19-
var ExecutingMessageEventTopic = crypto.Keccak256Hash([]byte("ExecutingMessage(bytes32,(address,uint256,uint256,uint256,uint256))"))
20-
21-
type Message struct {
22-
Identifier Identifier `json:"identifier"`
23-
PayloadHash common.Hash `json:"payloadHash"`
24-
}
25-
26-
func (m *Message) DecodeEvent(topics []common.Hash, data []byte) error {
27-
if len(topics) != 2 { // event hash, indexed payloadHash
28-
return fmt.Errorf("unexpected number of event topics: %d", len(topics))
29-
}
30-
if topics[0] != ExecutingMessageEventTopic {
31-
return fmt.Errorf("unexpected event topic %q", topics[0])
32-
}
33-
if len(data) != 32*5 {
34-
return fmt.Errorf("unexpected identifier data length: %d", len(data))
35-
}
36-
take := func(length uint) []byte {
37-
taken := data[:length]
38-
data = data[length:]
39-
return taken
40-
}
41-
takeZeroes := func(length uint) error {
42-
for _, v := range take(length) {
43-
if v != 0 {
44-
return errors.New("expected zero")
45-
}
46-
}
47-
return nil
48-
}
49-
if err := takeZeroes(12); err != nil {
50-
return fmt.Errorf("invalid address padding: %w", err)
51-
}
52-
m.Identifier.Origin = common.Address(take(20))
53-
if err := takeZeroes(32 - 8); err != nil {
54-
return fmt.Errorf("invalid block number padding: %w", err)
55-
}
56-
m.Identifier.BlockNumber = binary.BigEndian.Uint64(take(8))
57-
if err := takeZeroes(32 - 4); err != nil {
58-
return fmt.Errorf("invalid log index padding: %w", err)
59-
}
60-
m.Identifier.LogIndex = binary.BigEndian.Uint32(take(4))
61-
if err := takeZeroes(32 - 8); err != nil {
62-
return fmt.Errorf("invalid timestamp padding: %w", err)
63-
}
64-
m.Identifier.Timestamp = binary.BigEndian.Uint64(take(8))
65-
m.Identifier.ChainID.SetBytes32(take(32))
66-
m.PayloadHash = topics[1]
67-
return nil
68-
}
69-
70-
func ExecutingMessagesFromLogs(logs []*types.Log) ([]Message, error) {
71-
var executingMessages []Message
72-
for i, l := range logs {
73-
if l.Address == params.InteropCrossL2InboxAddress {
74-
// ignore events that do not match this
75-
if len(l.Topics) == 0 || l.Topics[0] != ExecutingMessageEventTopic {
76-
continue
77-
}
78-
var msg Message
79-
if err := msg.DecodeEvent(l.Topics, l.Data); err != nil {
80-
return nil, fmt.Errorf("invalid executing message %d, tx-log %d: %w", len(executingMessages), i, err)
81-
}
82-
executingMessages = append(executingMessages, msg)
83-
}
84-
}
85-
return executingMessages, nil
86-
}
87-
88-
type Identifier struct {
89-
Origin common.Address
90-
BlockNumber uint64
91-
LogIndex uint32
92-
Timestamp uint64
93-
ChainID uint256.Int // flat, not a pointer, to make Identifier safe as map key
94-
}
95-
96-
type identifierMarshaling struct {
97-
Origin common.Address `json:"origin"`
98-
BlockNumber hexutil.Uint64 `json:"blockNumber"`
99-
LogIndex hexutil.Uint64 `json:"logIndex"`
100-
Timestamp hexutil.Uint64 `json:"timestamp"`
101-
ChainID hexutil.U256 `json:"chainID"`
102-
}
103-
104-
func (id Identifier) MarshalJSON() ([]byte, error) {
105-
var enc identifierMarshaling
106-
enc.Origin = id.Origin
107-
enc.BlockNumber = hexutil.Uint64(id.BlockNumber)
108-
enc.LogIndex = hexutil.Uint64(id.LogIndex)
109-
enc.Timestamp = hexutil.Uint64(id.Timestamp)
110-
enc.ChainID = (hexutil.U256)(id.ChainID)
111-
return json.Marshal(&enc)
112-
}
113-
114-
func (id *Identifier) UnmarshalJSON(input []byte) error {
115-
var dec identifierMarshaling
116-
if err := json.Unmarshal(input, &dec); err != nil {
117-
return err
118-
}
119-
id.Origin = dec.Origin
120-
id.BlockNumber = uint64(dec.BlockNumber)
121-
if dec.LogIndex > math.MaxUint32 {
122-
return fmt.Errorf("log index too large: %d", dec.LogIndex)
123-
}
124-
id.LogIndex = uint32(dec.LogIndex)
125-
id.Timestamp = uint64(dec.Timestamp)
126-
id.ChainID = (uint256.Int)(dec.ChainID)
127-
return nil
128-
}
129-
13014
type SafetyLevel string
13115

13216
func (lvl SafetyLevel) String() string {

core/types/interoptypes/interop_test.go

Lines changed: 0 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -10,39 +10,6 @@ import (
1010
"github.com/ethereum/go-ethereum/params"
1111
)
1212

13-
func FuzzMessage_DecodeEvent(f *testing.F) {
14-
f.Fuzz(func(t *testing.T, validEvTopic bool, numTopics uint8, data []byte) {
15-
if len(data) < 32 {
16-
return
17-
}
18-
if len(data) > 100_000 {
19-
return
20-
}
21-
if validEvTopic { // valid even signature topic implies a topic to be there
22-
numTopics += 1
23-
}
24-
if numTopics > 4 { // There can be no more than 4 topics per log event
25-
return
26-
}
27-
if int(numTopics)*32 > len(data) {
28-
return
29-
}
30-
var topics []common.Hash
31-
if validEvTopic {
32-
topics = append(topics, ExecutingMessageEventTopic)
33-
}
34-
for i := 0; i < int(numTopics); i++ {
35-
var topic common.Hash
36-
copy(topic[:], data[:])
37-
data = data[32:]
38-
}
39-
require.NotPanics(t, func() {
40-
var m Message
41-
_ = m.DecodeEvent(topics, data)
42-
})
43-
})
44-
}
45-
4613
func TestSafetyLevel(t *testing.T) {
4714
require.True(t, Invalid.wellFormatted())
4815
require.True(t, Unsafe.wellFormatted())
@@ -54,129 +21,6 @@ func TestSafetyLevel(t *testing.T) {
5421
require.False(t, SafetyLevel("").wellFormatted())
5522
}
5623

57-
func TestInteropMessageFormatEdgeCases(t *testing.T) {
58-
tests := []struct {
59-
name string
60-
log *types.Log
61-
expectedError string
62-
}{
63-
{
64-
name: "Empty Topics",
65-
log: &types.Log{
66-
Address: params.InteropCrossL2InboxAddress,
67-
Topics: []common.Hash{},
68-
Data: make([]byte, 32*5),
69-
},
70-
expectedError: "unexpected number of event topics: 0",
71-
},
72-
{
73-
name: "Wrong Event Topic",
74-
log: &types.Log{
75-
Address: params.InteropCrossL2InboxAddress,
76-
Topics: []common.Hash{
77-
common.BytesToHash([]byte("wrong topic")),
78-
common.BytesToHash([]byte("payloadHash")),
79-
},
80-
Data: make([]byte, 32*5),
81-
},
82-
expectedError: "unexpected event topic",
83-
},
84-
{
85-
name: "Missing PayloadHash Topic",
86-
log: &types.Log{
87-
Address: params.InteropCrossL2InboxAddress,
88-
Topics: []common.Hash{
89-
common.BytesToHash(ExecutingMessageEventTopic[:]),
90-
},
91-
Data: make([]byte, 32*5),
92-
},
93-
expectedError: "unexpected number of event topics: 1",
94-
},
95-
{
96-
name: "Too Many Topics",
97-
log: &types.Log{
98-
Address: params.InteropCrossL2InboxAddress,
99-
Topics: []common.Hash{
100-
common.BytesToHash(ExecutingMessageEventTopic[:]),
101-
common.BytesToHash([]byte("payloadHash")),
102-
common.BytesToHash([]byte("extra")),
103-
},
104-
Data: make([]byte, 32*5),
105-
},
106-
expectedError: "unexpected number of event topics: 3",
107-
},
108-
{
109-
name: "Data Too Short",
110-
log: &types.Log{
111-
Address: params.InteropCrossL2InboxAddress,
112-
Topics: []common.Hash{
113-
common.BytesToHash(ExecutingMessageEventTopic[:]),
114-
common.BytesToHash([]byte("payloadHash")),
115-
},
116-
Data: make([]byte, 32*4), // One word too short
117-
},
118-
expectedError: "unexpected identifier data length: 128",
119-
},
120-
{
121-
name: "Data Too Long",
122-
log: &types.Log{
123-
Address: params.InteropCrossL2InboxAddress,
124-
Topics: []common.Hash{
125-
common.BytesToHash(ExecutingMessageEventTopic[:]),
126-
common.BytesToHash([]byte("payloadHash")),
127-
},
128-
Data: make([]byte, 32*6), // One word too long
129-
},
130-
expectedError: "unexpected identifier data length: 192",
131-
},
132-
{
133-
name: "Invalid Address Padding",
134-
log: &types.Log{
135-
Address: params.InteropCrossL2InboxAddress,
136-
Topics: []common.Hash{
137-
common.BytesToHash(ExecutingMessageEventTopic[:]),
138-
common.BytesToHash([]byte("payloadHash")),
139-
},
140-
Data: func() []byte {
141-
data := make([]byte, 32*5)
142-
data[0] = 1 // Add non-zero byte in address padding
143-
return data
144-
}(),
145-
},
146-
expectedError: "invalid address padding",
147-
},
148-
{
149-
name: "Invalid Block Number Padding",
150-
log: &types.Log{
151-
Address: params.InteropCrossL2InboxAddress,
152-
Topics: []common.Hash{
153-
common.BytesToHash(ExecutingMessageEventTopic[:]),
154-
common.BytesToHash([]byte("payloadHash")),
155-
},
156-
Data: func() []byte {
157-
data := make([]byte, 32*5)
158-
data[32+23] = 1 // Add non-zero byte in block number padding
159-
return data
160-
}(),
161-
},
162-
expectedError: "invalid block number padding",
163-
},
164-
}
165-
166-
for _, tt := range tests {
167-
t.Run(tt.name, func(t *testing.T) {
168-
var msg Message
169-
err := msg.DecodeEvent(tt.log.Topics, tt.log.Data)
170-
if tt.expectedError != "" {
171-
require.Error(t, err)
172-
require.ErrorContains(t, err, tt.expectedError)
173-
} else {
174-
require.NoError(t, err)
175-
}
176-
})
177-
}
178-
}
179-
18024
func TestTxToInteropAccessList(t *testing.T) {
18125
t.Run("Tx has no access list", func(t *testing.T) {
18226
tx := types.NewTx(&types.DynamicFeeTx{})

0 commit comments

Comments
 (0)