From 28a79ec98deac6791d14407896d997eb44d9ccf1 Mon Sep 17 00:00:00 2001 From: Alex Forshtat Date: Mon, 27 May 2024 20:33:09 +0200 Subject: [PATCH] Fix issue: charging 'from' address (EntryPoint) for inner frames gas --- core/state_transition.go | 16 ++++++++++++++-- core/types/tx_rip7560.go | 14 ++++---------- internal/ethapi/transaction_args.go | 4 ++-- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/core/state_transition.go b/core/state_transition.go index 70b642e747..9391c28557 100644 --- a/core/state_transition.go +++ b/core/state_transition.go @@ -68,7 +68,10 @@ func (result *ExecutionResult) Revert() []byte { } // IntrinsicGas computes the 'intrinsic gas' for a message with the given data. -func IntrinsicGas(data []byte, accessList types.AccessList, isContractCreation bool, isHomestead, isEIP2028, isEIP3860 bool) (uint64, error) { +func IntrinsicGas(data []byte, accessList types.AccessList, isContractCreation bool, isHomestead, isEIP2028, isEIP3860 bool, isRIP7560InnerFrame ...bool) (uint64, error) { + if isRIP7560InnerFrame != nil && len(isRIP7560InnerFrame) > 0 && isRIP7560InnerFrame[0] { + return 0, nil + } // Set the starting gas for the raw transaction var gas uint64 if isContractCreation && isHomestead { @@ -358,6 +361,15 @@ func (st *StateTransition) preCheck() error { } } } + + // no need to "buy gus" for individual frames + // there is a single shared gas pre-charge + if st.rip7560Frame { + st.gasRemaining += st.msg.GasLimit + st.initialGas = st.msg.GasLimit + return nil + } + return st.buyGas() } @@ -395,7 +407,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) { ) // Check clauses 4-5, subtract intrinsic gas if everything is correct - gas, err := IntrinsicGas(msg.Data, msg.AccessList, contractCreation, rules.IsHomestead, rules.IsIstanbul, rules.IsShanghai) + gas, err := IntrinsicGas(msg.Data, msg.AccessList, contractCreation, rules.IsHomestead, rules.IsIstanbul, rules.IsShanghai, msg.IsRip7560Frame) if err != nil { return nil, err } diff --git a/core/types/tx_rip7560.go b/core/types/tx_rip7560.go index 335b58683d..47019c750b 100644 --- a/core/types/tx_rip7560.go +++ b/core/types/tx_rip7560.go @@ -24,11 +24,8 @@ import ( "math/big" ) -const ScaTransactionSubtype = 0x01 - // Rip7560AccountAbstractionTx represents an RIP-7560 transaction. type Rip7560AccountAbstractionTx struct { - Subtype byte // overlapping fields ChainID *big.Int GasTipCap *big.Int // a.k.a. maxPriorityFeePerGas @@ -56,10 +53,9 @@ type Rip7560AccountAbstractionTx struct { // copy creates a deep copy of the transaction data and initializes all fields. func (tx *Rip7560AccountAbstractionTx) copy() TxData { cpy := &Rip7560AccountAbstractionTx{ - Subtype: tx.Subtype, - To: copyAddressPtr(tx.To), - Data: common.CopyBytes(tx.Data), - Gas: tx.Gas, + To: copyAddressPtr(tx.To), + Data: common.CopyBytes(tx.Data), + Gas: tx.Gas, // These are copied below. AccessList: make(AccessList, len(tx.AccessList)), Value: new(big.Int), @@ -128,14 +124,12 @@ func (tx *Rip7560AccountAbstractionTx) setSignatureValues(chainID, v, r, s *big. // encode the subtype byte and the payload-bearing bytes of the RIP-7560 transaction func (tx *Rip7560AccountAbstractionTx) encode(b *bytes.Buffer) error { - b.WriteByte(ScaTransactionSubtype) return rlp.Encode(b, tx) } // decode the payload-bearing bytes of the encoded RIP-7560 transaction payload func (tx *Rip7560AccountAbstractionTx) decode(input []byte) error { - tx.Subtype = ScaTransactionSubtype - return rlp.DecodeBytes(input[1:], tx) + return rlp.DecodeBytes(input, tx) } // Rip7560Transaction an equivalent of a solidity struct only used to encode the 'transaction' parameter diff --git a/internal/ethapi/transaction_args.go b/internal/ethapi/transaction_args.go index 323dcc1a50..ed7dfcbaf6 100644 --- a/internal/ethapi/transaction_args.go +++ b/internal/ethapi/transaction_args.go @@ -76,7 +76,6 @@ type TransactionArgs struct { blobSidecarAllowed bool // Introduced by RIP-7560 Transaction - Subtype *hexutil.Uint64 Sender *common.Address `json:"sender"` Signature *hexutil.Bytes PaymasterData *hexutil.Bytes `json:"paymasterData"` @@ -84,6 +83,7 @@ type TransactionArgs struct { BuilderFee *hexutil.Big ValidationGas *hexutil.Uint64 PaymasterGas *hexutil.Uint64 + PostOpGas *hexutil.Uint64 } // from retrieves the transaction sender address. @@ -488,7 +488,6 @@ func (args *TransactionArgs) ToTransaction() *types.Transaction { al = *args.AccessList } aatx := types.Rip7560AccountAbstractionTx{ - Subtype: byte(*args.Subtype), To: &common.Address{}, ChainID: (*big.Int)(args.ChainID), Gas: uint64(*args.Gas), @@ -505,6 +504,7 @@ func (args *TransactionArgs) ToTransaction() *types.Transaction { BuilderFee: (*big.Int)(args.BuilderFee), ValidationGas: uint64(*args.ValidationGas), PaymasterGas: uint64(*args.PaymasterGas), + PostOpGas: uint64(*args.PostOpGas), } data = &aatx hash := types.NewTx(data).Hash()