Skip to content

Aptos Connect Signature for Sponsored Transactions is Invalid #465

Description

@Vaphen

Context

Requesting a signature via Aptos Connect sometimes results in an invalid Signature error when trying to sponsor and submit the transaction.

Error from the logs:
{"message":"Invalid transaction: Type: Validation Code: INVALID_SIGNATURE","error_code":"vm_error","vm_error_code":1}

This behavior is not deterministic, meaning that sometimes the transaction is executed successfully, sometimes the error above is returned.
The error happens using Aptos Connect via Browser, as well as via Telegram Mini App.

Steps to Reproduce

The issue can be reproduced by requesting a signature and sponsor the transaction using the following next client- and server functions:

Client:

const { signTransaction, account } = useWallet();

await executeTransaction(account.address, contractPayload);

async executeTransaction(sender: AccountAddressInput, data: EntryPayload) {
        const transactionPayload = {
            sender,
            data,
            withFeePayer: true,
        };

        const transaction = await aptos.transaction.build.simple(transactionPayload);
        const userAuthenticator = await signTransaction(transaction);

        const serializedUserAuthenticator = new Serializer();
        userAuthenticator.serialize(serializedUserAuthenticator);
        
        const transactionSerializer = new Serializer();
        transaction.serialize(transactionSerializer);

        return await sponsorTranasction(serializedUserAuthenticator.toUint8Array(), transactionSerializer.toUint8Array());      
    } 

Server:

'use server';

export default async function sponsorTranasction(serializedAuthenticator: Uint8Array, serializedTransaction: Uint8Array) {
    const privateKey = new Ed25519PrivateKey(...);
    const feePayerAccount = Account.fromPrivateKey({ privateKey });
    
    const userAuthenticator = AccountAuthenticator.deserialize(new Deserializer(serializedAuthenticator));
    const transaction = SimpleTransaction.deserialize(new Deserializer(serializedTransaction));

    const feePayerAuthenticator = aptos.transaction.signAsFeePayer({
        signer: feePayerAccount,
        transaction,
    });

    const committedTransaction = await aptos.transaction.submit.simple({
        transaction,
        senderAuthenticator: userAuthenticator,
        feePayerAuthenticator,
    });

    await aptos.waitForTransaction({ transactionHash: committedTransaction.hash });
}

Expected Behavior

The message signature is valid and the transaction can be executed by the server after sponsoring the gas fees.

Actual Behavior

Sometimes, the user's signature seems to be invalid. This is an excerpt of the server logs:
{"message":"Invalid transaction: Type: Validation Code: INVALID_SIGNATURE","error_code":"vm_error","vm_error_code":1}

Debugging Notes

Unfortunately, this error is not deterministic. At one test, after the INVALID_SIGNATURE error already happened twice, the third execution was successfull.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions