RareSkills / Udemy-Yul-Code

54 stars 36 forks source link

Video-05-Storage-2.sol - Use of 0xffff seems ambiguous #4

Open zaryab2000 opened 1 year ago

zaryab2000 commented 1 year ago

The readE() function includes masking at the very end, to get the exact value of E state variable.

However, it uses 0xffff specifically, to mask the shifted value, while the same can be achieved using just 0xf.

https://github.com/RareSkills/Udemy-Yul-Code/blob/17aec03882dd951b0d15707d71b6ab38626d853c/Video-05-Storage-2.sol#L66

Questions

jeffreyscholz commented 1 year ago

Thanks for adding this! This is to show the 1 in

https://github.com/RareSkills/Udemy-Yul-Code/blob/17aec03882dd951b0d15707d71b6ab38626d853c/Video-05-Storage-2.sol#L63

Get's ignored.

zaryab2000 commented 1 year ago

hey @jeffreyscholz ,

Just to be very sure, our aim is to mask the entire thing and only get the value stored in State variable E, correct?

If that's the case, we can AND this entire thing with just "0xf", isn't it? e := and(0xffff, shifted)

Why do we need to SHOW the 1 in 0x0000000000000000000000000000000000000000000000000000000000010008

walkerford commented 9 months ago

e is a uint16 (2 bytes), so it is appropriate to use a mask with 2 bytes (0xFFFF). If e happened to be a number that is larger than 255, then you would want to also capture the upper byte. Using only 0xFF would erase the top byte of e.