Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the order of signer and non-signer tx arg validation to maintain backward compatibility #8649

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions aptos-move/aptos-vm/src/verifier/transaction_arg_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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..],
Expand All @@ -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())
Expand Down