From 603d385c056ec82e7af293472184651f0e7b0a19 Mon Sep 17 00:00:00 2001 From: Dror Tirosh Date: Mon, 1 Jul 2024 22:11:30 +0300 Subject: [PATCH] paymaster time-range checking --- core/state_processor_rip7560.go | 2 +- tests/rip7560/paymaster_test.go | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/core/state_processor_rip7560.go b/core/state_processor_rip7560.go index aa815ad76d..9e0333ed4d 100644 --- a/core/state_processor_rip7560.go +++ b/core/state_processor_rip7560.go @@ -486,7 +486,7 @@ func validatePaymasterReturnData(data []byte) (context []byte, validAfter, valid if validationData == nil { return nil, 0, 0, errors.New("invalid paymaster return data") } - magicExpected, validAfter, validUntil := UnpackValidationData(validationData) + magicExpected, validUntil, validAfter := UnpackValidationData(validationData) if magicExpected != MAGIC_VALUE_PAYMASTER { return nil, 0, 0, errors.New("paymaster did not return correct MAGIC_VALUE") } diff --git a/tests/rip7560/paymaster_test.go b/tests/rip7560/paymaster_test.go index 4d9a37ce4e..e6a026d276 100644 --- a/tests/rip7560/paymaster_test.go +++ b/tests/rip7560/paymaster_test.go @@ -84,6 +84,26 @@ func TestPaymasterValidationFailure_contextTooLarge(t *testing.T) { }, "paymaster context too large") } +func TestPaymasterValidationFailure_validAfter(t *testing.T) { + handleTransaction(newTestContextBuilder(t).withCode(DEFAULT_SENDER, createAccountCode(), 0). + withCode(DEFAULT_PAYMASTER.String(), returnWithData(paymasterReturnValue(core.MAGIC_VALUE_PAYMASTER, 300, 200, []byte{})), DEFAULT_BALANCE), types.Rip7560AccountAbstractionTx{ + ValidationGas: 1000000000, + PaymasterGas: 1000000000, + GasFeeCap: big.NewInt(1000000000), + Paymaster: &DEFAULT_PAYMASTER, + }, "RIP-7560 transaction validity not reached yet") +} + +func TestPaymasterValidationFailure_validUntil(t *testing.T) { + handleTransaction(newTestContextBuilder(t).withCode(DEFAULT_SENDER, createAccountCode(), 0). + withCode(DEFAULT_PAYMASTER.String(), returnWithData(paymasterReturnValue(core.MAGIC_VALUE_PAYMASTER, 1, 0, []byte{})), DEFAULT_BALANCE), types.Rip7560AccountAbstractionTx{ + ValidationGas: 1000000000, + PaymasterGas: 1000000000, + GasFeeCap: big.NewInt(1000000000), + Paymaster: &DEFAULT_PAYMASTER, + }, "RIP-7560 transaction validity expired") +} + func TestPaymasterValidation_ok(t *testing.T) { handleTransaction(newTestContextBuilder(t).withCode(DEFAULT_SENDER, createAccountCode(), 0). withCode(DEFAULT_PAYMASTER.String(), returnWithData(paymasterReturnValue(core.MAGIC_VALUE_PAYMASTER, 0, 0, []byte{})), DEFAULT_BALANCE), types.Rip7560AccountAbstractionTx{