starknet.js icon indicating copy to clipboard operation
starknet.js copied to clipboard

Fee estimation throws an error: signature is invalid

Open iamvukasin opened this issue 2 years ago • 5 comments

I want to estimate the fee for ERC20 transfer function, for example:

const contract = new Contract(
  erc20Abi,
  contractAddress, // e.g. 0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7
  account,
);
console.log(contract.estimateFee.transfer(recipient, [1, 0]));

but I'm always getting signature is invalid error:

Uncaught (in promise) y: 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 (<ADDRESS>):
Error at pc=0:111:
Signature (<SIGNATURE>, <SIGNATURE>), is invalid, with respect to the public key <PUBLIC_KEY>, and the message hash <MESSAGE_HASH>.
Cairo traceback (most recent call last):
Unknown location (pc=0:802)
Unknown location (pc=0:727)
Error message: signer signature invalid
Unknown location (pc=0:1662)
    at L.<anonymous> (chrome-extension://dlcobpjiigpikoobohmabehhmhfoodbb/inpage.js:13:147581)
    at _ (chrome-extension://dlcobpjiigpikoobohmabehhmhfoodbb/inpage.js:13:144470)
    at Object.next (chrome-extension://dlcobpjiigpikoobohmabehhmhfoodbb/inpage.js:13:143774)
    at W (chrome-extension://dlcobpjiigpikoobohmabehhmhfoodbb/inpage.js:13:143329)

I even tried to run the code on StarkNet devnet, but I got the same error. Also, I checked the signature for the hash with the wallet's is_valid_signature on Voyager and it was failing with the same message. Any ideas about what's causing problems?

Starknet.js version: 3.18.2 Browser: Brave 1.42.97 Wallet: Argent X

iamvukasin avatar Aug 26 '22 14:08 iamvukasin

i meet the same problem for this. will be lovely if i can hv some ideas on what's happening

ShawTim avatar Aug 26 '22 14:08 ShawTim

Hi @ShawTim @iamvukasin , you mention version 3.18.2, is the same thing happening on the latest version, 4.3.0? You can get it with npm install starknet@next

ivpavici avatar Aug 29 '22 08:08 ivpavici

I tried to experiment more and it looks like functions (in this case contract.estimateFee.transfer) are not accepting string arguments that start with 0x. I tried to drop the prefix, but I'm getting (both 3.18.2 and 4.3.0):

Error: Invalid character
    at assert (bn.js:6:1)
    at parseBase (bn.js:274:1)
    at BN._parseBase (bn.js:298:1)
    at BN.init [as _init] (bn.js:105:1)
    at new BN (bn.js:39:1)
    at toBN (number.js:44:1)
    at toFelt (number.js:59:1)
    at Contract.parseCalldataField (default.js:481:1)
    at default.js:498:1
    at Array.reduce (<anonymous>)
    at Contract.compileCalldata (default.js:494:1)
    at Contract.populate (default.js:645:1)
    at Object.deposit (default.js:157:1)
    at Contract.<anonymous> (default.js:631:1)
    at step (default.js:44:1)
    at Object.next (default.js:25:1)
    at default.js:19:1
    at new Promise (<anonymous>)
    at push../node_modules/starknet/dist/contract/default.js.__awaiter (default.js:15:1)

It looks like Uint256 is not parsed properly. I tried standard ERC20 contract and some private ones that had functions with address and Uint256 arguments. FYI, fee estimation works for functions that have only addresses or felt as parameters.

iamvukasin avatar Aug 29 '22 15:08 iamvukasin

This could be related to fix https://github.com/0xs34n/starknet.js/pull/326 if rpc but need validation

tabaktoni avatar Sep 13 '22 13:09 tabaktoni

@iamvukasin can you try maybe with the 4.6 or 4.7 version?

ivpavici avatar Sep 22 '22 14:09 ivpavici

Please link the ERC20 contract that you are using and the address of the account that you are using to sign the transaction

dhruvkelawala avatar Oct 17 '22 10:10 dhruvkelawala

I got this error

Uncaught g: 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 (0x6c364fa52256aa61cfa0c8a38e34f24cd87ae84e4e6ae14064cb2df9f0dc6fb):
Error at pc=0:111:
Signature (3447494504044970689901750764193630679079270423579642062688034113813836319383, 2557973517685848781640890452275630452513344931078077293339077327899948440970), is invalid, with respect to the public key 385827734771476934023052269293056772643529258251723806345297986901502131071, and the message hash 3575025669602213270306795768317850983854030144556924386159985569757584110480.
Cairo traceback (most recent call last):
Unknown location (pc=0:802)
Unknown location (pc=0:727)
Error message: signer signature invalid
Unknown location (pc=0:1662)
    at m.<anonymous> (chrome-extension://dlcobpjiigpikoobohmabehhmhfoodbb/inpage.js:14:179846)
    at E (chrome-extension://dlcobpjiigpikoobohmabehhmhfoodbb/inpage.js:14:176734)
    at Object.next (chrome-extension://dlcobpjiigpikoobohmabehhmhfoodbb/inpage.js:14:176038)
    at H (chrome-extension://dlcobpjiigpikoobohmabehhmhfoodbb/inpage.js:14:175593)

with account address 0x06C364fa52256aA61CFa0C8A38e34F24cD87AE84E4e6ae14064CB2dF9F0dc6FB and contract 0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7 on version 4.7. I even tested with our custom contracts and still same errors.

iamvukasin avatar Oct 18 '22 13:10 iamvukasin

I'm seeing the same behavior on 4.9. It appears the message hash that's being signed is different than the actual message hash. Continuing to look into it.

The message hash that's being signed matches the hash that's output when declaring using the Starknet CLI.

solimander avatar Nov 18 '22 01:11 solimander

Added test for this case on PR for V5. The test is passing as expected.

tabaktoni avatar Feb 13 '23 13:02 tabaktoni