visit
I am not a security expert. But I do love Clean Code and Code Smells
TL;DR: don't trust your hashes.
I pay attention to blockchain and security news even though it is far from my comfort zone when writing technical articles.
However, I've written more than 180 code smells and refactorings. From experience, you learn that there's always an unspoken tension between doing things in the right, clean way versus performance optimization.
Blockchains should be fast.
Clean code is not so easily exploitable.
What does matter is that due to the way that hash functions are intended to work, we can basically say with certainty that any (path, nleaf) pair will produce a unique hash. If we want to forge a proof, those will need to stay the same
In summary, there was a bug in the way that the Binance Bridge verified proofs which could have allowed attackers to forge arbitrary messages. Fortunately, the attacker here only forged two messages, but the damage could have been far worse
TL;DR: A hash function was exploited.
Two objects with the same hash might not be the same.
If we override an object's equality, we need to also override the hash.
Use (fast) hash for fast discard, and use (slow) equality to ensure you are right.
How to Find the Stinky parts of your Code
Hashing guarantees two objects are different. Not that they are the same
TL;DR: If you check for the hash, you should also check for equality
public class Person {
public String name;
// Public attributes are another smell
@Override
public boolean equals(Person anotherPerson) {
return name.equals(anotherPerson.name);
}
@Override
public int hashCode() {
return (int)(Math.random()*256);
}
// This is just an example of non correlation
// When using HashMaps we can make a mistake
// and guess the object is not present in the collection
}
public class Person {
public String name;
// Public attributes are another smell
@Override
public boolean equals(Person anotherPerson) {
return name.equals(anotherPerson.name);
}
@Override
public int hashCode() {
return name.hashCode();
}
// This is just an example of non correlation
}
Code Smells are just my opinion.
This will surprise some of your readers, but my primary interest is not with computer security. I am primarily interested in writing software that works as intended.
Wietse Venema