Skip to content

Commit

Permalink
feat: set allowSigFail operation based on estimation condition
Browse files Browse the repository at this point in the history
  • Loading branch information
kangsorang committed Oct 25, 2024
1 parent 827e3a3 commit b026766
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
22 changes: 14 additions & 8 deletions core/state_processor_rip7560.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,13 @@ func ApplyRip7560ValidationPhases(
header *types.Header,
tx *types.Transaction,
cfg vm.Config,
estimateFlag ...bool,
) (*ValidationPhaseResult, error) {
var estimate = false
if len(estimateFlag) > 0 && estimateFlag[0] {
estimate = estimateFlag[0]
}

aatx := tx.Rip7560TransactionData()
err := performStaticValidation(aatx, statedb)
if err != nil {
Expand Down Expand Up @@ -461,7 +467,7 @@ func ApplyRip7560ValidationPhases(
true,
)
}
aad, err := validateAccountEntryPointCall(epc, aatx.Sender)
aad, err := validateAccountEntryPointCall(epc, aatx.Sender, estimate)
if err != nil {
return nil, wrapError(err)
}
Expand All @@ -476,7 +482,7 @@ func ApplyRip7560ValidationPhases(
return nil, wrapError(err)
}

paymasterContext, pmValidationUsedGas, pmValidAfter, pmValidUntil, err := applyPaymasterValidationFrame(st, epc, tx, signingHash, header)
paymasterContext, pmValidationUsedGas, pmValidAfter, pmValidUntil, err := applyPaymasterValidationFrame(st, epc, tx, signingHash, header, estimate)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -595,7 +601,7 @@ func performStaticValidation(
return nil
}

func applyPaymasterValidationFrame(st *StateTransition, epc *EntryPointCall, tx *types.Transaction, signingHash common.Hash, header *types.Header) ([]byte, uint64, uint64, uint64, error) {
func applyPaymasterValidationFrame(st *StateTransition, epc *EntryPointCall, tx *types.Transaction, signingHash common.Hash, header *types.Header, estimate bool) ([]byte, uint64, uint64, uint64, error) {
/*** Paymaster Validation Frame ***/
aatx := tx.Rip7560TransactionData()
var pmValidationUsedGas uint64
Expand All @@ -617,7 +623,7 @@ func applyPaymasterValidationFrame(st *StateTransition, epc *EntryPointCall, tx
)
}
pmValidationUsedGas = resultPm.UsedGas
apd, err := validatePaymasterEntryPointCall(epc, aatx.Paymaster)
apd, err := validatePaymasterEntryPointCall(epc, aatx.Paymaster, estimate)
if err != nil {
return nil, 0, 0, 0, wrapError(err)
}
Expand Down Expand Up @@ -892,7 +898,7 @@ func preparePostOpMessage(vpr *ValidationPhaseResult, success bool, gasUsed uint
return abiEncodePostPaymasterTransaction(success, gasUsed, vpr.PaymasterContext)
}

func validateAccountEntryPointCall(epc *EntryPointCall, sender *common.Address) (*AcceptAccountData, error) {
func validateAccountEntryPointCall(epc *EntryPointCall, sender *common.Address, estimate bool) (*AcceptAccountData, error) {
if epc.err != nil {
return nil, epc.err
}
Expand All @@ -902,10 +908,10 @@ func validateAccountEntryPointCall(epc *EntryPointCall, sender *common.Address)
if epc.From.Cmp(*sender) != 0 {
return nil, errors.New("invalid call to EntryPoint contract from a wrong account address")
}
return abiDecodeAcceptAccount(epc.Input, false)
return abiDecodeAcceptAccount(epc.Input, estimate)
}

func validatePaymasterEntryPointCall(epc *EntryPointCall, paymaster *common.Address) (*AcceptPaymasterData, error) {
func validatePaymasterEntryPointCall(epc *EntryPointCall, paymaster *common.Address, estimate bool) (*AcceptPaymasterData, error) {
if epc.err != nil {
return nil, epc.err
}
Expand All @@ -916,7 +922,7 @@ func validatePaymasterEntryPointCall(epc *EntryPointCall, paymaster *common.Addr
if epc.From.Cmp(*paymaster) != 0 {
return nil, errors.New("invalid call to EntryPoint contract from a wrong paymaster address")
}
apd, err := abiDecodeAcceptPaymaster(epc.Input, false)
apd, err := abiDecodeAcceptPaymaster(epc.Input, estimate)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion eth/gasestimator/gasestimator_rip7560.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func executeRip7560Validation(ctx context.Context, tx *types.Transaction, opts *
}()

// Gas Pool is set to half of the maximum possible gas to prevent overflow
vpr, err := core.ApplyRip7560ValidationPhases(opts.Config, opts.Chain, &opts.Header.Coinbase, new(core.GasPool).AddGas(math.MaxUint64/2), dirtyState, opts.Header, tx, evm.Config)
vpr, err := core.ApplyRip7560ValidationPhases(opts.Config, opts.Chain, &opts.Header.Coinbase, new(core.GasPool).AddGas(math.MaxUint64/2), dirtyState, opts.Header, tx, evm.Config, true)
if err != nil {
if errors.Is(err, vm.ErrOutOfGas) {
return nil, nil, nil // Special case, raise gas limit
Expand Down

0 comments on commit b026766

Please sign in to comment.