-
Notifications
You must be signed in to change notification settings - Fork 58
/
executionpayload_ssz.go
298 lines (237 loc) · 6.65 KB
/
executionpayload_ssz.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
// Code generated by fastssz. DO NOT EDIT.
// Hash: 4ecbe3dbe60a2948a3e56a15e89a4f0b7ac841eab13d9065b3181159630b08d5
// Version: 0.1.3
package bellatrix
import (
ssz "github.com/ferranbt/fastssz"
)
// MarshalSSZ ssz marshals the ExecutionPayload object
func (e *ExecutionPayload) MarshalSSZ() ([]byte, error) {
return ssz.MarshalSSZ(e)
}
// MarshalSSZTo ssz marshals the ExecutionPayload object to a target array
func (e *ExecutionPayload) MarshalSSZTo(buf []byte) (dst []byte, err error) {
dst = buf
offset := int(508)
// Field (0) 'ParentHash'
dst = append(dst, e.ParentHash[:]...)
// Field (1) 'FeeRecipient'
dst = append(dst, e.FeeRecipient[:]...)
// Field (2) 'StateRoot'
dst = append(dst, e.StateRoot[:]...)
// Field (3) 'ReceiptsRoot'
dst = append(dst, e.ReceiptsRoot[:]...)
// Field (4) 'LogsBloom'
dst = append(dst, e.LogsBloom[:]...)
// Field (5) 'PrevRandao'
dst = append(dst, e.PrevRandao[:]...)
// Field (6) 'BlockNumber'
dst = ssz.MarshalUint64(dst, e.BlockNumber)
// Field (7) 'GasLimit'
dst = ssz.MarshalUint64(dst, e.GasLimit)
// Field (8) 'GasUsed'
dst = ssz.MarshalUint64(dst, e.GasUsed)
// Field (9) 'Timestamp'
dst = ssz.MarshalUint64(dst, e.Timestamp)
// Offset (10) 'ExtraData'
dst = ssz.WriteOffset(dst, offset)
offset += len(e.ExtraData)
// Field (11) 'BaseFeePerGas'
dst = append(dst, e.BaseFeePerGas[:]...)
// Field (12) 'BlockHash'
dst = append(dst, e.BlockHash[:]...)
// Offset (13) 'Transactions'
dst = ssz.WriteOffset(dst, offset)
for ii := 0; ii < len(e.Transactions); ii++ {
offset += 4
offset += len(e.Transactions[ii])
}
// Field (10) 'ExtraData'
if size := len(e.ExtraData); size > 32 {
err = ssz.ErrBytesLengthFn("ExecutionPayload.ExtraData", size, 32)
return
}
dst = append(dst, e.ExtraData...)
// Field (13) 'Transactions'
if size := len(e.Transactions); size > 1048576 {
err = ssz.ErrListTooBigFn("ExecutionPayload.Transactions", size, 1048576)
return
}
{
offset = 4 * len(e.Transactions)
for ii := 0; ii < len(e.Transactions); ii++ {
dst = ssz.WriteOffset(dst, offset)
offset += len(e.Transactions[ii])
}
}
for ii := 0; ii < len(e.Transactions); ii++ {
if size := len(e.Transactions[ii]); size > 1073741824 {
err = ssz.ErrBytesLengthFn("ExecutionPayload.Transactions[ii]", size, 1073741824)
return
}
dst = append(dst, e.Transactions[ii]...)
}
return
}
// UnmarshalSSZ ssz unmarshals the ExecutionPayload object
func (e *ExecutionPayload) UnmarshalSSZ(buf []byte) error {
var err error
size := uint64(len(buf))
if size < 508 {
return ssz.ErrSize
}
tail := buf
var o10, o13 uint64
// Field (0) 'ParentHash'
copy(e.ParentHash[:], buf[0:32])
// Field (1) 'FeeRecipient'
copy(e.FeeRecipient[:], buf[32:52])
// Field (2) 'StateRoot'
copy(e.StateRoot[:], buf[52:84])
// Field (3) 'ReceiptsRoot'
copy(e.ReceiptsRoot[:], buf[84:116])
// Field (4) 'LogsBloom'
copy(e.LogsBloom[:], buf[116:372])
// Field (5) 'PrevRandao'
copy(e.PrevRandao[:], buf[372:404])
// Field (6) 'BlockNumber'
e.BlockNumber = ssz.UnmarshallUint64(buf[404:412])
// Field (7) 'GasLimit'
e.GasLimit = ssz.UnmarshallUint64(buf[412:420])
// Field (8) 'GasUsed'
e.GasUsed = ssz.UnmarshallUint64(buf[420:428])
// Field (9) 'Timestamp'
e.Timestamp = ssz.UnmarshallUint64(buf[428:436])
// Offset (10) 'ExtraData'
if o10 = ssz.ReadOffset(buf[436:440]); o10 > size {
return ssz.ErrOffset
}
if o10 < 508 {
return ssz.ErrInvalidVariableOffset
}
// Field (11) 'BaseFeePerGas'
copy(e.BaseFeePerGas[:], buf[440:472])
// Field (12) 'BlockHash'
copy(e.BlockHash[:], buf[472:504])
// Offset (13) 'Transactions'
if o13 = ssz.ReadOffset(buf[504:508]); o13 > size || o10 > o13 {
return ssz.ErrOffset
}
// Field (10) 'ExtraData'
{
buf = tail[o10:o13]
if len(buf) > 32 {
return ssz.ErrBytesLength
}
if cap(e.ExtraData) == 0 {
e.ExtraData = make([]byte, 0, len(buf))
}
e.ExtraData = append(e.ExtraData, buf...)
}
// Field (13) 'Transactions'
{
buf = tail[o13:]
num, err := ssz.DecodeDynamicLength(buf, 1048576)
if err != nil {
return err
}
e.Transactions = make([]Transaction, num)
err = ssz.UnmarshalDynamic(buf, num, func(indx int, buf []byte) (err error) {
if len(buf) > 1073741824 {
return ssz.ErrBytesLength
}
if cap(e.Transactions[indx]) == 0 {
e.Transactions[indx] = make([]byte, 0, len(buf))
}
e.Transactions[indx] = append(e.Transactions[indx], buf...)
return nil
})
if err != nil {
return err
}
}
return err
}
// SizeSSZ returns the ssz encoded size in bytes for the ExecutionPayload object
func (e *ExecutionPayload) SizeSSZ() (size int) {
size = 508
// Field (10) 'ExtraData'
size += len(e.ExtraData)
// Field (13) 'Transactions'
for ii := 0; ii < len(e.Transactions); ii++ {
size += 4
size += len(e.Transactions[ii])
}
return
}
// HashTreeRoot ssz hashes the ExecutionPayload object
func (e *ExecutionPayload) HashTreeRoot() ([32]byte, error) {
return ssz.HashWithDefaultHasher(e)
}
// HashTreeRootWith ssz hashes the ExecutionPayload object with a hasher
func (e *ExecutionPayload) HashTreeRootWith(hh ssz.HashWalker) (err error) {
indx := hh.Index()
// Field (0) 'ParentHash'
hh.PutBytes(e.ParentHash[:])
// Field (1) 'FeeRecipient'
hh.PutBytes(e.FeeRecipient[:])
// Field (2) 'StateRoot'
hh.PutBytes(e.StateRoot[:])
// Field (3) 'ReceiptsRoot'
hh.PutBytes(e.ReceiptsRoot[:])
// Field (4) 'LogsBloom'
hh.PutBytes(e.LogsBloom[:])
// Field (5) 'PrevRandao'
hh.PutBytes(e.PrevRandao[:])
// Field (6) 'BlockNumber'
hh.PutUint64(e.BlockNumber)
// Field (7) 'GasLimit'
hh.PutUint64(e.GasLimit)
// Field (8) 'GasUsed'
hh.PutUint64(e.GasUsed)
// Field (9) 'Timestamp'
hh.PutUint64(e.Timestamp)
// Field (10) 'ExtraData'
{
elemIndx := hh.Index()
byteLen := uint64(len(e.ExtraData))
if byteLen > 32 {
err = ssz.ErrIncorrectListSize
return
}
hh.Append(e.ExtraData)
hh.MerkleizeWithMixin(elemIndx, byteLen, (32+31)/32)
}
// Field (11) 'BaseFeePerGas'
hh.PutBytes(e.BaseFeePerGas[:])
// Field (12) 'BlockHash'
hh.PutBytes(e.BlockHash[:])
// Field (13) 'Transactions'
{
subIndx := hh.Index()
num := uint64(len(e.Transactions))
if num > 1048576 {
err = ssz.ErrIncorrectListSize
return
}
for _, elem := range e.Transactions {
{
elemIndx := hh.Index()
byteLen := uint64(len(elem))
if byteLen > 1073741824 {
err = ssz.ErrIncorrectListSize
return
}
hh.AppendBytes32(elem)
hh.MerkleizeWithMixin(elemIndx, byteLen, (1073741824+31)/32)
}
}
hh.MerkleizeWithMixin(subIndx, num, 1048576)
}
hh.Merkleize(indx)
return
}
// GetTree ssz hashes the ExecutionPayload object
func (e *ExecutionPayload) GetTree() (*ssz.Node, error) {
return ssz.ProofTree(e)
}