chiru-labs / ERC721A

https://ERC721A.org
MIT License
2.5k stars 839 forks source link

How may not be clean upper bits of `from` address in `transferFrom` function? #476

Closed Lruquaf closed 1 year ago

Lruquaf commented 1 year ago

Is there a redundant convertion on L552?

function transferFrom(
        address from,
        address to,
        uint256 tokenId
    ) public payable virtual override {
        uint256 prevOwnershipPacked = _packedOwnershipOf(tokenId);

        // Mask `from` to the lower 160 bits, in case the upper bits somehow aren't clean.
        from = address(uint160(uint256(uint160(from)) & _BITMASK_ADDRESS));
Vectorized commented 1 year ago

The conversion and cleaning is required for the assembly.

function testCleanAddress(uint256 x) public {
    address from = address(uint160(x));

    // If you comment out this line, the function will revert.
    from = address(uint160(uint256(uint160(from)) & 0x00ffffffffffffffffffffffffffffffffffffffff));

    assembly {
        if shr(160, from) { revert(0, 0) }
    }
}
Lruquaf commented 1 year ago

Thank you!