chiru-labs / ERC721A

https://ERC721A.org
MIT License
2.51k stars 843 forks source link

Question regarding bit masks #425

Closed Walodja1987 closed 2 years ago

Walodja1987 commented 2 years ago

Hi,

I have seen Bit masks being used in connection with inline assembly. I've seen it done in the 0x protocol repo and also in this repo. I was not able to find the answer on the web why this is done.

I know what a bit mask is and that the and operation renders any byte outside of the corresponding range to zero. My question is why this is needed, i.e. in which case would an address written into a memory slot have the remaining 96 bytes not all being zero?

Appreciate your help as I am trying to implement something very similar to 0x protocol for my project (DIVA Protocol) and want to make sure I fully understand it.

Walodja1987 commented 2 years ago

Ok, I found an answer after receiving the hint to search for ”dirty upper bits“: https://docs.soliditylang.org/en/v0.8.17/security-considerations.html#minor-details