hiero-ledger / hiero-ledger/hiero-consensus-node

ContractCallQuery to HTS with long-zero address in params

Open
#5,802 1 comment 0 reactions 1 assignee Claimed by @lukasz-hashgraph View on GitHub
Bug
Dominant language
Java
Stars
406
Forks
226
Avg merge
3d 4h
Merged PRs (30d)
210

Description

### Description

Submitting a `ContractCallQuery` to an HTS token with a long-zero address in the function parametters results in `CONTRACT_REVERT_EXECUTED`.

Submitting the same query, but with an evmAddress in the parametters instead, it returns a correct result.

### Steps to reproduce

1. Run the local node `hedera start -d`
2. Run the provided example js code.

### Additional context

```javascript
const {PrivateKey, Client, AccountId, TokenCreateTransaction,
TransactionId, ContractCallQuery, ContractId
} = require('@hashgraph/sdk');

(async () => {

// Init the client
let client = Client.forNetwork(JSON.parse('{"127.0.0.1:50211":"0.0.3"}'));
const accountId = '0.0.1012';
const longZeroAddress = '00000000000000000000000000000000000003f4';
const evmAddress = '67d8d32e9bf1a9968a5ff53b87d777aa8ebbee69';
const privateKey = '105d050185ccb907fba04dd92d8de9e32c18305e097ab41dadda21489a211524';
client = client.setOperator(AccountId.fromString(accountId), PrivateKey.fromStringECDSA(privateKey));

// Create an HTS token
const tokenCreate = await (new TokenCreateTransaction()
.setTokenName("NAME")
.setTokenSymbol("SYMBOL")
.setDecimals(18)
.setTreasuryAccountId(AccountId.fromString(accountId))
.setInitialSupply(1000)
.setTransactionId(TransactionId.generate(AccountId.fromString(accountId)))
.setNodeAccountIds([client._network.getNodeAccountIdsForExecute()[0]])
.freezeWith(client)
)
.execute(client);

const createReceipt = await tokenCreate.getReceipt(client);
const tokenId = createReceipt.tokenId;
const tokenLongZero = Number(tokenId.num.low).toString(16).padStart(40, '0');

console.log(`Token created: id: ${tokenId.toString()} | long zero address: ${tokenLongZero}`);
console.log('===========================');

{
console.log('Calling balanceOf with an evmAddress in the function params');
const contractCallQuery = new ContractCallQuery()
.setContractId(ContractId.fromEvmAddress(0, 0, tokenLongZero))
.setGas(30000);

const data = `70a08231000000000000000000000000${evmAddress}`;

contractCallQuery.setFunctionParameters(Buffer.from(data, 'hex'));
contractCallQuery.setPaymentTransactionId(TransactionId.generate(AccountId.fromString(accountId)));
const result = await contractCallQuery
.execute(client)

console.log(Buffer.from(result.asBytes()).toString('hex')); // returns result
}

console.log('===========================');

{
console.log('Calling balanceOf with a long-zero address in the function params');
const contractCallQuery = new ContractCallQuery()
.setContractId(ContractId.fromEvmAddress(0, 0, tokenLongZero))
.setGas(30000);

const data = `70a08231000000000000000000000000${longZeroAddress}`;

contractCallQuery.setFunctionParameters(Buffer.from(data, 'hex'));
contractCallQuery.setPaymentTransactionId(TransactionId.generate(AccountId.fromString(accountId)));
const result = await contractCallQuery
.execute(client)

console.log(Buffer.from(result.asBytes()).toString('hex')); // returns CONTRACT_REVERT_EXECUTED
}

})();
```
```

### Hedera network

other

### Version

0.36.0-alpha.1

### Operating system

Linux

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.