HomeContact
Solidity
Transform an address in a bytes32 or uint256 in Solidity
April 30, 2023
1 min

Table Of Contents

01
Transform address into uint256
02
Transform address into bytes32
03
Why is it useful?

Knowing how to alter the value of Solidity’s variable is helpful as an audit contractor or hacker. It allows you to pass data into a specific attribute that triggers unexpected behavior. And as a hacker, this is what you are looking for. Changing those using Foundry allows you to test multiple cases and see where it can break.

Transform address into uint256

uint256(uint160(address))

Transform address into bytes32

bytes32(uint256(uint160(address)))

Why is it useful?

Sometimes, you can send an address and store it into a variable that is not supposed to be that. With a proxy implementation, you can trigger unexpected behavior. You can check that on level 16 of Ethernaut, where you can delegatecall to an attacker address using this method.


Tags

blockchainSolidity

Related Posts

The best Web3 browser wallet extensions
October 26, 2022
2 min
© 2023, All Rights Reserved.

Quick Links

Contact Us

Social Media