Closed sherlock-admin2 closed 3 months ago
This is an intellectually interesting bug however I have a few problems with it, and would like further justification from the submitter before I can acknowledge this to be a real bug:
Encode
is nil so an error would occur when trying to call it, and even if you corrected those issues, I am not able to find a way to compile the repo with a nil value passed to Join4
- I get a compiler error CannotInferTypeArgs
That said I can add a PR that throws an error from Encoding if any component is nil: https://github.com/allora-network/allora-chain/pull/467
The protocol team fixed this issue in the following PRs/commits: https://github.com/allora-network/allora-chain/pull/467
request poc
PoC requested from @Minato7namikazi
Requests remaining: 6
After digging some into the failing tests, it appears encoding nil values is a necessary feature if you want to support nil rangers that will iterate over all keys
I'm inclined to call this a wontfix until theres some substantiated bug that can actually clearly demonstrate a problem
Minato7namikazi
High
Logic Bug in the
QuadrupleKeyCodec
ImplementationVulnerability Detail
in the
QuadrupleKeyCodec
implementation regarding how it handles nil values in theEncode
andDecode
methods.The Issue
Encode
: When encoding aQuadruple
key, if one of the key parts (e.g.,key.k2
) is nil, the code directly proceeds to encode the next key part using the previouswrittenTotal
. This means that no space is reserved in thebuffer
for the nil key part, leading to incorrect encoding.Decode
: Similarly, during decoding, if a key part is nil, the code still attempts to decode the subsequent parts, potentially leading to data misalignment and incorrect key reconstruction.impact
This bug can lead to data corruption and inconsistencies in the underlying storage. It may cause:
Code Snippet
https://github.com/sherlock-audit/2024-06-allora/blob/main/allora-chain/x/emissions/keeper/quadruple.go#L206
Tool used
Manual Review
Recommendation
we need to modify the
Encode
andDecode
methods to correctly handle nil key parts. ensures that the encoded representation of theQuadruple
key accurately reflects the presence or absence of each key part.PoC
Explanation
QuadrupleKeyCodec
using the sample codecs.Quadruple
key where the third part (k3
) is intentionally set to nil.QuadrupleKeyCodec
.Quadruple
key.QuadrupleKeyCodec
implementation.Expected Output
The test should initially fail due to the incorrect handling of the nil value in the original
QuadrupleKeyCodec.Encode
andQuadrupleKeyCodec.Decode
methods.