-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathaa_transaction.go
More file actions
756 lines (634 loc) · 20.8 KB
/
aa_transaction.go
File metadata and controls
756 lines (634 loc) · 20.8 KB
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
package types
import (
"bytes"
"errors"
"io"
"math/big"
"github.com/holiman/uint256"
"github.com/erigontech/erigon/common"
"github.com/erigontech/erigon/execution/abi"
"github.com/erigontech/erigon/execution/chain"
"github.com/erigontech/erigon/execution/protocol/mdgas"
"github.com/erigontech/erigon/execution/protocol/params"
"github.com/erigontech/erigon/execution/rlp"
"github.com/erigontech/erigon/execution/types/accounts"
"github.com/erigontech/erigon/node/gointerfaces/typesproto"
)
const (
ExecutionStatusSuccess = uint64(0)
ExecutionStatusExecutionFailure = uint64(1)
ExecutionStatusPostOpFailure = uint64(2)
ExecutionStatusExecutionAndPostOpFailure = uint64(3)
)
const AA_GAS_PENALTY_PCT = 10
var AA_ENTRY_POINT = accounts.InternAddress(common.HexToAddress("0x0000000000000000000000000000000000007560"))
var AA_SENDER_CREATOR = accounts.InternAddress(common.HexToAddress("0x00000000000000000000000000000000ffff7560"))
type AccountAbstractionTransaction struct {
TransactionMisc
Nonce uint64
ChainID *uint256.Int
Tip *uint256.Int
FeeCap *uint256.Int
GasLimit uint64
AccessList AccessList
SenderAddress accounts.Address
SenderValidationData []byte
ExecutionData []byte
Paymaster *common.Address
PaymasterData []byte
Deployer *common.Address
DeployerData []byte
BuilderFee *uint256.Int
ValidationGasLimit uint64
PaymasterValidationGasLimit uint64
PostOpGasLimit uint64
Authorizations []Authorization
// RIP-7712 two-dimensional nonce (optional), 192 bits
NonceKey *uint256.Int
}
func (tx *AccountAbstractionTransaction) GetData() []byte {
return []byte{}
}
func (tx *AccountAbstractionTransaction) GetAccessList() AccessList {
return tx.AccessList
}
func (tx *AccountAbstractionTransaction) GetAuthorizations() []Authorization {
return tx.Authorizations
}
func (tx *AccountAbstractionTransaction) Protected() bool {
return true
}
func (tx *AccountAbstractionTransaction) Sender(signer Signer) (accounts.Address, error) {
return tx.SenderAddress, nil
}
func (tx *AccountAbstractionTransaction) cachedSender() (accounts.Address, bool) {
return tx.SenderAddress, true
}
func (tx *AccountAbstractionTransaction) GetSender() (accounts.Address, bool) {
return tx.SenderAddress, true
}
func (tx *AccountAbstractionTransaction) SetSender(address accounts.Address) {
}
func (tx *AccountAbstractionTransaction) IsContractDeploy() bool {
return false
}
func (tx *AccountAbstractionTransaction) Unwrap() Transaction {
return tx
}
func (tx *AccountAbstractionTransaction) GetChainID() *uint256.Int {
return tx.ChainID
}
func (tx *AccountAbstractionTransaction) GetNonce() uint64 {
return tx.Nonce
}
func (tx *AccountAbstractionTransaction) GetPrice() *uint256.Int {
return tx.Tip
}
func (tx *AccountAbstractionTransaction) GetEffectiveGasTip(baseFee *uint256.Int) uint256.Int {
return CalcEffectiveGasTip(baseFee, tx.GetTipCap, tx.GetFeeCap)
}
func (tx *AccountAbstractionTransaction) GetFeeCap() *uint256.Int {
return tx.FeeCap
}
func (tx *AccountAbstractionTransaction) GetGasLimit() uint64 {
return params.TxAAGas + tx.ValidationGasLimit + tx.PaymasterValidationGasLimit + tx.GasLimit + tx.PostOpGasLimit
}
func (tx *AccountAbstractionTransaction) GetTipCap() *uint256.Int {
return tx.Tip
}
func (tx *AccountAbstractionTransaction) GetBlobHashes() []common.Hash {
return []common.Hash{}
}
func (tx *AccountAbstractionTransaction) GetGas() uint64 {
return tx.GasLimit
}
func (tx *AccountAbstractionTransaction) GetBlobGas() uint64 {
return 0
}
func (tx *AccountAbstractionTransaction) GetValue() *uint256.Int {
return uint256.NewInt(0)
}
func (tx *AccountAbstractionTransaction) GetTo() *common.Address {
return nil
}
func (tx *AccountAbstractionTransaction) Type() byte {
return AccountAbstractionTxType
}
func (tx *AccountAbstractionTransaction) AsMessage(s Signer, baseFee *uint256.Int, rules *chain.Rules) (*Message, error) {
return &Message{
to: accounts.NilAddress,
gasPrice: *tx.FeeCap,
blobHashes: []common.Hash{},
}, nil
}
func (tx *AccountAbstractionTransaction) WithSignature(signer Signer, sig []byte) (Transaction, error) {
return tx, nil
}
func (tx *AccountAbstractionTransaction) Hash() common.Hash {
if hash := tx.hash.Load(); hash != nil {
return *hash
}
hash := prefixedRlpHash(AccountAbstractionTxType, []any{
tx.ChainID,
tx.NonceKey, tx.Nonce,
tx.SenderAddress, tx.SenderValidationData,
tx.Deployer, tx.DeployerData,
tx.Paymaster, tx.PaymasterData,
tx.ExecutionData,
tx.BuilderFee,
tx.Tip, tx.FeeCap,
tx.ValidationGasLimit, tx.PaymasterValidationGasLimit, tx.PostOpGasLimit,
tx.GasLimit,
tx.AccessList,
tx.Authorizations,
})
tx.hash.Store(&hash)
return hash
}
func (tx *AccountAbstractionTransaction) SigningHash(chainID *big.Int) common.Hash {
hash := prefixedRlpHash(AccountAbstractionTxType, []any{
chainID,
tx.NonceKey, tx.Nonce,
tx.SenderAddress, tx.SenderValidationData,
tx.Deployer, tx.DeployerData,
tx.Paymaster, tx.PaymasterData,
tx.ExecutionData,
tx.BuilderFee,
tx.Tip, tx.FeeCap,
tx.ValidationGasLimit, tx.PaymasterValidationGasLimit, tx.PostOpGasLimit,
tx.GasLimit,
tx.AccessList, // authorization data is not included for signing hash
})
return hash
}
func (tx *AccountAbstractionTransaction) RawSignatureValues() (*uint256.Int, *uint256.Int, *uint256.Int) {
return new(uint256.Int), new(uint256.Int), new(uint256.Int)
}
func (tx *AccountAbstractionTransaction) payloadSize() (payloadSize, accessListLen, authorizationsLen int) {
payloadSize += rlp.Uint256Len(*tx.ChainID)
payloadSize += rlp.Uint256Len(*tx.NonceKey)
payloadSize += rlp.U64Len(tx.Nonce)
payloadSize++
if !tx.SenderAddress.IsNil() {
payloadSize += 20
}
payloadSize += rlp.StringLen(tx.SenderValidationData)
payloadSize++
if tx.Deployer != nil {
payloadSize += 20
}
payloadSize += rlp.StringLen(tx.DeployerData)
payloadSize++
if tx.Paymaster != nil {
payloadSize += 20
}
payloadSize += rlp.StringLen(tx.PaymasterData)
payloadSize += rlp.StringLen(tx.ExecutionData)
payloadSize += rlp.Uint256Len(*tx.BuilderFee)
payloadSize += rlp.Uint256Len(*tx.Tip)
payloadSize += rlp.Uint256Len(*tx.FeeCap)
payloadSize += rlp.U64Len(tx.ValidationGasLimit)
payloadSize += rlp.U64Len(tx.PaymasterValidationGasLimit)
payloadSize += rlp.U64Len(tx.PostOpGasLimit)
payloadSize += rlp.U64Len(tx.GasLimit)
accessListLen = accessListSize(tx.AccessList)
payloadSize += rlp.ListPrefixLen(accessListLen) + accessListLen
authorizationsLen = authorizationsSize(tx.Authorizations)
payloadSize += rlp.ListPrefixLen(authorizationsLen) + authorizationsLen
return
}
func (tx *AccountAbstractionTransaction) EncodingSize() int {
payloadSize, _, _ := tx.payloadSize()
// Add envelope size and type size
return 1 + rlp.ListPrefixLen(payloadSize) + payloadSize
}
func (tx *AccountAbstractionTransaction) EncodeRLP(w io.Writer) error {
payloadSize, accessListLen, authorizationsLen := tx.payloadSize()
envelopSize := 1 + rlp.ListPrefixLen(payloadSize) + payloadSize
b := rlp.NewEncodingBuf()
defer b.Release()
// encode envelope size
if err := rlp.EncodeStringPrefix(envelopSize, w, b[:]); err != nil {
return err
}
// encode TxType
b[0] = AccountAbstractionTxType
if _, err := w.Write(b[:1]); err != nil {
return err
}
if err := tx.encodePayload(w, b[:], payloadSize, accessListLen, authorizationsLen); err != nil {
return err
}
return nil
}
func (tx *AccountAbstractionTransaction) encodePayload(w io.Writer, b []byte, payloadSize, accessListLen, authorizationsLen int) error {
// prefix
if err := rlp.EncodeListPrefix(payloadSize, w, b); err != nil {
return err
}
if err := rlp.EncodeUint256(*tx.ChainID, w, b); err != nil {
return err
}
if err := rlp.EncodeUint256(*tx.NonceKey, w, b); err != nil {
return err
}
if err := rlp.EncodeU64(tx.Nonce, w, b); err != nil {
return err
}
var senderAddress *common.Address
if !tx.SenderAddress.IsNil() {
senderValue := tx.SenderAddress.Value()
senderAddress = &senderValue
}
if err := EncodeOptionalAddress(senderAddress, w, b); err != nil {
return err
}
if err := rlp.EncodeString(tx.SenderValidationData, w, b); err != nil {
return err
}
if err := EncodeOptionalAddress(tx.Deployer, w, b); err != nil {
return err
}
if err := rlp.EncodeString(tx.DeployerData, w, b); err != nil {
return err
}
if err := EncodeOptionalAddress(tx.Paymaster, w, b); err != nil {
return err
}
if err := rlp.EncodeString(tx.PaymasterData, w, b); err != nil {
return err
}
if err := rlp.EncodeString(tx.ExecutionData, w, b); err != nil {
return err
}
if err := rlp.EncodeUint256(*tx.BuilderFee, w, b); err != nil {
return err
}
if err := rlp.EncodeUint256(*tx.Tip, w, b); err != nil {
return err
}
if err := rlp.EncodeUint256(*tx.FeeCap, w, b); err != nil {
return err
}
if err := rlp.EncodeU64(tx.ValidationGasLimit, w, b); err != nil {
return err
}
if err := rlp.EncodeU64(tx.PaymasterValidationGasLimit, w, b); err != nil {
return err
}
if err := rlp.EncodeU64(tx.PostOpGasLimit, w, b); err != nil {
return err
}
if err := rlp.EncodeU64(tx.GasLimit, w, b); err != nil {
return err
}
// prefix
if err := rlp.EncodeListPrefix(accessListLen, w, b); err != nil {
return err
}
// encode AccessList
if err := encodeAccessList(tx.AccessList, w, b); err != nil {
return err
}
// prefix
if err := rlp.EncodeListPrefix(authorizationsLen, w, b); err != nil {
return err
}
// encode Authorizations
if err := encodeAuthorizations(tx.Authorizations, w, b); err != nil {
return err
}
return nil
}
func (tx *AccountAbstractionTransaction) DecodeRLP(s *rlp.Stream) error {
_, err := s.List()
if err != nil {
return err
}
tx.ChainID = new(uint256.Int)
if err = s.ReadUint256(tx.ChainID); err != nil {
return err
}
tx.NonceKey = new(uint256.Int)
if err = s.ReadUint256(tx.NonceKey); err != nil {
return err
}
if tx.Nonce, err = s.Uint64(); err != nil {
return err
}
var senderAddress common.Address
if err = s.ReadBytes(senderAddress[:]); err != nil {
return err
}
tx.SenderAddress = accounts.InternAddress(senderAddress)
if tx.SenderValidationData, err = s.Bytes(); err != nil {
return err
}
if err = DecodeOptionalAddress(&tx.Deployer, s); err != nil {
return err
}
if tx.DeployerData, err = s.Bytes(); err != nil {
return err
}
if err = DecodeOptionalAddress(&tx.Paymaster, s); err != nil {
return err
}
if tx.PaymasterData, err = s.Bytes(); err != nil {
return err
}
if tx.ExecutionData, err = s.Bytes(); err != nil {
return err
}
tx.BuilderFee = new(uint256.Int)
if err = s.ReadUint256(tx.BuilderFee); err != nil {
return err
}
tx.Tip = new(uint256.Int)
if err = s.ReadUint256(tx.Tip); err != nil {
return err
}
tx.FeeCap = new(uint256.Int)
if err = s.ReadUint256(tx.FeeCap); err != nil {
return err
}
if tx.ValidationGasLimit, err = s.Uint64(); err != nil {
return err
}
if tx.PaymasterValidationGasLimit, err = s.Uint64(); err != nil {
return err
}
if tx.PostOpGasLimit, err = s.Uint64(); err != nil {
return err
}
if tx.GasLimit, err = s.Uint64(); err != nil {
return err
}
// decode AccessList
tx.AccessList = AccessList{}
if err = decodeAccessList(&tx.AccessList, s); err != nil {
return err
}
// decode authorizations
tx.Authorizations = make([]Authorization, 0)
if err = decodeAuthorizations(&tx.Authorizations, s); err != nil {
return err
}
return s.ListEnd()
}
func (tx *AccountAbstractionTransaction) MarshalBinary(w io.Writer) error {
payloadSize, accessListLen, authorizationsLen := tx.payloadSize()
b := rlp.NewEncodingBuf()
defer b.Release()
// encode TxType
b[0] = AccountAbstractionTxType
if _, err := w.Write(b[:1]); err != nil {
return err
}
if err := tx.encodePayload(w, b[:], payloadSize, accessListLen, authorizationsLen); err != nil {
return err
}
return nil
}
func (tx *AccountAbstractionTransaction) PreTransactionGasCost(rules *chain.Rules, hasEIP3860 bool) (uint64, error) {
// data should have tx.SenderValidationData, tx.DeployerData, tx.ExecutionData, tx.PaymasterData
data := make([]byte, 0, len(tx.SenderValidationData)+len(tx.DeployerData)+len(tx.ExecutionData)+len(tx.PaymasterData))
data = append(data, tx.SenderValidationData...)
data = append(data, tx.DeployerData...)
data = append(data, tx.ExecutionData...)
data = append(data, tx.PaymasterData...)
intrinsicGasResult, overflow := mdgas.IntrinsicGas(mdgas.IntrinsicGasCalcArgs{
Data: data,
AuthorizationsLen: uint64(len(tx.Authorizations)),
AccessListLen: uint64(len(tx.AccessList)),
StorageKeysLen: uint64(tx.AccessList.StorageKeys()),
IsEIP2: rules.IsHomestead,
IsEIP2028: rules.IsIstanbul,
IsEIP3860: hasEIP3860,
IsEIP7623: rules.IsPrague,
IsEIP7976: rules.IsAmsterdam,
IsEIP7981: rules.IsAmsterdam,
IsEIP8037: rules.IsAmsterdam,
IsAATxn: true,
})
if overflow {
return 0, errors.New("overflow")
}
return intrinsicGasResult.RegularGas, nil
}
func (tx *AccountAbstractionTransaction) DeployerFrame(rules *chain.Rules, hasEIP3860 bool) *Message {
intrinsicGas, _ := tx.PreTransactionGasCost(rules, hasEIP3860)
deployerGasLimit := tx.ValidationGasLimit - intrinsicGas
var to accounts.Address
if tx.Deployer == nil {
to = accounts.NilAddress
} else {
to = accounts.InternAddress(*tx.Deployer)
}
return &Message{
to: to,
from: AA_SENDER_CREATOR,
gasLimit: deployerGasLimit,
data: tx.DeployerData,
}
}
func (tx *AccountAbstractionTransaction) ExecutionFrame() *Message {
return &Message{
to: tx.SenderAddress,
from: AA_ENTRY_POINT,
gasLimit: tx.GasLimit,
data: tx.ExecutionData,
}
}
func (tx *AccountAbstractionTransaction) PaymasterPostOp(paymasterContext []byte, gasUsed uint64, executionSuccess bool) (*Message, error) {
postOpData, err := EncodePostOpFrame(paymasterContext, big.NewInt(int64(gasUsed)), executionSuccess)
if err != nil {
return nil, errors.New("unable to encode postPaymasterTransaction")
}
var to accounts.Address
if tx.Paymaster == nil {
to = accounts.NilAddress
} else {
to = accounts.InternAddress(*tx.Paymaster)
}
return &Message{
to: to,
from: AA_SENDER_CREATOR,
gasLimit: tx.PostOpGasLimit,
data: postOpData,
}, nil
}
func (tx *AccountAbstractionTransaction) PaymasterFrame(chainID *big.Int) (*Message, error) {
zeroAddress := common.Address{}
if tx.Paymaster == nil || bytes.Equal(zeroAddress[:], tx.Paymaster[:]) {
return nil, nil
}
signingHash := tx.SigningHash(chainID)
txAbiEncoding, err := tx.AbiEncode()
if err != nil {
return nil, err
}
validatePaymasterData, err := EncodeTxnForFrame("validatePaymasterTransaction", signingHash, txAbiEncoding)
if err != nil {
return nil, err
}
var to accounts.Address
if tx.Paymaster == nil {
to = accounts.NilAddress
} else {
to = accounts.InternAddress(*tx.Paymaster)
}
return &Message{
to: to,
from: AA_ENTRY_POINT,
gasLimit: tx.PaymasterValidationGasLimit,
data: validatePaymasterData,
}, nil
}
func (tx *AccountAbstractionTransaction) ValidationFrame(chainID *big.Int, deploymentGasUsed uint64, rules *chain.Rules, hasEIP3860 bool) (*Message, error) {
signingHash := tx.SigningHash(chainID)
txAbiEncoding, err := tx.AbiEncode()
if err != nil {
return nil, err
}
validateTransactionData, err := EncodeTxnForFrame("validateTransaction", signingHash, txAbiEncoding)
if err != nil {
return nil, err
}
intrinsicGas, _ := tx.PreTransactionGasCost(rules, hasEIP3860)
accountGasLimit := tx.ValidationGasLimit - intrinsicGas - deploymentGasUsed
return &Message{
to: tx.SenderAddress,
from: AA_ENTRY_POINT,
gasLimit: accountGasLimit,
data: validateTransactionData,
}, nil
}
func (tx *AccountAbstractionTransaction) GasPayer() accounts.Address {
if tx.Paymaster != nil && tx.Paymaster.Cmp(common.Address{}) != 0 {
return accounts.InternAddress(*tx.Paymaster)
}
return tx.SenderAddress
}
func (tx *AccountAbstractionTransaction) AbiEncode() ([]byte, error) {
abiType, _ := abi.NewType("tuple", "tuple", []abi.ArgumentMarshaling{ // internaltype does not matter
{Name: "sender", Type: "address"},
{Name: "nonceKey", Type: "uint256"},
{Name: "nonce", Type: "uint256"},
{Name: "validationGasLimit", Type: "uint256"},
{Name: "paymasterValidationGasLimit", Type: "uint256"},
{Name: "postOpGasLimit", Type: "uint256"},
{Name: "callGasLimit", Type: "uint256"},
{Name: "maxFeePerGas", Type: "uint256"},
{Name: "maxPriorityFeePerGas", Type: "uint256"},
{Name: "builderFee", Type: "uint256"},
{Name: "senderValidationData", Type: "bytes"},
{Name: "paymaster", Type: "address"},
{Name: "paymasterData", Type: "bytes"},
{Name: "deployer", Type: "address"},
{Name: "deployerData", Type: "bytes"},
{Name: "executionData", Type: "bytes"}, // TODO: discuss how to pass authorization data to EVM
})
args := abi.Arguments{
{Type: abiType, Name: "param_one"}, // name does not matter
}
paymaster := tx.Paymaster
if paymaster == nil {
paymaster = &common.Address{}
}
deployer := tx.Deployer
if deployer == nil {
deployer = &common.Address{}
}
record := &ABIAccountAbstractTxn{
Sender: tx.SenderAddress.Value(),
NonceKey: tx.NonceKey.ToBig(),
Nonce: big.NewInt(int64(tx.Nonce)),
ValidationGasLimit: big.NewInt(int64(tx.ValidationGasLimit)),
PaymasterValidationGasLimit: big.NewInt(int64(tx.PaymasterValidationGasLimit)),
PostOpGasLimit: big.NewInt(int64(tx.PostOpGasLimit)),
CallGasLimit: big.NewInt(int64(tx.GasLimit)),
MaxFeePerGas: tx.FeeCap.ToBig(),
MaxPriorityFeePerGas: tx.Tip.ToBig(),
BuilderFee: tx.BuilderFee.ToBig(),
SenderValidationData: tx.SenderValidationData,
Paymaster: *paymaster,
PaymasterData: tx.PaymasterData,
Deployer: *deployer,
DeployerData: tx.DeployerData,
ExecutionData: tx.ExecutionData,
}
packed, err := args.Pack(&record)
return packed, err
}
// ABIAccountAbstractTxn an equivalent of a solidity struct only used to encode the 'transaction' parameter
type ABIAccountAbstractTxn struct {
Sender common.Address
NonceKey *big.Int
Nonce *big.Int
ValidationGasLimit *big.Int
PaymasterValidationGasLimit *big.Int
PostOpGasLimit *big.Int
CallGasLimit *big.Int
MaxFeePerGas *big.Int
MaxPriorityFeePerGas *big.Int
BuilderFee *big.Int
Paymaster common.Address
PaymasterData []byte
Deployer common.Address
DeployerData []byte
ExecutionData []byte
SenderValidationData []byte
}
func FromProto(tx *typesproto.AccountAbstractionTransaction) *AccountAbstractionTransaction {
if tx == nil {
return nil
}
senderAddress := common.BytesToAddress(tx.SenderAddress)
var paymasterAddress, deployerAddress *common.Address
if len(tx.Paymaster) != 0 {
address := common.BytesToAddress(tx.Paymaster)
paymasterAddress = &address
}
if len(tx.Deployer) != 0 {
address := common.BytesToAddress(tx.Deployer)
deployerAddress = &address
}
return &AccountAbstractionTransaction{
Nonce: tx.Nonce,
ChainID: uint256.NewInt(0).SetBytes(tx.ChainId),
Tip: uint256.NewInt(0).SetBytes(tx.Tip),
FeeCap: uint256.NewInt(0).SetBytes(tx.FeeCap),
GasLimit: tx.Gas,
SenderAddress: accounts.InternAddress(senderAddress),
SenderValidationData: tx.SenderValidationData,
ExecutionData: tx.ExecutionData,
Paymaster: paymasterAddress,
PaymasterData: tx.PaymasterData,
Deployer: deployerAddress,
DeployerData: tx.DeployerData,
BuilderFee: uint256.NewInt(0).SetBytes(tx.BuilderFee),
ValidationGasLimit: tx.ValidationGasLimit,
PaymasterValidationGasLimit: tx.PaymasterValidationGasLimit,
PostOpGasLimit: tx.PostOpGasLimit,
NonceKey: uint256.NewInt(0).SetBytes(tx.NonceKey),
Authorizations: convertProtoAuthorizations(tx.Authorizations),
}
}
func convertProtoAuthorizations(auths []*typesproto.Authorization) []Authorization {
goAuths := make([]Authorization, len(auths))
var r, s, chainID uint256.Int
for i, auth := range auths {
r.SetBytes(auth.R) // Convert bytes to uint256
s.SetBytes(auth.S)
chainID.SetUint64(auth.ChainId)
goAuths[i] = Authorization{
ChainID: chainID,
Address: common.BytesToAddress(auth.Address),
Nonce: auth.Nonce,
YParity: uint8(auth.YParity),
R: r,
S: s,
}
}
return goAuths
}