Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AA-523: Rename and reorder fields to match the spec changes #52

Open
wants to merge 1 commit into
base: RIP-7560-revision-3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/state_processor_rip7560.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ func applyPaymasterValidationFrame(st *stateTransition, epc *EntryPointCall, tx
if err != nil {
return nil, 0, 0, 0, wrapError(err)
}
if len(apd.Context) > 0 && aatx.PostOpGas == 0 {
if len(apd.Context) > 0 && aatx.PostOpGasLimit == 0 {
return nil, 0, 0, 0, wrapError(
fmt.Errorf(
"paymaster returned a context of size %d but the paymasterPostOpGasLimit is 0",
Expand All @@ -613,7 +613,7 @@ func applyPaymasterValidationFrame(st *stateTransition, epc *EntryPointCall, tx
func applyPaymasterPostOpFrame(st *stateTransition, aatx *types.Rip7560AccountAbstractionTx, vpr *ValidationPhaseResult, success bool, gasUsed uint64) *ExecutionResult {
var paymasterPostOpResult *ExecutionResult
paymasterPostOpMsg := preparePostOpMessage(vpr, success, gasUsed)
paymasterPostOpResult = CallFrame(st, &AA_ENTRY_POINT, aatx.Paymaster, paymasterPostOpMsg, aatx.PostOpGas)
paymasterPostOpResult = CallFrame(st, &AA_ENTRY_POINT, aatx.Paymaster, paymasterPostOpMsg, aatx.PostOpGasLimit)
return paymasterPostOpResult
}

Expand Down Expand Up @@ -685,7 +685,7 @@ func ApplyRip7560ExecutionPhase(
}
executionStatus = ExecutionStatusPostOpFailure
}
postOpGasPenalty := (aatx.PostOpGas - postOpGasUsed) * AA_GAS_PENALTY_PCT / 100
postOpGasPenalty := (aatx.PostOpGasLimit - postOpGasUsed) * AA_GAS_PENALTY_PCT / 100
postOpGasUsed += postOpGasPenalty
gasUsed += postOpGasUsed
}
Expand Down
4 changes: 2 additions & 2 deletions core/types/transaction_signing_rip7560.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ func (s rip7560Signer) Hash(tx *Transaction) common.Hash {
tx.GasFeeCap(),
aatx.ValidationGasLimit,
aatx.PaymasterValidationGasLimit,
aatx.PostOpGas,
aatx.PostOpGasLimit,
tx.Gas(),
tx.AccessList(),

// no AuthorizationData here - this is hashing "for signing"
// no SenderValidationData here - this is hashing "for signing"
})
}
79 changes: 41 additions & 38 deletions core/types/tx_rip7560.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,37 @@ package types
import (
"bytes"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"math/big"
)

// Rip7560AccountAbstractionTx represents an RIP-7560 transaction.
type Rip7560AccountAbstractionTx struct {
// overlapping fields
ChainID *big.Int
Nonce uint64
GasTipCap *big.Int // a.k.a. maxPriorityFeePerGas
GasFeeCap *big.Int // a.k.a. maxFeePerGas
Gas uint64
AccessList AccessList

// extra fields
ChainID *big.Int
// RIP-7712 two-dimensional nonce
NonceKey *big.Int
Nonce uint64
Sender *common.Address
AuthorizationData []byte
ExecutionData []byte
SenderValidationData []byte
Paymaster *common.Address `rlp:"nil"`
PaymasterData []byte
Deployer *common.Address `rlp:"nil"`
DeployerData []byte
ExecutionData []byte
BuilderFee *big.Int
GasTipCap *big.Int // a.k.a. maxPriorityFeePerGas
GasFeeCap *big.Int // a.k.a. maxFeePerGas
ValidationGasLimit uint64
PaymasterValidationGasLimit uint64
PostOpGas uint64

// RIP-7712 two-dimensional nonce (optional), 192 bits
NonceKey *big.Int
PostOpGasLimit uint64
Gas uint64
AccessList AccessList
AuthList []SetCodeAuthorization
}

// copy creates a deep copy of the transaction data and initializes all fields.
Expand All @@ -69,15 +68,15 @@ func (tx *Rip7560AccountAbstractionTx) copy() TxData {
GasFeeCap: new(big.Int),

Sender: copyAddressPtr(tx.Sender),
AuthorizationData: common.CopyBytes(tx.AuthorizationData),
SenderValidationData: common.CopyBytes(tx.SenderValidationData),
Paymaster: copyAddressPtr(tx.Paymaster),
PaymasterData: common.CopyBytes(tx.PaymasterData),
Deployer: copyAddressPtr(tx.Deployer),
DeployerData: common.CopyBytes(tx.DeployerData),
BuilderFee: new(big.Int),
ValidationGasLimit: tx.ValidationGasLimit,
PaymasterValidationGasLimit: tx.PaymasterValidationGasLimit,
PostOpGas: tx.PostOpGas,
PostOpGasLimit: tx.PostOpGasLimit,
}
copy(cpy.AccessList, tx.AccessList)
if tx.ChainID != nil {
Expand Down Expand Up @@ -152,7 +151,7 @@ func (tx *Rip7560AccountAbstractionTx) PreTransactionGasCost() (uint64, error) {

func (tx *Rip7560AccountAbstractionTx) callDataGasCost() (uint64, error) {
return SumGas(
callDataCost(tx.AuthorizationData),
callDataCost(tx.SenderValidationData),
callDataCost(tx.DeployerData),
callDataCost(tx.ExecutionData),
callDataCost(tx.PaymasterData),
Expand All @@ -177,7 +176,7 @@ func (tx *Rip7560AccountAbstractionTx) eip7702CodeInsertionsGasCost() uint64 {
func (tx *Rip7560AccountAbstractionTx) TotalGasLimit() (uint64, error) {
return SumGas(
params.Rip7560TxGas,
tx.Gas, tx.ValidationGasLimit, tx.PaymasterValidationGasLimit, tx.PostOpGas,
tx.Gas, tx.ValidationGasLimit, tx.PaymasterValidationGasLimit, tx.PostOpGasLimit,
)
}

Expand Down Expand Up @@ -230,41 +229,43 @@ func (tx *Rip7560AccountAbstractionTx) decode(input []byte) error {
// Rip7560Transaction an equivalent of a solidity struct only used to encode the 'transaction' parameter
type Rip7560Transaction struct {
Sender common.Address
Paymaster common.Address
Deployer common.Address
NonceKey *big.Int
Nonce *big.Int
BuilderFee *big.Int
MaxFeePerGas *big.Int
MaxPriorityFeePerGas *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
SenderValidationData []byte
PaymasterData []byte
Deployer common.Address
DeployerData []byte
ExecutionData []byte
AuthorizationData []byte
AuthorizationList []common.Address
AuthorizationListStatus []bool
}

func (tx *Rip7560AccountAbstractionTx) AbiEncode() ([]byte, error) {
structThing, _ := abi.NewType("tuple", "struct thing", []abi.ArgumentMarshaling{
{Name: "sender", Type: "address"},
{Name: "paymaster", Type: "address"},
{Name: "deployer", Type: "address"},
{Name: "nonceKey", Type: "uint256"},
{Name: "nonce", Type: "uint256"},
{Name: "builderFee", Type: "uint256"},
{Name: "maxFeePerGas", Type: "uint256"},
{Name: "maxPriorityFeePerGas", 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: "paymaster", Type: "address"},
{Name: "senderData", Type: "bytes"},
{Name: "paymasterData", Type: "bytes"},
{Name: "deployer", Type: "address"},
{Name: "deployerData", Type: "bytes"},
{Name: "executionData", Type: "bytes"},
{Name: "authorizationData", Type: "bytes"},
})

args := abi.Arguments{
Expand All @@ -282,21 +283,23 @@ func (tx *Rip7560AccountAbstractionTx) AbiEncode() ([]byte, error) {

record := &Rip7560Transaction{
Sender: *tx.Sender,
Paymaster: *paymaster,
Deployer: *deployer,
NonceKey: tx.NonceKey,
Nonce: big.NewInt(int64(tx.Nonce)),
BuilderFee: tx.BuilderFee,
MaxFeePerGas: tx.GasFeeCap,
MaxPriorityFeePerGas: tx.GasTipCap,
ValidationGasLimit: big.NewInt(int64(tx.ValidationGasLimit)),
PaymasterValidationGasLimit: big.NewInt(int64(tx.PaymasterValidationGasLimit)),
PostOpGasLimit: big.NewInt(int64(tx.PostOpGas)),
PostOpGasLimit: big.NewInt(int64(tx.PostOpGasLimit)),
CallGasLimit: big.NewInt(int64(tx.Gas)),
MaxFeePerGas: tx.GasFeeCap,
MaxPriorityFeePerGas: tx.GasTipCap,
BuilderFee: tx.BuilderFee,
Paymaster: *paymaster,
SenderValidationData: tx.SenderValidationData,
PaymasterData: tx.PaymasterData,
Deployer: *deployer,
DeployerData: tx.DeployerData,
ExecutionData: tx.ExecutionData,
AuthorizationData: tx.AuthorizationData,
AuthorizationList: make([]common.Address, 0),
AuthorizationListStatus: make([]bool, 0),
}
packed, err := args.Pack(&record)
return packed, err
Expand Down
14 changes: 7 additions & 7 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ func RPCMarshalBlock(block *types.Block, inclTx bool, fullTx bool, config *param
type RPCTransaction struct {
BlockHash *common.Hash `json:"blockHash"`
BlockNumber *hexutil.Big `json:"blockNumber"`
From common.Address `json:"from,omitempty"`
From common.Address `json:"from,omitempty"`
Gas hexutil.Uint64 `json:"gas"`
GasPrice *hexutil.Big `json:"gasPrice"`
GasFeeCap *hexutil.Big `json:"maxFeePerGas,omitempty"`
Expand All @@ -948,17 +948,17 @@ type RPCTransaction struct {
Hash common.Hash `json:"hash"`
Input hexutil.Bytes `json:"input"`
Nonce hexutil.Uint64 `json:"nonce"`
To *common.Address `json:"to,omitempty"`
To *common.Address `json:"to,omitempty"`
TransactionIndex *hexutil.Uint64 `json:"transactionIndex"`
Value *hexutil.Big `json:"value"`
Type hexutil.Uint64 `json:"type"`
Accesses *types.AccessList `json:"accessList,omitempty"`
ChainID *hexutil.Big `json:"chainId,omitempty"`
BlobVersionedHashes []common.Hash `json:"blobVersionedHashes,omitempty"`
AuthorizationList []types.SetCodeAuthorization `json:"authorizationList,omitempty"`
V *hexutil.Big `json:"v,omitempty"`
R *hexutil.Big `json:"r,omitempty"`
S *hexutil.Big `json:"s,omitempty"`
V *hexutil.Big `json:"v,omitempty"`
R *hexutil.Big `json:"r,omitempty"`
S *hexutil.Big `json:"s,omitempty"`
YParity *hexutil.Uint64 `json:"yParity,omitempty"`

// Introduced by RIP-7560 Transaction
Expand Down Expand Up @@ -1058,7 +1058,7 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber
result.NonceKey = (*hexutil.Big)(rip7560Tx.NonceKey)
result.Input = make(hexutil.Bytes, 0)
result.Sender = rip7560Tx.Sender
result.AuthorizationData = toBytes(rip7560Tx.AuthorizationData)
result.AuthorizationData = toBytes(rip7560Tx.SenderValidationData)
result.ExecutionData = toBytes(rip7560Tx.ExecutionData)
result.Gas = hexutil.Uint64(tx.Gas())
result.Paymaster = rip7560Tx.Paymaster
Expand All @@ -1068,7 +1068,7 @@ func newRPCTransaction(tx *types.Transaction, blockHash common.Hash, blockNumber
result.BuilderFee = (*hexutil.Big)(rip7560Tx.BuilderFee)
result.ValidationGas = (*hexutil.Uint64)(&rip7560Tx.ValidationGasLimit)
result.PaymasterValidationGasLimit = conditional_uint64(rip7560Tx.PaymasterValidationGasLimit, rip7560Tx.Paymaster)
result.PostOpGas = conditional_uint64(rip7560Tx.PostOpGas, rip7560Tx.Paymaster)
result.PostOpGas = conditional_uint64(rip7560Tx.PostOpGasLimit, rip7560Tx.Paymaster)

//shared fields with DynamicFeeTxType
result.ChainID = (*hexutil.Big)(tx.ChainId())
Expand Down
4 changes: 2 additions & 2 deletions internal/ethapi/transaction_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,15 +557,15 @@ func (args *TransactionArgs) ToTransaction(defaultType int) *types.Transaction {
AccessList: al,
// RIP-7560 parameters
Sender: args.Sender,
AuthorizationData: *args.AuthorizationData,
SenderValidationData: *args.AuthorizationData,
Paymaster: args.Paymaster,
PaymasterData: *args.PaymasterData,
Deployer: args.Deployer,
DeployerData: *args.DeployerData,
BuilderFee: (*big.Int)(args.BuilderFee),
ValidationGasLimit: toUint64(args.ValidationGas),
PaymasterValidationGasLimit: toUint64(args.PaymasterGas),
PostOpGas: toUint64(args.PostOpGas),
PostOpGasLimit: toUint64(args.PostOpGas),
}

zeroAddress := common.Address{}
Expand Down
Loading