Skip to content
This repository was archived by the owner on May 22, 2024. It is now read-only.
This repository was archived by the owner on May 22, 2024. It is now read-only.

Check balance before doing IERC20.transferFrom #32

@dhruvkelawala

Description

@dhruvkelawala

Problem

https://github.com/starknet-id/naming_contract/blob/8d7f4b7a06b895df1d612e9ae739d09502e1dd80/src/naming/registration.cairo#L60

Here, you execute transferFrom on ERC20 without checking for balance. So if the balance is not enough, it throws error on wallets when estimateFee is called by the wallets. OZ's ERC20 contracts doesn't show errors properly. So it becomes very difficult for the wallets to handle it and users to know what the actual error is.

This is what the error looks like:

Error in the called contract (0x6ac597f8116f886fa1c97a23fa4e08299975ecaf6b598873ca6792b9bbfb678):
Error at pc=0:15:
Got an exception while executing a hint.
Cairo traceback (most recent call last):
Unknown location (pc=0:214)
Unknown location (pc=0:200)

Error in the called contract (0x6ac597f8116f886fa1c97a23fa4e08299975ecaf6b598873ca6792b9bbfb678):
Error at pc=0:178:
Got an exception while executing a hint.
Cairo traceback (most recent call last):
Unknown location (pc=0:2822)
Unknown location (pc=0:2800)
Unknown location (pc=0:1712)
Unknown location (pc=0:1380)

Error in the called contract (0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7):
Error at pc=0:104:
Got an exception while executing a hint.
Cairo traceback (most recent call last):
Unknown location (pc=0:1678)
Unknown location (pc=0:1664)

Error in the called contract (0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7):
Error at pc=0:9:
Got an exception while executing a hint.
Cairo traceback (most recent call last):
Unknown location (pc=0:1434)
Unknown location (pc=0:1395)
Unknown location (pc=0:915)

Traceback (most recent call last):
  File "<hint1>", line 3, in <module>
AssertionError: assert_not_zero failed: 0 = 0.

Possible Solution

I would suggest to check for balance before doing this transferFrom and use an assert statement with with_attr error_message to display correct message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions