Overflow Risk Mitigation in Merkle Sum Trees Using keccak256 #289
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem Statement
@bbresearcher has identified a potential security risk related to overflow in the Merkle sum tree.
This theoretical issue could allow a Prover to generate identical identities for different users under certain conditions, despite having unique usernames.
For example:
0x30644e72e131a029b85045b68181585d2833e84879b9709143e1f593f0000002
0x1
In scenarios where both users have the same currency amount, a malicious Prover could exploit this flaw to provide the same cryptographic proof to different users.
Proposed Changes
To address this vulnerability, we propose the following change, as suggested by @alxkzmn :
keccak256
for Hashing Usernames: Implementingkeccak256
to hash usernames significantly enhances collision resistance. This measure is crucial given the assumption of a global cryptocurrency user base of approximatelyImpact on Security
keccak256
, we greatly reduce the risk of username collision. The probability of two usernames resulting in the same hash is approximatelyThis ensures that each username has a unique and secure identity within the MST.
hashed_username
utilizes the full 256 bits produced bykeccak256
. However, to meet the requirements of the Poseidon hash function used in subsequent cryptographic processes, this output is subjected to a modulo operation to fit within the finite field (Fp
) of 254 bits.This adjustment effectively reduces the bit length by approximately 2 bits, yet this reduction does not meaningfully impact the overall security.
Computational Feasibility
Even with a powerful hashing capability of$2^{30}$ hashes per second, the time required to encounter a duplicate hash result by chance would be about $2.7 \times 10^{21}$ years.
$T = \frac{2^{127}}{2^{30}} \text{ seconds} $
This is calculated using the formula:
where$2^{127}$ is the estimated number of attempts needed to find a collision based on the birthday paradox, highlighting the impracticality of such an event.