Skip to content

Commit

Permalink
clearer feature gating for keyless TXNs
Browse files Browse the repository at this point in the history
  • Loading branch information
alinush committed Feb 29, 2024
1 parent cd35002 commit 0bba2e8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
15 changes: 14 additions & 1 deletion aptos-move/aptos-vm/src/aptos_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,20 @@ impl AptosVM {

let authenticators = aptos_types::keyless::get_authenticators(transaction)
.map_err(|_| VMStatus::error(StatusCode::INVALID_SIGNATURE, None))?;
keyless_validation::validate_authenticators(&authenticators, self.features(), resolver)?;

// If there are keyless TXN authenticators, validate them all.
if !authenticators.is_empty() {
// Feature-gating keyless TXNs: if they are *not* enabled, return `FEATURE_UNDER_GATING`,
// which will discard the TXN from being put on-chain.
if !self.features().is_keyless_enabled() {
return Err(VMStatus::error(StatusCode::FEATURE_UNDER_GATING, None));
}
keyless_validation::validate_authenticators(
&authenticators,
self.features(),
resolver,
)?;
}

// The prologue MUST be run AFTER any validation. Otherwise you may run prologue and hit
// SEQUENCE_NUMBER_TOO_NEW if there is more than one transaction from the same sender and
Expand Down
15 changes: 5 additions & 10 deletions aptos-move/aptos-vm/src/keyless_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,17 @@ pub(crate) fn validate_authenticators(
features: &Features,
resolver: &impl AptosMoveResolver,
) -> Result<(), VMStatus> {
// Feature gating
for (_, sig) in authenticators {
if !features.is_keyless_enabled() && matches!(sig.sig, ZkpOrOpenIdSig::Groth16Zkp { .. }) {
return Err(VMStatus::error(StatusCode::FEATURE_UNDER_GATING, None));
}
if (!features.is_keyless_enabled() || !features.is_keyless_zkless_enabled())
&& matches!(sig.sig, ZkpOrOpenIdSig::OpenIdSig { .. })
// Feature-gating for keyless-but-zkless TXNs: If keyless TXNs *are* enabled, and (1) this
// is a ZKless transaction but (2) ZKless TXNs are not yet enabled, discard the TXN from
// being put on-chain.
if matches!(sig.sig, ZkpOrOpenIdSig::OpenIdSig { .. })
&& !features.is_keyless_zkless_enabled()
{
return Err(VMStatus::error(StatusCode::FEATURE_UNDER_GATING, None));
}
}

if authenticators.is_empty() {
return Ok(());
}

let config = &get_configs_onchain(resolver)?;
if authenticators.len() > config.max_signatures_per_txn as usize {
return Err(invalid_signature!("Too many keyless authenticators"));
Expand Down

0 comments on commit 0bba2e8

Please sign in to comment.