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

Bug in NFT and FT allowances in the precompile #67

Closed
ed-marquez opened this issue Sep 15, 2022 · 7 comments
Closed

Bug in NFT and FT allowances in the precompile #67

ed-marquez opened this issue Sep 15, 2022 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@ed-marquez
Copy link

ed-marquez commented Sep 15, 2022

Description

When approving allowances for FTs and NFTs via the precompiles, the process does not complete as expected because there's a bug where the precompile doesn't seem to understand that a token and an account are already associated.

This same process works OK and as expected when done through the SDKs.

In the FT/NFT example:

  • 5 entities are involved: Operator, Treasury, Alice, Bob, and the token.
  • The Treasury of the token approves an allowance for Alice of 50 FT units / 1 NFT
  • Alice should send bob 10 FT / 1 NFT units from the allowance
  • Again, this same process was successfully completed using the JS SDK for both FT and NFT

The Issue:
The allowance transfer throws the error: SPENDER_DOES_NOT_HAVE_ALLOWANCE. See the error file for console output and additional details. Approval-Allowance bug - error message.txt

The crypto transfer tx in Alice's tx history in HashScan correctly shows that she doesn't have the allowance. AlicesTxs

The operator tx history, specifically the failed contract call for approving the allowance FALSELY shows: TOKEN_NOT_ASSOCIATED_TO_ACCOUNT. operatorTxs

The console output (and tx history) shows that both Alice and Bob are associated with the token. As a test, the treasury already sent some tokens to Alice using the SDK before calling the contract.

So even though Alice already owns tokens, the precompile seems to think that Alice is not associated to the token => thus the allowance approval via precompile fails => thus the approved token transfer fails.

Tagging @Nana-EC @tinker-michaelj for visibility. Thank you in advanced team : )

Steps to reproduce

  1. Open the following GitPod: https://gitpod.io/#https://github.com/ed-marquez/quick-contract-examples
  2. Add a .env file with your own credentials
  3. Try running the files: 0_test_precompile_FT.js and 0_test_precompile_NFT.js
  4. Monitor the operator account activity in HashScan for additional details

Additional context

No response

Hedera network

mainnet, testnet

Version

v2.18

Operating system

Windows

@ed-marquez ed-marquez added the bug Something isn't working label Sep 15, 2022
@a-ridley
Copy link

This bug is also affecting granting an allowance to an account using ERC20 standard calls. Currently, users cannot grant an allowance to an account and complete a token transfer.



Please see the link below for the repo, an explanation of what is being done in the repo, and steps to reproduce:



This below code example does the following:

1. creates 3 accounts: Treasury, Alice, and Bob.
2. creates an FT of token symbol POP
3. executes a tokenAssocations for Alice and Bob to POP
4. executes a token transfer of 3 POP from Treasury to Alice
5. deploys a smart contract
6. executes a ContractExecuteTransaction for the ERC20 approve function
7. executes an approved token transfer

Steps to reproduce: https://gitpod.io/#snapshot/7f7e3241-10f9-443b-88d0-cae4d43222c8

  1. Open the following GitPod:
  2. Add a .env file with your own credentials
  3. Run node index.js in the gitpod terminal
  4. Monitor account activity in HashScan for additional details

@Burstall
Copy link

Burstall commented Oct 1, 2022

To add to this discussion:

HederaTokenService.sol approveNFT method takes a uint256 input for the serial (per the gitpod example) however it dynamically binds to send to the precompile using the IHederaTokenService which expects an int64. If I create my own method making the low-level call dynamically to precompile via IHederaTokenService passing an int64 then I get it to work. This is not the only case of inconsistency, unfortunately.

function approveNFT(address token, int64 serialNumber) external returns (int responseCode) {
		// HederaTokenSerive.sol implments the method as unit256 serialNumber
		// however it is called via the interface (IHederaTokenService) where serialNumber is int64
		(bool success, bytes memory result) = precompileAddress.call(
            abi.encodeWithSelector(IHederaTokenService.approveNFT.selector,
            token, address(this), serialNumber));
        responseCode = success ? abi.decode(result, (int32)) : HederaResponseCodes.UNKNOWN;
	}

@Nana-EC
Copy link
Collaborator

Nana-EC commented Oct 3, 2022

HI @Burstall thanks for highlighting this.
We are aware of it and are carefully considering the right approach with minimal impact.
This was captured in hashgraph/hedera-services#3916

@ed-marquez and @a-ridley thanks for the original issue.
We're aware and are investigating how best to approach this.
See #69 and hashgraph/hedera-services#3758

@Ivo-Yankov
Copy link
Collaborator

The code from gitpod completes succesfully without any errors and the CRYPTO_APPROVE_ALLOWANCE transaction doesn't fail. @ed-marquez @a-ridley Could you please confirm if the issue is resolved?

@a-ridley
Copy link

The code from gitpod completes succesfully without any errors and the CRYPTO_APPROVE_ALLOWANCE transaction doesn't fail. @ed-marquez @a-ridley Could you please confirm if the issue is resolved?

The issue is resolved. I had to make the following change to the smart contract: use delegatecall instead of call. The CRYPTO_APPROVE_ALLOWANCE transaction completes successfully.

@Nana-EC
Copy link
Collaborator

Nana-EC commented Oct 15, 2022

Thanks closing this.

@Burstall where are you seeing an int64 serialNumber in IHederaTokenService?
The current and previous data types were all uint256.
Notably this will change with #99 so feel free to comment there regarding your issue.

@Nana-EC Nana-EC closed this as completed Oct 15, 2022
@Burstall
Copy link

looks good now on the latest set I saw. I see things moving around a little and am trying to keep up to date accordingly. thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

5 participants