Currently not exploitable because this bug is cancelled out by another issue (see my Gas report). If the other issue is fixed validateSignature will return completely incorrect values.
This has been working so far only because the EllipticCurve performs a redundant chain of immediate conversions projective->affine->projective->affine and so during that last conversion $Z = 1$. Should the chain of redundant conversions be fixed, validateSignature will no longer work correctly.
I agree that EllipticCurve.sol is somewhat of a bodge. It’s correct what the warden says in that ”EllipticCurve mixes up” something. But actually it adds affine points and then trivially converts them to jacobian/projective coordinates. Since they are trivial they are the same in jacobian as in projective, so one could say that it’s as much a misnamed function as a confused computation.
But it’s also correct what the warden himself said that it is “currently not exploitable”. In fact, I’m quite sure it’s not exploitable even if “the other issue is fixed”. Then it will just invalidate every signature.
Both recommendations here are therefore just gas savings and refactoring. mulmod(Px, Px, p) is indeed a redundant computation, because Px == 1 always here. But so is inverseMod(P[2], p) redundant. The first recommendation can be simplified even further to just
The second recommendation is a better optimisation but still does redundant conversions in multiplyScalar, which also should be corrected then. The whole point of using projective coordinates is to do the modular inverse (i.e. convert to affine) only at the end.
In any case, there is nothing exploitable here, no funds or functionality are at risk. The code does what it’s supposed to do as it is, just not in the prettiest way. And the way in which the hypothetical issue is proposed to arise is by fixing the very same thing that the hypothetical issue is itself based on, i.e. it is said that fixing the needless conversion between coordinate representations causes an error due to coordinate conversions. One should assume that reworking the coordinate handling would fix all coordinate issues. And if the bug described here were to arise in the suggested manner, it would be immediately noticed in testing.
This is a bug that is not yet a bug but could be a bug that is impossible to miss if someone were to create this bug so it’s never going to actually be a bug.
I think this is a good catch, but the severity is only QA/Gas.
I agree with @d3e4 that the bug is highly unlikely to make it to production without being caught. In this case, however, if it were to make it into production, the “function of the protocol or availability could be impacted”. That makes this a valid medium in my view. I agree with the warden and sponsor.
The original report as published on Code4rena, by Holmgren. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
What is known
A medium-severity crypto bug in ENS. Code4rena made it public on 31 August 2023. Found in the 2023-04-ens audit contest (finding M-06), also found by 1 other warden.
About Crypto
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
What is Crypto?
Encryption, signatures, randomness or certificate checks that do not protect what they claim to.