Improper Address Alignment in to_address Function Leading to Potential Address Spoofing[AddressCast.sol::to_address()] #406
Labels
bug
Something isn't working
downgraded by judge
Judge downgraded the risk level of this issue
duplicate-157
grade-b
Q-06
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
🤖_46_group
AI based duplicate group recommendation
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-08-chakra/blob/d0d45ae1d26ca1b87034e67180fac07ce9642fd9/solidity/handler/contracts/libraries/AddressCast.sol#L14-L18
Vulnerability details
Impact
This vulnerability allows incoming bytes32 addresses to not be checked or processed in the expected format. The contract does not verify whether the address is aligned on the left or right end, resulting in potential incorrect address conversion. An attacker may manipulate the contract logic by forging bytes32 addresses, causing invalid addresses to be considered valid, thereby affecting key functions of the contract, such as fund transfer or permission verification.
Proof of Concept
Link1: https://github.com/code-423n4/2024-08-chakra/blob/d0d45ae1d26ca1b87034e67180fac07ce9642fd9/solidity/handler/contracts/libraries/AddressCast.sol#L14-L18
Link2: https://github.com/code-423n4/2024-08-chakra/blob/d0d45ae1d26ca1b87034e67180fac07ce9642fd9/solidity/settlement/contracts/libraries/AddressCast.sol#L22-L26
This function directly converts bytes32 to address, but does not verify whether the address in bytes32 is aligned on the correct side. Since Solidity addresses are of type uint160 and bytes32 is of type uint256, if the user does not strictly follow the correct alignment, the bytes32 type address conversion will fail if the address is left-aligned, leading to serious security issues.
Steps to reproduce:
0x5B38Da6a701c568545dCfcB03FcB875f56beddC4
0x3fCb875F56bEDdc4000000000000000000000000
From the results, we can see that after the conversion by the
to_address(bytes32 _address)
function, the caller msg.sender and the output result are completely different, which is absolutely not allowed.Tools Used
Recommended Mitigation Steps
To prevent this vulnerability, you need to check whether bytes32 conforms to the valid uint160 address format during address conversion and specify the alignment of the address in bytes32 data. This can be fixed by:
Assessed type
Decimal
The text was updated successfully, but these errors were encountered: