Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aptos Connect Signature for Sponsored Transactions is Invalid #465

Open
Vaphen opened this issue Jan 16, 2025 · 0 comments
Open

Aptos Connect Signature for Sponsored Transactions is Invalid #465

Vaphen opened this issue Jan 16, 2025 · 0 comments

Comments

@Vaphen
Copy link

Vaphen commented Jan 16, 2025

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.

@Vaphen Vaphen changed the title Aptos Connect Signature for Sponsored Transactions Aptos Connect Signature for Sponsored Transactions is Invalid Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant