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-430: (WIP) Encode 'UsedGasBreakdown' struct for 'postPaymasterTx' frame #45

Open
wants to merge 2 commits into
base: RIP-7560-revision-2
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
13 changes: 11 additions & 2 deletions core/rip7560_abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,18 @@ func abiEncodeValidatePaymasterTransaction(tx *types.Rip7560AccountAbstractionTx
return data, err
}

func abiEncodePostPaymasterTransaction(success bool, actualGasCost uint64, context []byte) []byte {
type UsedGasBreakdown struct {
PreTransactionGasUsed *big.Int
AccountDeploymentGasUsed *big.Int
AccountValidationGasUsed *big.Int
PaymasterValidationGasUsed *big.Int
ExecutionGasUsed *big.Int
ExecutionUnusedPenaltyGas *big.Int
}

func abiEncodePostPaymasterTransaction(success bool, usedGasBreakdown *UsedGasBreakdown, context []byte) []byte {
// TODO: pass actual gas cost parameter here!
postOpData, err := Rip7560Abi.Pack("postPaymasterTransaction", success, big.NewInt(int64(actualGasCost)), context)
postOpData, err := Rip7560Abi.Pack("postPaymasterTransaction", success, context, usedGasBreakdown)
if err != nil {
panic("unable to encode postPaymasterTransaction")
}
Expand Down
48 changes: 45 additions & 3 deletions core/rip7560_abi_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,51 @@ const Rip7560AbiJson = `
"name":"postPaymasterTransaction",
"inputs": [
{"name": "success","type": "bool"},
{"name": "actualGasCost","type": "uint256"},
{"name": "context","type": "bytes"}
]
{
"internalType": "bytes",
"name": "context",
"type": "bytes"
},
{
"components": [
{
"internalType": "uint256",
"name": "preTransactionGasUsed",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "accountDeploymentGasUsed",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "accountValidationGasUsed",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "paymasterValidationGasUsed",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "executionGasUsed",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "executionUnusedPenaltyGas",
"type": "uint256"
}
],
"internalType": "struct UsedGasBreakdown",
"name": "usedGasBreakdown",
"type": "tuple"
}
],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type":"function",
Expand Down
6 changes: 6 additions & 0 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,12 @@ func (s *StateDB) GetRefund() uint64 {
return s.refund
}

// ResetRefundRip7560 sets the refund counter to 0 preparing for the next frame
// TODO: Consider if this is a viable way to achieve a per-frame gas refund or if we must do something else
func (s *StateDB) ResetRefundRip7560() {
s.refund = 0
}

// Finalise finalises the state by removing the destructed objects and clears
// the journal as well as the refunds. Finalise, however, will not push any updates
// into the tries just yet. Only IntermediateRoot or Commit will do that.
Expand Down
Loading
Loading