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

Incorrect Usage of Strings.toHexString Without Proper Address Conversion in Two Files #386

Open
Himess opened this issue Jan 23, 2025 · 0 comments · May be fixed by #387
Open

Incorrect Usage of Strings.toHexString Without Proper Address Conversion in Two Files #386

Himess opened this issue Jan 23, 2025 · 0 comments · May be fixed by #387
Labels
bug Something isn't working

Comments

@Himess
Copy link

Himess commented Jan 23, 2025

Description and Context
The issue occurs in two files: MockAllMetadataViewModule.sol and MockCoreMetadataViewModule.sol, where Strings.toHexString is used incorrectly for address type variables (ipId and owner(ipId)).

Problem:
The Strings.toHexString function expects a uint256 input, but the ipId and owner(ipId) variables are of type address. Directly passing an address type without converting it to uint256 will lead to unexpected behavior or compilation issues.

Test
The issue was validated by running tests to confirm the improper usage of Strings.toHexString. Below are the details of the steps taken and the observed outputs:
Steps:
-Created a test case to use Strings.toHexString directly with an address type variable (ipId).
-Observed the compilation error due to the incorrect type conversion.
Observed Output:
Compilation error when directly using Strings.toHexString(ipId) without conversion.
Image

Steps to Reproduce
1- In MockAllMetadataViewModule.sol:

Locate the tokenURI function.
Find the following incorrect usage:

Strings.toHexString(ipId);
Strings.toHexString(owner(ipId));

2- In MockCoreMetadataViewModule.sol:
Locate the tokenURI and description functions.
Find the following incorrect usage:
Strings.toHexString(ipId);
Strings.toHexString(owner(ipId));

3-Attempt to compile or execute functions that use Strings.toHexString with address type inputs without proper conversion.

Experienced Behavior
The Strings.toHexString function is used incorrectly with address variables, causing compilation errors or incorrect results.

Expected Behavior
The Strings.toHexString function should correctly convert an address variable to a hexadecimal string by first casting it to uint160.

Solution Recommendation
The solution is to cast the address type variables (ipId and owner(ipId)) to uint160 before passing them to Strings.toHexString.

File: MockAllMetadataViewModule.sol

Incorrect Usage:
Strings.toHexString(ipId);
Strings.toHexString(owner(ipId));

Correct Usage:
Strings.toHexString(uint160(ipId));
Strings.toHexString(uint160(owner(ipId)));

File: MockCoreMetadataViewModule.sol
Incorrect Usage:
Strings.toHexString(ipId);
Strings.toHexString(owner(ipId));

Correct Usage:
Strings.toHexString(uint160(ipId));
Strings.toHexString(uint160(owner(ipId)));

@Himess Himess added the bug Something isn't working label Jan 23, 2025
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

Successfully merging a pull request may close this issue.

1 participant