Skip to content

Commit 9a19b08

Browse files
authored
Fix paymaster-less v0.7 AA encoding (#143)
1 parent 59f7ed8 commit 9a19b08

File tree

1 file changed

+41
-22
lines changed

1 file changed

+41
-22
lines changed

Thirdweb/Thirdweb.Wallets/SmartWallet/SmartWallet.cs

+41-22
Original file line numberDiff line numberDiff line change
@@ -897,28 +897,47 @@ private async Task<byte[]> HashAndSignUserOp(UserOperationV7 userOp, ThirdwebCon
897897
Buffer.BlockCopy(maxPriorityFeePerGasBytes, 0, gasFeesBuffer, 0, 16);
898898
Buffer.BlockCopy(maxFeePerGasBytes, 0, gasFeesBuffer, 16, 16);
899899

900-
var paymasterBytes = userOp.Paymaster.HexToBytes();
901-
var paymasterVerificationGasLimitBytes = userOp.PaymasterVerificationGasLimit.ToHexBigInteger().HexValue.HexToBytes().PadBytes(16);
902-
var paymasterPostOpGasLimitBytes = userOp.PaymasterPostOpGasLimit.ToHexBigInteger().HexValue.HexToBytes().PadBytes(16);
903-
var paymasterDataBytes = userOp.PaymasterData;
904-
var paymasterAndDataBuffer = new byte[20 + 16 + 16 + paymasterDataBytes.Length];
905-
Buffer.BlockCopy(paymasterBytes, 0, paymasterAndDataBuffer, 0, 20);
906-
Buffer.BlockCopy(paymasterVerificationGasLimitBytes, 0, paymasterAndDataBuffer, 20, 16);
907-
Buffer.BlockCopy(paymasterPostOpGasLimitBytes, 0, paymasterAndDataBuffer, 20 + 16, 16);
908-
Buffer.BlockCopy(paymasterDataBytes, 0, paymasterAndDataBuffer, 20 + 16 + 16, paymasterDataBytes.Length);
909-
910-
var packedOp = new PackedUserOperation()
911-
{
912-
Sender = userOp.Sender,
913-
Nonce = userOp.Nonce,
914-
InitCode = initCodeBuffer,
915-
CallData = userOp.CallData,
916-
AccountGasLimits = accountGasLimitsBuffer,
917-
PreVerificationGas = userOp.PreVerificationGas,
918-
GasFees = gasFeesBuffer,
919-
PaymasterAndData = paymasterAndDataBuffer,
920-
Signature = userOp.Signature
921-
};
900+
PackedUserOperation packedOp;
901+
if (userOp.Paymaster is null or Constants.ADDRESS_ZERO or "0x")
902+
{
903+
packedOp = new PackedUserOperation()
904+
{
905+
Sender = userOp.Sender,
906+
Nonce = userOp.Nonce,
907+
InitCode = initCodeBuffer,
908+
CallData = userOp.CallData,
909+
AccountGasLimits = accountGasLimitsBuffer,
910+
PreVerificationGas = userOp.PreVerificationGas,
911+
GasFees = gasFeesBuffer,
912+
PaymasterAndData = Array.Empty<byte>(),
913+
Signature = userOp.Signature
914+
};
915+
}
916+
else
917+
{
918+
var paymasterBytes = userOp.Paymaster.HexToBytes();
919+
var paymasterVerificationGasLimitBytes = userOp.PaymasterVerificationGasLimit.ToHexBigInteger().HexValue.HexToBytes().PadBytes(16);
920+
var paymasterPostOpGasLimitBytes = userOp.PaymasterPostOpGasLimit.ToHexBigInteger().HexValue.HexToBytes().PadBytes(16);
921+
var paymasterDataBytes = userOp.PaymasterData;
922+
var paymasterAndDataBuffer = new byte[20 + 16 + 16 + paymasterDataBytes.Length];
923+
Buffer.BlockCopy(paymasterBytes, 0, paymasterAndDataBuffer, 0, 20);
924+
Buffer.BlockCopy(paymasterVerificationGasLimitBytes, 0, paymasterAndDataBuffer, 20, 16);
925+
Buffer.BlockCopy(paymasterPostOpGasLimitBytes, 0, paymasterAndDataBuffer, 20 + 16, 16);
926+
Buffer.BlockCopy(paymasterDataBytes, 0, paymasterAndDataBuffer, 20 + 16 + 16, paymasterDataBytes.Length);
927+
928+
packedOp = new PackedUserOperation()
929+
{
930+
Sender = userOp.Sender,
931+
Nonce = userOp.Nonce,
932+
InitCode = initCodeBuffer,
933+
CallData = userOp.CallData,
934+
AccountGasLimits = accountGasLimitsBuffer,
935+
PreVerificationGas = userOp.PreVerificationGas,
936+
GasFees = gasFeesBuffer,
937+
PaymasterAndData = paymasterAndDataBuffer,
938+
Signature = userOp.Signature
939+
};
940+
}
922941

923942
var userOpHash = await ThirdwebContract.Read<byte[]>(entryPointContract, "getUserOpHash", packedOp).ConfigureAwait(false);
924943

0 commit comments

Comments
 (0)