Can you convert a bytes20 to address in assembly (not solidity-typecasting)?
If so, how?
Can you convert a bytes20 to address in assembly (not solidity-typecasting)?
If so, how?
SOLUTION:
If the address is in the first bytes, you can do:
assembly {
parsed := shr(96, mload(add(data, 32)))
}
With this, you right-shift 96 bits (or 12 bytes), and then assign to an address type.
This solution won't work if you assign to a bytes20 because bytes20 grabs the highest bytes while address the lowest.
Yep, heres an example of what the function might look like:
function convertBytes20ToAddress(bytes bytesInput) internal returns (address addressOutput) {
assembly {
addressOutput := mload(add(bytesInput,20))
}
}
assembly { parsed := shr(96, mload(add(data, 32))) } . I found the answer a couple of days ago, but forgot to update it here. Doing that right now.
– dNyrM Jan 24 '23 at 14:24