in gamma, VaultReader.sol is used to retrieve vital values from the datastore, These values such as the positioninfo and the pnl are used throughout the protocol to carry out various operations but the functions that hashes the positionkey and retrieves the value from the datastore is not written properly leading to a wrong hash being generated thereby returning zero or wrong values from the datastore
The exact functions that are used in VaultReader.sol to retrieve these values from datastore are;
[Link to sample code](https://github.com/CodeHawks-Contests/2025-02-gamma/blob/84b9da452fc84762378481fa39b4087b10bab5e0/contracts/VaultReader.sol#L192-L209)
it can be seen that in the hashing the key value is placed before the hash identifier SIZE_IN_USD and SIZE_IN_TOKENS respectively but this is inconsistent with the way hashing for datastore queries are done in other places in the protocol and even with gmx.
It can be seen here that the hash identifier is always before the value being hashed
Sample link
The hashes generated in VaultReader.sol will therefore be wrong as it doesn't match the with way it were hashed and stored in datastore leading to zero values constantly being returned (as datastore is a mapping)
The VaultReader.sol itself becomes useless as wrong values are always returned
The values returned by these flawed functions are further to used to generate very important data used throughout the perpetualvault and protocol, leading to wrong states and bricking of vital operations.
Manual Review
write the mentioned functions to have the identifier first, ensuring correct hash results.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.