From 15e9cedc0d88560712e6fbb887288d45d2c6313c Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 27 Jan 2022 12:50:01 +0000 Subject: [PATCH] test_ed25519 fails if we randomly select index 1 (#22780) (cherry picked from commit c1b543c74d18e1342f57756a38e6c956ee2711c0) Co-authored-by: Sean Young --- sdk/src/ed25519_instruction.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sdk/src/ed25519_instruction.rs b/sdk/src/ed25519_instruction.rs index f06ac6560e..5c78523dfc 100644 --- a/sdk/src/ed25519_instruction.rs +++ b/sdk/src/ed25519_instruction.rs @@ -94,6 +94,7 @@ pub fn verify( 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(PrecompileError::InvalidInstructionDataSize); } @@ -359,7 +360,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],