-
Notifications
You must be signed in to change notification settings - Fork 838
chore: upgrade noble curves #4179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
I have this worked out so that the tests pass, i'm just doing some extra double-checking to make sure I didn't change anything unintentionally.
|
Seems like there is a few vm-state tests still failing. Haven't yet been able to nail down what's wrong, |
…umjs/ethereumjs-monorepo into chore/upgrade-noble-2.0.1
|
Although lowS: false makes signatures trivially malleable. Ethereum has fixed it in EIP-2 for secp256k1, but p256 has been left unattented for now. |
|
@holgerd77 I suggest increasing priority of merging this to get it into the next minor / patch release, in order to not duplicate user code between old/new noble in the future. I'm available for a help. |
|
@paulmillr Ok, thanks for your help offer, yes, aggree that it makes sense to prioritize a bit, also regarding the imminent Fusaka hardfork with some emphasis on p256. Added the |
|
To re-iterate here, the most lightweight to continue is likely to use the Osaka tests - currently not integrated into the full blockchain/state test run (which is actually an interesting insight, that this none-integration is actually useful, we might want to consider this when seeing how/if to integrate 🤔 (side thought)), so this would be: npm run test:osaka:stateCurrent result of this, with various "errors thrown in file": 1..1113
# tests 1113
# pass 895
# fail 218A dedicated test run would be (so this long thing from npm run test:osaka:state -- --test='tests/osaka/eip7951_p256verify_precompiles/test_p256verify.py::test_valid[fork_Osaka-state_test--wycheproof/ecdsa_webcrypto_test.json EcdsaP1363Verify SHA-256 #134: s == 1]'Will give this a quick run through the VSCode debugger:
Ok, this is giving @paulmillr let me know if you can already spot anything, otherwise I will try to extract the values used to copy over (I'll convert to hex for easier copy-over): const signature = ''0x555555550000000055555555555555553ef7a8e48d07df81a693439654210c700000000000000000000000000000000000000000000000000000000000000001'
const msgHash = '0x532eaabd9574880dbf76b9b8cc00832c20a6ec113d682299550d7a6e0f345e25'
// bytesToHex(publicKey.toBytes(false))
const pubKey = '0x04e84d9b232e971a43382630f99725e423ec1ecb41e55172e9c69748a03f0d5988618b15b427ad83363bd041ff75fac98ef2ee923714e7d1dfe31753793c7588d4'
// and the we have the `{ lowS: false }` in so the above values would feed (as bytes) the below line in our code:
const isValid = p256.verify(signature, msgHash, publicKey.toBytes(false), { lowS: false })Maybe you can test this out on your side? |
|
@holgerd77 import { p256 } from '@noble/curves/nist.js';
import { hexToBytes } from '@noble/curves/utils.js';
const signature = '555555550000000055555555555555553ef7a8e48d07df81a693439654210c700000000000000000000000000000000000000000000000000000000000000001'
const msgHash = '532eaabd9574880dbf76b9b8cc00832c20a6ec113d682299550d7a6e0f345e25'
const pubKey = '04e84d9b232e971a43382630f99725e423ec1ecb41e55172e9c69748a03f0d5988618b15b427ad83363bd041ff75fac98ef2ee923714e7d1dfe31753793c7588d4'
const isValid = p256.verify(
hexToBytes(signature), hexToBytes(msgHash),
hexToBytes(pubKey),
{ lowS: false, prehash: false }
)
console.log(isValid); |
e565283 to
f52c026
Compare
|
Ah ok. Still not all. But the Osaka tests are fixed now. |
|
Any other specific vector which fails? |
|
@paulmillr yes, now the other tests that fail are the Prague state/blockchain tests for bn254 multiplication, likely related to the changes in this file https://github.com/ethereumjs/ethereumjs-monorepo/pull/4179/files#diff-d8e4e56024eab6bc6446b026499696dcfcc4cbb9b6bdfe6c9fd35e983052d026 respectively not sufficient adoptions. Can you spot anything? |
|
( @paulmillr and if you have time to look over #4192 would also be appreciated (might also point to a bug in Noble), blocking me a bit) |
|
Just validated this -- the bn254 changes are 100% correct. If you could provide a specific test vector, that would be very helpful. Not sure it's related to bn itself. I can take a detailed glance, and debug, but only next week. |
|
That's new security feature; try Scalars >= ORDER are invalid, because finite field (Fr) max value is ORDER. Everything else larger than ORDER should either be mod-divided (what you're doing), or rejected. You're automatically wrapping scalars larger than ORDER here, so validation can be skipped: ethereumjs-monorepo/packages/evm/src/precompiles/bn254/noble.ts Lines 60 to 64 in c2bf887
|
|
@paulmillr This works, cool 🙏 (have now used the |
holgerd77
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM



Fixes #4178