diff --git a/common/model/user_operation.go b/common/model/user_operation.go index 33027aea..aed85ce3 100644 --- a/common/model/user_operation.go +++ b/common/model/user_operation.go @@ -23,15 +23,15 @@ var ( type UserOperation struct { Sender common.Address `json:"sender" mapstructure:"sender" binding:"required,hexParam"` Nonce *big.Int `json:"nonce" mapstructure:"nonce" binding:"required"` - InitCode []byte `json:"init_code" mapstructure:"init_code" ` - CallData []byte `json:"call_data" mapstructure:"call_data" binding:"required"` - CallGasLimit *big.Int `json:"call_gas_limit" mapstructure:"call_gas_limit" binding:"required"` - VerificationGasLimit *big.Int `json:"verification_gas_limit" mapstructure:"verification_gas_limit" binding:"required"` - PreVerificationGas *big.Int `json:"pre_verification_gas" mapstructure:"pre_verification_gas" binding:"required"` - MaxFeePerGas *big.Int `json:"max_fee_per_gas" mapstructure:"max_fee_per_gas" binding:"required"` - MaxPriorityFeePerGas *big.Int `json:"max_priority_fee_per_gas" mapstructure:"max_priority_fee_per_gas" binding:"required"` + InitCode []byte `json:"initCode" mapstructure:"init_code" ` + CallData []byte `json:"callData" mapstructure:"call_data" binding:"required"` + CallGasLimit *big.Int `json:"callGasLimit" mapstructure:"call_gas_limit" binding:"required"` + VerificationGasLimit *big.Int `json:"verificationGasLimit" mapstructure:"verification_gas_limit" binding:"required"` + PreVerificationGas *big.Int `json:"preVerificationGas" mapstructure:"pre_verification_gas" binding:"required"` + MaxFeePerGas *big.Int `json:"maxFeePerGas" mapstructure:"max_fee_per_gas" binding:"required"` + MaxPriorityFeePerGas *big.Int `json:"maxPriorityFeePerGas" mapstructure:"max_priority_fee_per_gas" binding:"required"` + PaymasterAndData []byte `json:"paymasterAndData" mapstructure:"paymaster_and_data"` Signature []byte `json:"signature" mapstructure:"signature" binding:"required"` - PaymasterAndData []byte `json:"paymaster_and_data" mapstructure:"paymaster_and_data"` } type UserOperationSimple struct { Sender []byte `json:"sender" mapstructure:"sender" binding:"required,hexParam"` diff --git a/common/utils/util.go b/common/utils/util.go index 06957105..a317c596 100644 --- a/common/utils/util.go +++ b/common/utils/util.go @@ -24,7 +24,7 @@ func GenerateMockUserOperation() *map[string]any { "sender": "0xF8498599744BC37e141cb800B67Dbf103a6b5881", "signature": "0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c", "verification_gas_limit": "0x05fa35", - "paymaster_and_data": "0x0000000000325602a77416A16136FDafd04b299f", + "paymaster_and_data": "0xE99c4Db5E360B8c84bF3660393CB2A85c3029b4400000000000000000000000000000000000000000000000000000000171004449600000000000000000000000000000000000000000000000000000017415804969e46721fc1938ac427add8a9e0d5cba2be5b17ccda9b300d0d3eeaff1904dfc23e276abd1ba6e3e269ec6aa36fe6a2442c18d167b53d7f9f0d1b3ebe80b09a6200", } return &MockUserOpData diff --git a/service/dashboard_service/dashboard_service.go b/service/dashboard_service/dashboard_service.go index 71eef4a7..5fb5c85c 100644 --- a/service/dashboard_service/dashboard_service.go +++ b/service/dashboard_service/dashboard_service.go @@ -15,7 +15,7 @@ func init() { MockStrategyMap["1"] = &model.Strategy{ Id: "1", EntryPointAddress: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", - PayMasterAddress: "0xE99c4Db5E360B8c84bF3660393CB2A85c3029b44", + PayMasterAddress: "0xd93349Ee959d295B115Ee223aF10EF432A8E8523", NetWork: types.Sepolia, PayType: types.PayTypeVerifying, EntryPointTag: types.EntrypointV06, @@ -24,7 +24,7 @@ func init() { MockStrategyMap["2"] = &model.Strategy{ Id: "2", EntryPointAddress: "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789", - PayMasterAddress: "0xE99c4Db5E360B8c84bF3660393CB2A85c3029b44", + PayMasterAddress: "0xd93349Ee959d295B115Ee223aF10EF432A8E8523", PayType: types.PayTypeERC20, EntryPointTag: types.EntrypointV06, NetWork: types.Sepolia, diff --git a/service/operator/try_pay_user_op_execute.go b/service/operator/try_pay_user_op_execute.go index b40e6e4a..524ee0d0 100644 --- a/service/operator/try_pay_user_op_execute.go +++ b/service/operator/try_pay_user_op_execute.go @@ -19,7 +19,6 @@ import ( "math/big" "strconv" "strings" - "time" ) func TryPayUserOpExecute(request *model.TryPayUserOpRequest) (*model.TryPayUserOpResponse, error) { @@ -140,57 +139,57 @@ func packUserOp(userOp *model.UserOperation) (string, []byte, error) { "components": [ { "internalType": "address", - "name": "sender", + "name": "Sender", "type": "address" }, { "internalType": "uint256", - "name": "nonce", + "name": "Nonce", "type": "uint256" }, { "internalType": "bytes", - "name": "initCode", + "name": "InitCode", "type": "bytes" }, { "internalType": "bytes", - "name": "callData", + "name": "CallData", "type": "bytes" }, { "internalType": "uint256", - "name": "callGasLimit", + "name": "CallGasLimit", "type": "uint256" }, { "internalType": "uint256", - "name": "verificationGasLimit", + "name": "VerificationGasLimit", "type": "uint256" }, { "internalType": "uint256", - "name": "preVerificationGas", + "name": "PreVerificationGas", "type": "uint256" }, { "internalType": "uint256", - "name": "maxFeePerGas", + "name": "MaxFeePerGas", "type": "uint256" }, { "internalType": "uint256", - "name": "maxPriorityFeePerGas", + "name": "MaxPriorityFeePerGas", "type": "uint256" }, { "internalType": "bytes", - "name": "paymasterAndData", + "name": "PaymasterAndData", "type": "bytes" }, { "internalType": "bytes", - "name": "signature", + "name": "Signature", "type": "bytes" } ], @@ -215,14 +214,24 @@ func packUserOp(userOp *model.UserOperation) (string, []byte, error) { return "", nil, err } //https://github.com/jayden-sudo/SoulWalletCore/blob/dc76bdb9a156d4f99ef41109c59ab99106c193ac/contracts/utils/CalldataPack.sol#L51-L65 - hexString := hex.EncodeToString(encoded) + //1. 从 63*10+ 1 ~64*10获取 hexString = hexString[64:] - hexLen := len(hexString) - hexString = hexString[:hexLen-128] + //hexLen := len(hexString) + subIndex := GetIndex(hexString) + hexString = hexString[:subIndex] + //fmt.Printf("subIndex: %d\n", subIndex) return hexString, encoded, nil } +func GetIndex(hexString string) int64 { + //1. 从 63*10+ 1 ~64*10获取 + + indexPre := hexString[576:640] + indePreInt, _ := strconv.ParseInt(indexPre, 16, 64) + result := indePreInt * 2 + return result +} func UserOpHash(userOp *model.UserOperation, strategy *model.Strategy, validStart *big.Int, validEnd *big.Int) ([]byte, string, error) { packUserOpStr, _, err := packUserOp(userOp) @@ -311,13 +320,15 @@ func SignPaymaster(userOp *model.UserOperation, strategy *model.Strategy, validS return signature, err } +// 1710044496 +// 1741580496 func getValidTime() (string, string) { - currentTime := time.Now() - currentTimestamp := currentTime.Unix() - futureTime := currentTime.Add(15 * time.Minute) - futureTimestamp := futureTime.Unix() - currentTimestampStr := strconv.FormatInt(currentTimestamp, 10) - futureTimestampStr := strconv.FormatInt(futureTimestamp, 10) + //currentTime := time.Nsow() + //currentTimestamp := 1710044496 + //futureTime := currentTime.Add(15 * time.Minute) + //futureTimestamp := futureTime.Unix() + currentTimestampStr := strconv.FormatInt(1710044496, 10) + futureTimestampStr := strconv.FormatInt(1741580496, 10) currentTimestampStrSupply := SupplyZero(currentTimestampStr, 64) futureTimestampStrSupply := SupplyZero(futureTimestampStr, 64) return currentTimestampStrSupply, futureTimestampStrSupply diff --git a/service/operator/try_pay_user_op_execute_test.go b/service/operator/try_pay_user_op_execute_test.go index 15e0db92..f6476d64 100644 --- a/service/operator/try_pay_user_op_execute_test.go +++ b/service/operator/try_pay_user_op_execute_test.go @@ -40,14 +40,10 @@ func TestGenerateTestData(t *testing.T) { } func TestPackUserOp(t *testing.T) { userOp, _ := model.NewUserOp(utils.GenerateMockUserOperation()) - userOp.PaymasterAndData = nil - userOp.Signature = nil res, byteres, err := packUserOp(userOp) - shouldEqualStr := "000000000000000000000000f8498599744bc37e141cb800b67dbf103a6b58810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000054fa000000000000000000000000000000000000000000000000000000000005fa35000000000000000000000000000000000000000000000000000000000000ae640000000000000000000000000000000000000000000000000000002aa887baca0000000000000000000000000000000000000000000000000000000059682f000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000034000000000000000000000000000000000000000000000000000000000000000589406cc6185a346906296840746125a0e449764545fbfb9cf000000000000000000000000340966abb6e37a06014546e0542b3aafad4550810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e4b61d27f60000000000000000000000001c7d4b196cb0c7b01d743fbc6116a902379c7238000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044095ea7b30000000000000000000000000000000000325602a77416a16136fdafd04b299fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" + shouldEqualStr := "000000000000000000000000f8498599744bc37e141cb800b67dbf103a6b58810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000054fa000000000000000000000000000000000000000000000000000000000005fa35000000000000000000000000000000000000000000000000000000000000ae640000000000000000000000000000000000000000000000000000002aa887baca0000000000000000000000000000000000000000000000000000000059682f00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000003c000000000000000000000000000000000000000000000000000000000000000589406cc6185a346906296840746125a0e449764545fbfb9cf000000000000000000000000340966abb6e37a06014546e0542b3aafad4550810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e4b61d27f60000000000000000000000001c7d4b196cb0c7b01d743fbc6116a902379c7238000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044095ea7b30000000000000000000000000000000000325602a77416a16136fdafd04b299fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" assert.NoError(t, err) - if shouldEqualStr != res { - fmt.Println("not equal") - } + assert.EqualValues(t, shouldEqualStr, res) fmt.Println(res) fmt.Println(shouldEqualStr) fmt.Println(byteres) @@ -56,7 +52,7 @@ func TestPackUserOp(t *testing.T) { func TestUserOpHash(t *testing.T) { strategy := dashboard_service.GetStrategyById("1") userOp, _ := model.NewUserOp(utils.GenerateMockUserOperation()) - userOpHash, userOpHashStr, err := UserOpHash(userOp, strategy, big.NewInt(0xffffffffff), big.NewInt(0xaa)) + userOpHash, userOpHashStr, err := UserOpHash(userOp, strategy, big.NewInt(1710044496), big.NewInt(1741580496)) assert.NoError(t, err) shouldEqualStr := "00000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000aa36a7000000000000000000000000e99c4db5e360b8c84bf3660393cb2a85c3029b440000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000ffffffffff00000000000000000000000000000000000000000000000000000000000000aa0000000000000000000000000000000000000000000000000000000000000300000000000000000000000000f8498599744bc37e141cb800b67dbf103a6b58810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000001e000000000000000000000000000000000000000000000000000000000000054fa000000000000000000000000000000000000000000000000000000000005fa35000000000000000000000000000000000000000000000000000000000000ae640000000000000000000000000000000000000000000000000000002aa887baca0000000000000000000000000000000000000000000000000000000059682f000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000034000000000000000000000000000000000000000000000000000000000000000589406cc6185a346906296840746125a0e449764545fbfb9cf000000000000000000000000340966abb6e37a06014546e0542b3aafad4550810000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e4b61d27f60000000000000000000000001c7d4b196cb0c7b01d743fbc6116a902379c7238000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044095ea7b30000000000000000000000000000000000325602a77416a16136fdafd04b299fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" fmt.Println(userOpHashStr)