Fix issue: charging 'from' address (EntryPoint) for inner frames gas

This commit is contained in:
Alex Forshtat 2024-05-27 20:33:09 +02:00 committed by Dror Tirosh
parent c6fc74b5f8
commit 28a79ec98d
3 changed files with 20 additions and 14 deletions

View file

@ -68,7 +68,10 @@ func (result *ExecutionResult) Revert() []byte {
} }
// IntrinsicGas computes the 'intrinsic gas' for a message with the given data. // 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 // Set the starting gas for the raw transaction
var gas uint64 var gas uint64
if isContractCreation && isHomestead { 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() return st.buyGas()
} }
@ -395,7 +407,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
) )
// Check clauses 4-5, subtract intrinsic gas if everything is correct // 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 { if err != nil {
return nil, err return nil, err
} }

View file

@ -24,11 +24,8 @@ import (
"math/big" "math/big"
) )
const ScaTransactionSubtype = 0x01
// Rip7560AccountAbstractionTx represents an RIP-7560 transaction. // Rip7560AccountAbstractionTx represents an RIP-7560 transaction.
type Rip7560AccountAbstractionTx struct { type Rip7560AccountAbstractionTx struct {
Subtype byte
// overlapping fields // overlapping fields
ChainID *big.Int ChainID *big.Int
GasTipCap *big.Int // a.k.a. maxPriorityFeePerGas 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. // copy creates a deep copy of the transaction data and initializes all fields.
func (tx *Rip7560AccountAbstractionTx) copy() TxData { func (tx *Rip7560AccountAbstractionTx) copy() TxData {
cpy := &Rip7560AccountAbstractionTx{ cpy := &Rip7560AccountAbstractionTx{
Subtype: tx.Subtype, To: copyAddressPtr(tx.To),
To: copyAddressPtr(tx.To), Data: common.CopyBytes(tx.Data),
Data: common.CopyBytes(tx.Data), Gas: tx.Gas,
Gas: tx.Gas,
// These are copied below. // These are copied below.
AccessList: make(AccessList, len(tx.AccessList)), AccessList: make(AccessList, len(tx.AccessList)),
Value: new(big.Int), 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 // encode the subtype byte and the payload-bearing bytes of the RIP-7560 transaction
func (tx *Rip7560AccountAbstractionTx) encode(b *bytes.Buffer) error { func (tx *Rip7560AccountAbstractionTx) encode(b *bytes.Buffer) error {
b.WriteByte(ScaTransactionSubtype)
return rlp.Encode(b, tx) return rlp.Encode(b, tx)
} }
// decode the payload-bearing bytes of the encoded RIP-7560 transaction payload // decode the payload-bearing bytes of the encoded RIP-7560 transaction payload
func (tx *Rip7560AccountAbstractionTx) decode(input []byte) error { func (tx *Rip7560AccountAbstractionTx) decode(input []byte) error {
tx.Subtype = ScaTransactionSubtype return rlp.DecodeBytes(input, tx)
return rlp.DecodeBytes(input[1:], tx)
} }
// Rip7560Transaction an equivalent of a solidity struct only used to encode the 'transaction' parameter // Rip7560Transaction an equivalent of a solidity struct only used to encode the 'transaction' parameter

View file

@ -76,7 +76,6 @@ type TransactionArgs struct {
blobSidecarAllowed bool blobSidecarAllowed bool
// Introduced by RIP-7560 Transaction // Introduced by RIP-7560 Transaction
Subtype *hexutil.Uint64
Sender *common.Address `json:"sender"` Sender *common.Address `json:"sender"`
Signature *hexutil.Bytes Signature *hexutil.Bytes
PaymasterData *hexutil.Bytes `json:"paymasterData"` PaymasterData *hexutil.Bytes `json:"paymasterData"`
@ -84,6 +83,7 @@ type TransactionArgs struct {
BuilderFee *hexutil.Big BuilderFee *hexutil.Big
ValidationGas *hexutil.Uint64 ValidationGas *hexutil.Uint64
PaymasterGas *hexutil.Uint64 PaymasterGas *hexutil.Uint64
PostOpGas *hexutil.Uint64
} }
// from retrieves the transaction sender address. // from retrieves the transaction sender address.
@ -488,7 +488,6 @@ func (args *TransactionArgs) ToTransaction() *types.Transaction {
al = *args.AccessList al = *args.AccessList
} }
aatx := types.Rip7560AccountAbstractionTx{ aatx := types.Rip7560AccountAbstractionTx{
Subtype: byte(*args.Subtype),
To: &common.Address{}, To: &common.Address{},
ChainID: (*big.Int)(args.ChainID), ChainID: (*big.Int)(args.ChainID),
Gas: uint64(*args.Gas), Gas: uint64(*args.Gas),
@ -505,6 +504,7 @@ func (args *TransactionArgs) ToTransaction() *types.Transaction {
BuilderFee: (*big.Int)(args.BuilderFee), BuilderFee: (*big.Int)(args.BuilderFee),
ValidationGas: uint64(*args.ValidationGas), ValidationGas: uint64(*args.ValidationGas),
PaymasterGas: uint64(*args.PaymasterGas), PaymasterGas: uint64(*args.PaymasterGas),
PostOpGas: uint64(*args.PostOpGas),
} }
data = &aatx data = &aatx
hash := types.NewTx(data).Hash() hash := types.NewTx(data).Hash()