From b41f046bf079d2e230e307e79c1b39249656fc3b Mon Sep 17 00:00:00 2001 From: Kevin <105028215+movekevin@users.noreply.github.com> Date: Tue, 13 Jun 2023 20:03:23 -0500 Subject: [PATCH] Fix the order of signer and non-signer tx arg validation to maintain backward compatibility (#8649) --- .../verifier/transaction_arg_validation.rs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/aptos-move/aptos-vm/src/verifier/transaction_arg_validation.rs b/aptos-move/aptos-vm/src/verifier/transaction_arg_validation.rs index ec00229ebe57d4..3807eceb29e4d5 100644 --- a/aptos-move/aptos-vm/src/verifier/transaction_arg_validation.rs +++ b/aptos-move/aptos-vm/src/verifier/transaction_arg_validation.rs @@ -149,6 +149,20 @@ pub(crate) fn validate_combine_signer_and_txn_args( )); } + // If the invoked function expects one or more signers, we need to check that the number of + // signers actually passed is matching first to maintain backward compatibility before + // moving on to the validation of non-signer args. + // the number of txn senders should be the same number of signers + if signer_param_cnt > 0 && senders.len() != signer_param_cnt { + return Err(VMStatus::Error( + StatusCode::NUMBER_OF_SIGNER_ARGUMENTS_MISMATCH, + None, + )); + } + + // This also validates that the args are valid. If they are structs, they have to be allowed + // and must be constructed successfully. If construction fails, this would fail with a + // FAILED_TO_DESERIALIZE_ARGUMENT error. let args = construct_args( session, &func.parameters[signer_param_cnt..], @@ -158,19 +172,10 @@ pub(crate) fn validate_combine_signer_and_txn_args( false, )?; - // if function doesn't require signer, we reuse txn args - // if the function require signer, we check senders number same as signers - // and then combine senders with txn args. + // Combine signer and non-signer arguments. let combined_args = if signer_param_cnt == 0 { args } else { - // the number of txn senders should be the same number of signers - if senders.len() != signer_param_cnt { - return Err(VMStatus::Error( - StatusCode::NUMBER_OF_SIGNER_ARGUMENTS_MISMATCH, - None, - )); - } senders .into_iter() .map(|s| MoveValue::Signer(s).simple_serialize().unwrap())