nearcore icon indicating copy to clipboard operation
nearcore copied to clipboard

logic: improve test coverage and error messages of ed25519_verify

Open blasrodri opened this issue 2 years ago • 1 comments

ref: #7567

blasrodri avatar Oct 11 '22 07:10 blasrodri

(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.

blasrodri avatar Oct 11 '22 07:10 blasrodri

tests failures seem legit

matklad avatar Oct 19 '22 17:10 matklad

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

blasrodri avatar Oct 19 '22 23:10 blasrodri

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

matklad avatar Oct 24 '22 14:10 matklad