Skip to content

Commit

Permalink
discard on deposit calculation failure, and new status code
Browse files Browse the repository at this point in the history
  • Loading branch information
zjma committed Apr 17, 2024
1 parent dbb03eb commit cf9ebc5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
23 changes: 15 additions & 8 deletions aptos-move/aptos-vm/src/aptos_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1637,7 +1637,7 @@ impl AptosVM {
&gas_meter.vm_gas_params().txn,
&txn_data,
txn.payload(),
);
)?;
txn_data.set_required_deposit(required_deposit);
self.validate_signed_transaction(session, resolver, txn, &txn_data, log_context)
}));
Expand Down Expand Up @@ -2319,11 +2319,11 @@ impl AptosVM {
txn_gas_params: &TransactionGasParameters,
txn_metadata: &TransactionMetadata,
payload: &TransactionPayload,
) -> Option<u64> {
) -> VMResult<Option<u64>> {
match payload {
TransactionPayload::EntryFunction(entry_func) => {
if self.randomness_enabled
&& has_randomness_attribute(resolver, session, entry_func).unwrap_or(false)
&& has_randomness_attribute(resolver, session, entry_func)?
{
let max_execution_gas: Gas = txn_gas_params
.max_execution_gas
Expand All @@ -2336,14 +2336,14 @@ impl AptosVM {
let cand_1 =
txn_metadata.gas_unit_price * txn_gas_params.maximum_number_of_gas_units;
let required_fee_deposit = min(cand_0, cand_1);
Some(u64::from(required_fee_deposit))
Ok(Some(u64::from(required_fee_deposit)))
} else {
None
Ok(None)
}
},
TransactionPayload::Script(_)
| TransactionPayload::ModuleBundle(_)
| TransactionPayload::Multisig(_) => None,
| TransactionPayload::Multisig(_) => Ok(None),
}
}
}
Expand Down Expand Up @@ -2481,7 +2481,7 @@ impl VMValidator for AptosVM {

let resolver = self.as_move_resolver(&state_view);
let mut session = self.new_session(&resolver, SessionId::prologue_meta(&txn_data));
let required_deposit = if let Ok(gas_params) = &self.gas_params {
let maybe_required_deposit = if let Ok(gas_params) = &self.gas_params {
self.get_required_deposit(
&mut session,
&resolver,
Expand All @@ -2490,7 +2490,14 @@ impl VMValidator for AptosVM {
txn.payload(),
)
} else {
return VMValidatorResult::error(StatusCode::UNKNOWN_VALIDATION_STATUS);
return VMValidatorResult::error(StatusCode::GAS_PARAMS_MISSING);
};

let required_deposit = match maybe_required_deposit {
Ok(v) => v,
Err(_e) => {
return VMValidatorResult::error(StatusCode::DEPOSIT_CALCULATION_FAILED);
},
};

txn_data.set_required_deposit(required_deposit);
Expand Down
6 changes: 4 additions & 2 deletions third_party/move/move-core/types/src/vm_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -584,11 +584,13 @@ pub enum StatusCode {
MULTISIG_TRANSACTION_PAYLOAD_DOES_NOT_MATCH_HASH = 35,
GAS_PAYER_ACCOUNT_MISSING = 36,
INSUFFICIENT_BALANCE_FOR_REQUIRED_DEPOSIT = 37,
GAS_PARAMS_MISSING = 38,
DEPOSIT_CALCULATION_FAILED = 39,
// Reserved error code for future use
RESERVED_VALIDATION_ERROR_3 = 38,
RESERVED_VALIDATION_ERROR_4 = 39,
RESERVED_VALIDATION_ERROR_5 = 40,
RESERVED_VALIDATION_ERROR_6 = 41,
RESERVED_VALIDATION_ERROR_7 = 42,
RESERVED_VALIDATION_ERROR_8 = 43,

// When a code module/script is published it is verified. These are the
// possible errors that can arise from the verification process.
Expand Down

0 comments on commit cf9ebc5

Please sign in to comment.