Skip to content

Commit a69d8a5

Browse files
committed
discard on deposit calculation failure, and new status code
1 parent 72e83b7 commit a69d8a5

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

aptos-move/aptos-vm/src/aptos_vm.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,7 +1611,7 @@ impl AptosVM {
16111611
&gas_meter.vm_gas_params().txn,
16121612
&txn_data,
16131613
txn.payload(),
1614-
);
1614+
)?;
16151615
txn_data.set_required_deposit(required_deposit);
16161616
self.validate_signed_transaction(session, resolver, txn, &txn_data, log_context)
16171617
}));
@@ -2293,11 +2293,11 @@ impl AptosVM {
22932293
txn_gas_params: &TransactionGasParameters,
22942294
txn_metadata: &TransactionMetadata,
22952295
payload: &TransactionPayload,
2296-
) -> Option<u64> {
2296+
) -> VMResult<Option<u64>> {
22972297
match payload {
22982298
TransactionPayload::EntryFunction(entry_func) => {
22992299
if self.randomness_enabled
2300-
&& has_randomness_attribute(resolver, session, entry_func).unwrap_or(false)
2300+
&& has_randomness_attribute(resolver, session, entry_func)?
23012301
{
23022302
let max_execution_gas: Gas = txn_gas_params
23032303
.max_execution_gas
@@ -2310,14 +2310,14 @@ impl AptosVM {
23102310
let cand_1 =
23112311
txn_metadata.gas_unit_price * txn_gas_params.maximum_number_of_gas_units;
23122312
let required_fee_deposit = min(cand_0, cand_1);
2313-
Some(u64::from(required_fee_deposit))
2313+
Ok(Some(u64::from(required_fee_deposit)))
23142314
} else {
2315-
None
2315+
Ok(None)
23162316
}
23172317
},
23182318
TransactionPayload::Script(_)
23192319
| TransactionPayload::ModuleBundle(_)
2320-
| TransactionPayload::Multisig(_) => None,
2320+
| TransactionPayload::Multisig(_) => Ok(None),
23212321
}
23222322
}
23232323
}
@@ -2455,7 +2455,7 @@ impl VMValidator for AptosVM {
24552455

24562456
let resolver = self.as_move_resolver(&state_view);
24572457
let mut session = self.new_session(&resolver, SessionId::prologue_meta(&txn_data));
2458-
let required_deposit = if let Ok(gas_params) = &self.gas_params {
2458+
let maybe_required_deposit = if let Ok(gas_params) = &self.gas_params {
24592459
self.get_required_deposit(
24602460
&mut session,
24612461
&resolver,
@@ -2464,7 +2464,14 @@ impl VMValidator for AptosVM {
24642464
txn.payload(),
24652465
)
24662466
} else {
2467-
return VMValidatorResult::error(StatusCode::UNKNOWN_VALIDATION_STATUS);
2467+
return VMValidatorResult::error(StatusCode::GAS_PARAMS_MISSING);
2468+
};
2469+
2470+
let required_deposit = match maybe_required_deposit {
2471+
Ok(v) => v,
2472+
Err(_e) => {
2473+
return VMValidatorResult::error(StatusCode::DEPOSIT_CALCULATION_FAILED);
2474+
},
24682475
};
24692476

24702477
txn_data.set_required_deposit(required_deposit);

third_party/move/move-core/types/src/vm_status.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,11 +584,13 @@ pub enum StatusCode {
584584
MULTISIG_TRANSACTION_PAYLOAD_DOES_NOT_MATCH_HASH = 35,
585585
GAS_PAYER_ACCOUNT_MISSING = 36,
586586
INSUFFICIENT_BALANCE_FOR_REQUIRED_DEPOSIT = 37,
587+
GAS_PARAMS_MISSING = 38,
588+
DEPOSIT_CALCULATION_FAILED = 39,
587589
// Reserved error code for future use
588-
RESERVED_VALIDATION_ERROR_3 = 38,
589-
RESERVED_VALIDATION_ERROR_4 = 39,
590590
RESERVED_VALIDATION_ERROR_5 = 40,
591591
RESERVED_VALIDATION_ERROR_6 = 41,
592+
RESERVED_VALIDATION_ERROR_7 = 42,
593+
RESERVED_VALIDATION_ERROR_8 = 43,
592594

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

0 commit comments

Comments
 (0)