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

toSolidityAddress - Does not work for correctly for “native” EVM addresses #1680

Closed
se7enarianelabs opened this issue Dec 15, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@se7enarianelabs
Copy link

se7enarianelabs commented Dec 15, 2023

Description

When you have a Hedera account, such as 0.0.104225, that possesses a 'native' EVM address, utilizing the toSolidityAddress method on such an AccountId results in an incorrect solidity address. This discrepancy can potentially introduce bugs in the services that make use of it. Currently, it is necessary to retrieve the value of the EVM address from the mirror node to handle all accounts without relying on conditional statements. In our opinion, an SDK method should internally handle different cases, as the current approach may introduce bugs in the services that rely on it

Steps to reproduce

Run this function:

java
/**
 * Extract the Solidity address.
 *
 * @return the Solidity address as a string
 */
public String toSolidityAddress()

on this account: 0.0.104225

Additional context

Method: AccountId.fromString("0.0.104225").toSolidityAddress();
Expected: 0x87a8a5c124577bcca68ba44dd12c76d3e427805a
Actual: 0x0000000000000000000000000000000000019721

Hedera network

mainnet, testnet, previewnet

Version

v2.18.2

Operating system

None

@se7enarianelabs se7enarianelabs added the bug Something isn't working label Dec 15, 2023
@Ashe-Oro
Copy link

since the method toSolidityAddress() is effectively a DEC-to-HEX conversion, it will not return the expected solidity address if it was generated natively based on the user's keys.

Only solidity address which are derived from the 0.0.xxxx accountId type will be successfully returned.

See the reproducible example included in the original issue.

@Nana-EC
Copy link

Nana-EC commented Dec 19, 2023

I'd argue that toSolidityAddress() functions by design and returns the account id in a 20 byte address format.
I think what you want is toEvmAddress(). This requires a Mirror Node query though as you're aware as it likely why the method is currently missing.

SDK would have to make a call to api/v1/accounts/<accountId>?limit=1 and retrieve evm_address

FYI @ochikov

@thenswan
Copy link
Contributor

Closing it due to inactivity. Would like to mention that there is an AccountId.populateAccountEvmAddress method that seems to be relevant.

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
None yet
Development

No branches or pull requests

4 participants