6 ms·
"Check the first 4 bytes of" should be banned in crypto code. Either I want something to match, in which case check it all, or I don't care if it matches, in w
by londons_explore 5y ago
"Check the first 4 bytes of" should be banned in crypto code.
Either I want something to match, in which case check it all, or I don't care if it matches, in which case don't check at all.
Why would you ever check 4 bytes?
To me it smells like a way to prevent fuzzers stumbling on a deliberate loophole.
- et2o 5y agoThis is perhaps the most confusing element of it all, to me. I can hardly imagine a legitimate reason to do this. Defeats entirely the purpose of a hash.
- ed_elliott_asc 5y agoChecking whole hash was probably too slow, you can imagine they put in a check for first four bytes, if that matched then check the whole hash - probably merge conflict and lost the second bit - doesn’t seem too far fetched!
- thrwawy4345784 5y agoMaybe somebody thought of short sha-1 id's of git: https://git-scm.com/book/en/v2/Git-Tools-Revision-Selection https://git-scm.com/book/en/v2/Git-Tools-Revision-Selection With that only 4 chars is enough to identify a commit :-)
- cesarb 5y agoIf I understood it correctly, the purpose of this hash is just to shorten the method signature (name+types) to a 4 byte identifier. Unless a contract has thousands of methods, the chance of collision is very low (and the compiler could detect any collision, since it can see all methods). The "legitimate reason" for shortening the method signature is probably just to save space; bytes on distributed blockchain transactions are expensive.
- abstractbarista 5y agoThis blew me away. That's 2^32. They took a cryptographic hash, with good preimage/second-preimage/collision resistance, and then discarded 7/8 of it before comparing to ensure some user-provided input is valid. What in the world?!