starknet-io / starknet.js

JavaScript library for StarkNet
https://www.starknetjs.com
MIT License
1.21k stars 739 forks source link

Error message: argent: signer signature invalid #765

Closed duanlixin closed 11 months ago

duanlixin commented 11 months ago

Describe the bug

Starknet has upgraded to version 5.19.5. And in this new version, I can bridge funds from Ethereum to the Starknet account successfully, but failed to deploy the Starknet account(specially, Argent account) with my code in the next step.

To Reproduce

code here

import { Account, CallData, Provider, constants, ec, hash } from 'starknet';

const deployAxAccount = async () => {
  // connect provider
  const provider = new Provider({ sequencer: { network: constants.NetworkName.SN_MAIN } });

  //new Argent X account v0.2.3
  const argentXproxyClassHash = '0x25ec026985a3bf9d0cc1fe17326b245dfdc3ff89b8fde106542a3ea56c5a918';
  const argentXaccountClassHash = '0x033434ad846cdd5f23eb73ff09fe6fddd568284a0fb7d1be20ee482f044dabe2';

  const privateKeyAX = process.env.AX_ACCOUNT_PRIVATE_KEY || '';
  const AXcontractAddress =  process.env.AX_ACCOUNT_CONTRACT_ADDRESS || '';

  const starkKeyPubAX = ec.starkCurve.getStarkKey(privateKeyAX);

  const AXproxyConstructorCallData = CallData.compile({
    implementation: argentXaccountClassHash,
    selector: hash.getSelectorFromName('initialize'),
    calldata: CallData.compile({ signer: starkKeyPubAX, guardian: '0' }),
  });

  const accountAX = new Account(provider, AXcontractAddress, privateKeyAX);
  // Calculate future address of the ArgentX account
  const deployAccountPayload = {
    classHash: argentXproxyClassHash,
    constructorCalldata: AXproxyConstructorCallData,
    contractAddress: AXcontractAddress,
    addressSalt: starkKeyPubAX,
  };

  const { transaction_hash: AXdAth, contract_address: AXcontractFinalAdress } = await accountAX.deployAccount(deployAccountPayload);

  console.log('✅ ArgentX wallet deployed at:', AXcontractFinalAdress);
};

deployAxAccount();

error here

/Users/.pnpm/registry.npmmirror.com+starknet@5.19.5/node_modules/starknet/src/provider/sequencer.ts:240
        throw new GatewayError(responseBody.message, responseBody.code);
              ^
GatewayError: Error at pc=0:12:
Got an exception while executing a hint.
Cairo traceback (most recent call last):
Unknown location (pc=0:161)
Unknown location (pc=0:147)

Error in the called contract (0x6d070c08b45f615ac66ad73c7dbcc56ec82cf7140afe60bf1b640d6471d628c):
Error at pc=0:111:
Signature (xxx, xxx), is invalid, with respect to the public key xxx, and the message hash xxx.
Cairo traceback (most recent call last):
Unknown location (pc=0:1498)
Unknown location (pc=0:1471)
Error message: argent: signer signature invalid
Unknown location (pc=0:1056)
    at SequencerProvider.fetch (/Users/.pnpm/registry.npmmirror.com+starknet@5.19.5/node_modules/starknet/src/provider/sequencer.ts:240:15)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Account.estimateAccountDeployFee (/Users/.pnpm/registry.npmmirror.com+starknet@5.19.5/node_modules/starknet/src/account/default.ts:199:22)
    at async Account.getSuggestedMaxFee (/Users/.pnpm/registry.npmmirror.com+starknet@5.19.5/node_modules/starknet/src/account/default.ts:524:23)
    at async Account.deployAccount (/Users/.pnpm/registry.npmmirror.com+starknet@5.19.5/node_modules/starknet/src/account/default.ts:445:8)
    at async deployAxAccount (/Users/git/starknet5.19.5/src/action/step/DeployAccount.ts:32:81) {
  errorCode: 'StarknetErrorCode.TRANSACTION_FAILED'
}
 ELIFECYCLE  Command failed with exit code 1.

Expected behavior

I want to deploy this Argent account successful.

Screenshots

1

Additional context

I have a doubtful question,the argentXproxyClassHash is inconsistent

2 3 4

PhilippeR26 commented 11 months ago

Hello, You should follow our Discord here : https://discord.com/channels/793094838509764618/927918707613786162 The recent upgrade of Argent X accounts to Cairo 1 have some impacts. Everything is explained there.

duanlixin commented 11 months ago

Hello, You should follow our Discord here : https://discord.com/channels/793094838509764618/927918707613786162 The recent upgrade of Argent X accounts to Cairo 1 have some impacts. Everything is explained there. 5

PhilippeR26 commented 11 months ago

It's necessary to subscribe first to Starknet Discord : https://discord.gg/qypnmzkhbc

PhilippeR26 commented 11 months ago

You can also have a look here : https://github.com/PhilippeR26/starknet.js-workshop-typescript/blob/main/src/scripts/3.createNewArgentXaccount.ts

duanlixin commented 11 months ago

You can also have a look here : https://github.com/PhilippeR26/starknet.js-workshop-typescript/blob/main/src/scripts/3.createNewArgentXaccount.ts

Yes, I've followed the instruction in the link you provided. I change contractAXclassHash to 0x1a736d6ed154502257f02b1ccdf4d9d1089f80811cd6acad48e6b6a9d1f2003. But it still failed. Error as below: node_modules/starknet/src/provider/sequencer.ts:240 throw new GatewayError(responseBody.message, responseBody.code); ^ GatewayError: Execution was reverted; failure reason: [0x617267656e742f696e76616c69642d6f776e65722d736967].

PhilippeR26 commented 11 months ago

Use this code to decode the message : https://github.com/PhilippeR26/starknet.js-workshop-typescript/blob/main/src/scripts/decodeError.ts

duanlixin commented 11 months ago

Error code as below: console.log("Decoded message =", shortString.decodeShortString("0x617267656e742f696e76616c69642d6f776e65722d736967"));

Console after decode as below: Decoded message = argent/invalid-owner-sig

duanlixin commented 11 months ago

Use this code to decode the message : https://github.com/PhilippeR26/starknet.js-workshop-typescript/blob/main/src/scripts/decodeError.ts

Thanks bro. It fixed. It's due to the lack of parameter "1". The sample code in doc lack of the parameter. image

duanlixin commented 11 months ago
import { Account, CallData, Provider, constants, ec, hash } from 'starknet';
const deployAxAccount = async () => {
  // connect provider
  const provider = new Provider({ sequencer: { network: constants.NetworkName.SN_MAIN } });

  //new Argent X account v0.2.3
  const contractAXclassHash = '0x1a736d6ed154502257f02b1ccdf4d9d1089f80811cd6acad48e6b6a9d1f2003';

  const privateKeyAX = process.env.AX_ACCOUNT_PRIVATE_KEY || '';
  const AXcontractAddress =  process.env.AX_ACCOUNT_CONTRACT_ADDRESS || '';

  const starkKeyPubAX = ec.starkCurve.getStarkKey(privateKeyAX);

  const ConstructorAXCallData = CallData.compile({
    owner: starkKeyPubAX,
    guardian: '0'
  });

  const accountAX = new Account(provider, AXcontractAddress, privateKeyAX, '1');

  const accountAXAddress = hash.calculateContractAddressFromHash(starkKeyPubAX, contractAXclassHash, ConstructorAXCallData, 0);
  console.log('Precalculated account address=', accountAXAddress);
  // Calculate future address of the ArgentX account
  const deployAccountPayload = {
    classHash: contractAXclassHash,
    constructorCalldata: ConstructorAXCallData,
    contractAddress: AXcontractAddress,
    addressSalt: starkKeyPubAX,
  };

  const { transaction_hash: AXdAth, contract_address: accountAXFinalAdress } = await accountAX.deployAccount(deployAccountPayload);
  console.log("Final address =",accountAXFinalAdress);
  await provider.waitForTransaction(AXdAth);
  console.log('✅ ArgentX wallet deployed.');
};

deployAxAccount();