From 92cc75b3ae9ea4b344f4a43dba29d0d0e0c6baf0 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 27 Jan 2022 13:02:42 +0000 Subject: [PATCH] test_ed25519 fails if we randomly select index 1 (#22779) (cherry picked from commit c1b543c74d18e1342f57756a38e6c956ee2711c0) # Conflicts: # sdk/src/ed25519_instruction.rs Co-authored-by: Sean Young --- programs/ed25519/src/lib.rs | 9 ++++++++- sdk/src/ed25519_instruction.rs | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/programs/ed25519/src/lib.rs b/programs/ed25519/src/lib.rs index b0496f02cf..7f4dc8b730 100644 --- a/programs/ed25519/src/lib.rs +++ b/programs/ed25519/src/lib.rs @@ -44,7 +44,14 @@ pub mod test { assert!(tx.verify_precompiles(&feature_set).is_ok()); - let index = thread_rng().gen_range(0, instruction.data.len()); + let index = loop { + let index = thread_rng().gen_range(0, instruction.data.len()); + // byte 1 is not used, so this would not cause the verify to fail + if index != 1 { + break index; + } + }; + instruction.data[index] = instruction.data[index].wrapping_add(12); let tx = Transaction::new_signed_with_payer( &[instruction], diff --git a/sdk/src/ed25519_instruction.rs b/sdk/src/ed25519_instruction.rs index 911b31e80b..ae7a3c9395 100644 --- a/sdk/src/ed25519_instruction.rs +++ b/sdk/src/ed25519_instruction.rs @@ -108,6 +108,7 @@ pub fn verify_signatures(data: &[u8], instruction_datas: &[&[u8]]) -> Result<(), let expected_data_size = num_signatures .saturating_mul(SIGNATURE_OFFSETS_SERIALIZED_SIZE) .saturating_add(SIGNATURE_OFFSETS_START); + // We do not check or use the byte at data[1] if data.len() < expected_data_size { return Err(Ed25519Error::InvalidInstructionDataSize); }