Skip to content

Commit

Permalink
Check empty provides tags when decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaka committed Dec 27, 2023
1 parent eeef70a commit 8fd0c63
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 18 deletions.
3 changes: 2 additions & 1 deletion lib/src/transactions/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ fn valid_transaction(bytes: &[u8]) -> nom::IResult<&[u8], ValidTransaction> {
nom::sequence::tuple((
nom::number::streaming::le_u64,
tags,
tags,
// TODO: maybe show by strong typing the fact that the provide tags are never empty
nom::combinator::verify(tags, |provides: &Vec<Vec<u8>>| !provides.is_empty()),
nom::combinator::map_opt(nom::number::streaming::le_u64, NonZeroU64::new),
util::nom_bool_decode,
)),
Expand Down
19 changes: 2 additions & 17 deletions light-base/src/transactions_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,6 @@ pub enum ValidateTransactionError {
WasmExecution(runtime_host::ErrorDetail),
/// Error while decoding the output of the runtime.
OutputDecodeError(validate::DecodeError),
/// The list of provided tags ([`ValidTransaction::provides`]) is empty. It is mandatory for
/// the runtime to always provide a non-empty list of tags. This error is consequently a bug
/// in the runtime.
EmptyProvidedTags,
/// Runtime called a forbidden host function.
ForbiddenHostCall,
}
Expand Down Expand Up @@ -1360,6 +1356,7 @@ async fn validate_transaction<TPlat: PlatformRef>(
}
};

// TODO: move somewhere else?
log::debug!(
target: log_target,
"TxValidations <= Start(tx={}, block={}, block_height={})",
Expand All @@ -1378,7 +1375,6 @@ async fn validate_transaction<TPlat: PlatformRef>(
let (runtime_call_lock, runtime) = runtime_lock
.start(
validate::VALIDATION_FUNCTION_NAME,
// TODO: don't hardcode v3 but determine parameters dynamically from the runtime
validate::validate_transaction_runtime_parameters_v3(
iter::once(scale_encoded_transaction.as_ref()),
source,
Expand Down Expand Up @@ -1434,18 +1430,7 @@ async fn validate_transaction<TPlat: PlatformRef>(
);
runtime_call_lock.unlock(success.virtual_machine.into_prototype());
return match decode_result {
Ok(Ok(decoded)) => {
if decoded.provides.is_empty() {
// TODO: this check should be performed by the validate module
return Err(ValidationError::InvalidOrError(
InvalidOrError::ValidateError(
ValidateTransactionError::EmptyProvidedTags,
),
));
}

Ok(decoded)
}
Ok(Ok(decoded)) => Ok(decoded),
Ok(Err(err)) => Err(ValidationError::InvalidOrError(InvalidOrError::Invalid(
err,
))),
Expand Down

0 comments on commit 8fd0c63

Please sign in to comment.