-
Notifications
You must be signed in to change notification settings - Fork 97
Description
In Crypto.sol
the expandMessageXMDKeccak256()
function uses the free memory pointer as a scratch space to build a message that will eventually be hashed. The function does not allocate itself this memory, but expects the memory region to be zero.
hoprnet/ethereum/contracts/src/Crypto.sol
Line 678 in c3230c3
// payload[0..KECCAK256_BLOCKSIZE] = 0 |
However later on in the function a separate part of the code does the something similar and will write to the exact same memory region. This code also doesn't allocate the memory to itself.
hoprnet/ethereum/contracts/src/Crypto.sol
Line 714 in c3230c3
let bIPayload := mload(0x40) |
This doesn't cause an issue if the function is called once, however if the function is called in a loop the second iteration will use the memory that has been polluted by the later code.
Expected Behavior
Memory region pointed at by free memory pointer should be zero before first block of assembly code uses that memory
Current Behavior
Other areas will write to that same memory region in certain circumstances. Causing an incorrect hash.
(Optional) Possible Solution
We did this
which just zeros the memory before use
Metadata
Metadata
Assignees
Type
Projects
Status