nearcore
nearcore copied to clipboard
logic: improve test coverage and error messages of ed25519_verify
ref: #7567
(from https://github.com/near/NEPs/pull/364#issuecomment-1238147491)
Second, even if the length is correct, the key or signature might still be considered invalid due to this conditions: https://docs.rs/ed25519-dalek/latest/src/ed25519_dalek/public.rs.html#142 https://docs.rs/ed25519/latest/src/ed25519/lib.rs.html#302 In the case of invalid signature, I am somewhat confident that the right approach is just return false. It seems logical that, if the signature is trivially invalid, than it's just an invalid signature.
I'm not sure how to split the error between the second and the first part. I believe returning an error mentioning the the input is invalid is a valid solution.
tests failures seem legit
tests failures seem legit
When applying the following diff
diff --git a/runtime/near-vm-logic/src/tests/miscs.rs b/runtime/near-vm-logic/src/tests/miscs.rs
index aca82c686..06ce87204 100644
--- a/runtime/near-vm-logic/src/tests/miscs.rs
+++ b/runtime/near-vm-logic/src/tests/miscs.rs
@@ -998,7 +998,7 @@ fn test_ed25519_verify() {
assert_eq!(result, expected_result);
assert_costs(map! {
- ExtCosts::read_memory_byte: 128,
+ ExtCosts::read_memory_byte: 127,
ExtCosts::read_memory_base: 3,
ExtCosts::ed25519_verify_base: 1,
ExtCosts::ed25519_verify_byte: 32,
I get (locally)
failures:
---- tests::miscs::test_ed25519_verify stdout ----
thread 'tests::miscs::test_ed25519_verify' panicked at 'assertion failed: `(left == right)`
left: `{ed25519_verify_byte: 32, read_memory_byte: 128, ed25519_verify_base: 1, read_memory_base: 3}`,
right: `{ed25519_verify_byte: 32, read_memory_byte: 127, read_memory_base: 3, ed25519_verify_base: 1}`', runtime/near-vm-logic/src/tests/helpers.rs:119:32
Whereas CI is failing saying that read_memory_byte: 127
Ref: https://buildkite.com/nearprotocol/nearcore/builds/21180#0183e7ff-119e-4404-893a-e960638fb283/97-1623
Running cargo t -p near-vm-logic --all-features test_ed25519_verify
reproduces the failure locally for me. Looks like something is order dependent.
A good way to debug these kinds of issues is trying to run the exact command that the CI is running, which is printed here:
https://buildkite.com/nearprotocol/nearcore/builds/21180#0183e7ff-119e-4404-893a-e960638fb283/97-101