Fix unset internal function pointer retrieval from packed storage slot with a subsequent non-zero variable - #16776
Conversation
af2e5cb to
fe6c6bd
Compare
fe6c6bd to
fc400a5
Compare
fc400a5 to
0eae968
Compare
| if (type->category() == Type::Category::UserDefinedValueType) | ||
| type = type->encodingType(); | ||
| bool cleaned = false; | ||
| // shift bytes to the right positioning the function pointer at the start of the slot |
There was a problem hiding this comment.
I am a bit confused about this comment. retrieveValue is a general method, no? It deals with all types, not only function pointers.
There was a problem hiding this comment.
Yes, true. I guess I got to much focused on function pointers at the time 😅
I will change it to state variable, ok?
| // shift bytes to the right positioning the function pointer at the start of the slot | ||
| m_context | ||
| << Instruction::SWAP1 << s_loadInstruction << Instruction::SWAP1 | ||
| << u256(0x100) << Instruction::EXP << Instruction::SWAP1 << Instruction::DIV; |
There was a problem hiding this comment.
Side note: If this is supposed to do shift, it does not need to use EXP instruction for that.
There was a problem hiding this comment.
DIV does the right shifting. I am trying to remember exactly, but I think that EXP is just telling by how much you shift.
I will confirm this.
There was a problem hiding this comment.
Also, just for clarity, I think this uses DIV (and other places MUL) because shift opcodes were introduced in later EVM versions.
There was a problem hiding this comment.
I had "decoded" this before, but it was used with MUL in another place.
The variable offset is given in bytes, EXP 0x100, offset computes the amount of bits to shift when using DIV.
256^offset = (2^8)^offset = 2^8 * offset.
When the bytes of the slot are divided by this value, it is equivalent to shifting it 8 * offset bits to the right.
0eae968 to
7f82e49
Compare
Fix #16775.