Skip to content

Commit cf9ebc5

Browse files
committed
discard on deposit calculation failure, and new status code
1 parent dbb03eb commit cf9ebc5

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
@@ -1637,7 +1637,7 @@ impl AptosVM {
16371637
&gas_meter.vm_gas_params().txn,
16381638
&txn_data,
16391639
txn.payload(),
1640-
);
1640+
)?;
16411641
txn_data.set_required_deposit(required_deposit);
16421642
self.validate_signed_transaction(session, resolver, txn, &txn_data, log_context)
16431643
}));
@@ -2319,11 +2319,11 @@ impl AptosVM {
23192319
txn_gas_params: &TransactionGasParameters,
23202320
txn_metadata: &TransactionMetadata,
23212321
payload: &TransactionPayload,
2322-
) -> Option<u64> {
2322+
) -> VMResult<Option<u64>> {
23232323
match payload {
23242324
TransactionPayload::EntryFunction(entry_func) => {
23252325
if self.randomness_enabled
2326-
&& has_randomness_attribute(resolver, session, entry_func).unwrap_or(false)
2326+
&& has_randomness_attribute(resolver, session, entry_func)?
23272327
{
23282328
let max_execution_gas: Gas = txn_gas_params
23292329
.max_execution_gas
@@ -2336,14 +2336,14 @@ impl AptosVM {
23362336
let cand_1 =
23372337
txn_metadata.gas_unit_price * txn_gas_params.maximum_number_of_gas_units;
23382338
let required_fee_deposit = min(cand_0, cand_1);
2339-
Some(u64::from(required_fee_deposit))
2339+
Ok(Some(u64::from(required_fee_deposit)))
23402340
} else {
2341-
None
2341+
Ok(None)
23422342
}
23432343
},
23442344
TransactionPayload::Script(_)
23452345
| TransactionPayload::ModuleBundle(_)
2346-
| TransactionPayload::Multisig(_) => None,
2346+
| TransactionPayload::Multisig(_) => Ok(None),
23472347
}
23482348
}
23492349
}
@@ -2481,7 +2481,7 @@ impl VMValidator for AptosVM {
24812481

24822482
let resolver = self.as_move_resolver(&state_view);
24832483
let mut session = self.new_session(&resolver, SessionId::prologue_meta(&txn_data));
2484-
let required_deposit = if let Ok(gas_params) = &self.gas_params {
2484+
let maybe_required_deposit = if let Ok(gas_params) = &self.gas_params {
24852485
self.get_required_deposit(
24862486
&mut session,
24872487
&resolver,
@@ -2490,7 +2490,14 @@ impl VMValidator for AptosVM {
24902490
txn.payload(),
24912491
)
24922492
} else {
2493-
return VMValidatorResult::error(StatusCode::UNKNOWN_VALIDATION_STATUS);
2493+
return VMValidatorResult::error(StatusCode::GAS_PARAMS_MISSING);
2494+
};
2495+
2496+
let required_deposit = match maybe_required_deposit {
2497+
Ok(v) => v,
2498+
Err(_e) => {
2499+
return VMValidatorResult::error(StatusCode::DEPOSIT_CALCULATION_FAILED);
2500+
},
24942501
};
24952502

24962503
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)