Skip to content

Commit

Permalink
Enable Simulation Without Auth Key and Gas Fee Checks
Browse files Browse the repository at this point in the history
This PR enhances the simulation functionality by allowing it to run without checking:
* authentication keys
* a gas fee payer and their sufficient funds for gas payment

This removed the mandatory check for an authentication key during simulations.

This also removed the requirement for a gas fee payer during simulations.
Simulations will no longer validate the presence of sufficient funds for gas payment, allowing developers to test scenarios without considering gas fees.

These changes are aimed at improving the flexibility of the simulation environment by allowing developers to test transactions and interactions without the constraints of authentication keys and gas fee payments.
  • Loading branch information
junkil-park committed Jun 20, 2024
1 parent 97a555b commit 8cfb624
Show file tree
Hide file tree
Showing 13 changed files with 383 additions and 156 deletions.
4 changes: 4 additions & 0 deletions api/types/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use std::{
str::FromStr,
time::{SystemTime, UNIX_EPOCH},
};
use crate::AccountSignature::NoAccountSignature;

static DUMMY_GUID: Lazy<EventGuid> = Lazy::new(|| EventGuid {
creation_number: U64::from(0u64),
Expand Down Expand Up @@ -1633,6 +1634,7 @@ pub enum AccountSignature {
MultiEd25519Signature(MultiEd25519Signature),
SingleKeySignature(SingleKeySignature),
MultiKeySignature(MultiKeySignature),
NoAccountSignature,
}

impl VerifyInput for AccountSignature {
Expand All @@ -1642,6 +1644,7 @@ impl VerifyInput for AccountSignature {
AccountSignature::MultiEd25519Signature(inner) => inner.verify(),
AccountSignature::SingleKeySignature(inner) => inner.verify(),
AccountSignature::MultiKeySignature(inner) => inner.verify(),
AccountSignature::NoAccountSignature => Ok(()),
}
}
}
Expand Down Expand Up @@ -1815,6 +1818,7 @@ impl From<&AccountAuthenticator> for AccountSignature {
signatures_required: public_keys.signatures_required(),
})
},
NoAccountAuthenticator => NoAccountSignature,
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ pub enum FeatureFlag {
DefaultToConcurrentFungibleBalance,
LimitVMTypeSize,
AbortIfMultisigPayloadMismatch,
SimulationEnhancement,
}

fn generate_features_blob(writer: &CodeWriter, data: &[u64]) {
Expand Down Expand Up @@ -316,6 +317,7 @@ impl From<FeatureFlag> for AptosFeatureFlag {
FeatureFlag::AbortIfMultisigPayloadMismatch => {
AptosFeatureFlag::ABORT_IF_MULTISIG_PAYLOAD_MISMATCH
},
FeatureFlag::SimulationEnhancement => AptosFeatureFlag::SIMULATION_ENHANCEMENT,
}
}
}
Expand Down Expand Up @@ -440,6 +442,7 @@ impl From<AptosFeatureFlag> for FeatureFlag {
AptosFeatureFlag::ABORT_IF_MULTISIG_PAYLOAD_MISMATCH => {
FeatureFlag::AbortIfMultisigPayloadMismatch
},
AptosFeatureFlag::SIMULATION_ENHANCEMENT => FeatureFlag::SimulationEnhancement,
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions aptos-move/aptos-vm/src/aptos_vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ impl AptosVM {
txn_data,
log_context,
traversal_context,
self.is_simulation,

Check warning on line 686 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L686 was not covered by tests
)
})?;
epilogue_session
Expand Down Expand Up @@ -710,6 +711,7 @@ impl AptosVM {
txn_data,
log_context,
traversal_context,
self.is_simulation,

Check warning on line 714 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L714 was not covered by tests
)
})?;
epilogue_session
Expand Down Expand Up @@ -756,6 +758,7 @@ impl AptosVM {
txn_data,
log_context,
traversal_context,
self.is_simulation,

Check warning on line 761 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L761 was not covered by tests
)
})?;
let change_set = epilogue_session.finish(change_set_configs)?;
Expand Down Expand Up @@ -2342,6 +2345,7 @@ impl AptosVM {
txn_data,
log_context,
traversal_context,
self.is_simulation,

Check warning on line 2348 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L2348 was not covered by tests
)
},
TransactionPayload::Multisig(multisig_payload) => {
Expand All @@ -2353,6 +2357,7 @@ impl AptosVM {
txn_data,
log_context,
traversal_context,
self.is_simulation,

Check warning on line 2360 in aptos-move/aptos-vm/src/aptos_vm.rs

View check run for this annotation

Codecov / codecov/patch

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

Added line #L2360 was not covered by tests
)?;
// Skip validation if this is part of tx simulation.
// This allows simulating multisig txs without having to first create the multisig
Expand Down
21 changes: 15 additions & 6 deletions aptos-move/aptos-vm/src/transaction_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,29 @@ impl TransactionMetadata {
pub fn new(txn: &SignedTransaction) -> Self {
Self {
sender: txn.sender(),
authentication_key: txn.authenticator().sender().authentication_key().to_vec(),
authentication_key: txn
.authenticator()
.sender()
.authentication_key()
.map_or_else(|| vec![], |auth_key| auth_key.to_vec()),

Check warning on line 45 in aptos-move/aptos-vm/src/transaction_metadata.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/transaction_metadata.rs#L41-L45

Added lines #L41 - L45 were not covered by tests
secondary_signers: txn.authenticator().secondary_signer_addresses(),
secondary_authentication_keys: txn
.authenticator()
.secondary_signers()
.iter()
.map(|account_auth| account_auth.authentication_key().to_vec())
.map(|account_auth| {
account_auth
.authentication_key()
.map_or_else(|| vec![], |auth_key| auth_key.to_vec())
})

Check warning on line 55 in aptos-move/aptos-vm/src/transaction_metadata.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/transaction_metadata.rs#L51-L55

Added lines #L51 - L55 were not covered by tests
.collect(),
sequence_number: txn.sequence_number(),
fee_payer: txn.authenticator_ref().fee_payer_address(),
fee_payer_authentication_key: txn
.authenticator()
.fee_payer_signer()
.map(|signer| signer.authentication_key().to_vec()),
fee_payer_authentication_key: txn.authenticator().fee_payer_signer().map(|signer| {
signer
.authentication_key()
.map_or_else(|| vec![], |auth_key| auth_key.to_vec())
}),

Check warning on line 63 in aptos-move/aptos-vm/src/transaction_metadata.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/transaction_metadata.rs#L59-L63

Added lines #L59 - L63 were not covered by tests
max_gas_amount: txn.max_gas_amount().into(),
gas_unit_price: txn.gas_unit_price().into(),
transaction_size: (txn.raw_txn_bytes_len() as u64).into(),
Expand Down
11 changes: 11 additions & 0 deletions aptos-move/aptos-vm/src/transaction_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pub(crate) fn run_script_prologue(
txn_data: &TransactionMetadata,
log_context: &AdapterLogSchema,
traversal_context: &mut TraversalContext,
is_simulation: bool,

Check warning on line 92 in aptos-move/aptos-vm/src/transaction_validation.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/transaction_validation.rs#L92

Added line #L92 was not covered by tests
) -> Result<(), VMStatus> {
let txn_sequence_number = txn_data.sequence_number();
let txn_authentication_key = txn_data.authentication_key().to_vec();
Expand Down Expand Up @@ -118,6 +119,7 @@ pub(crate) fn run_script_prologue(
MoveValue::U64(txn_max_gas_units.into()),
MoveValue::U64(txn_expiration_timestamp_secs),
MoveValue::U8(chain_id.id()),
MoveValue::Bool(is_simulation),

Check warning on line 122 in aptos-move/aptos-vm/src/transaction_validation.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/transaction_validation.rs#L122

Added line #L122 was not covered by tests
];
if txn_data.required_deposit.is_some() {
args.push(txn_data.required_deposit.as_move_value());
Expand All @@ -139,6 +141,7 @@ pub(crate) fn run_script_prologue(
MoveValue::U64(txn_max_gas_units.into()),
MoveValue::U64(txn_expiration_timestamp_secs),
MoveValue::U8(chain_id.id()),
MoveValue::Bool(is_simulation),

Check warning on line 144 in aptos-move/aptos-vm/src/transaction_validation.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/transaction_validation.rs#L144

Added line #L144 was not covered by tests
];
(
&APTOS_TRANSACTION_VALIDATION.multi_agent_prologue_name,
Expand All @@ -154,6 +157,7 @@ pub(crate) fn run_script_prologue(
MoveValue::U64(txn_expiration_timestamp_secs),
MoveValue::U8(chain_id.id()),
MoveValue::vector_u8(txn_data.script_hash.clone()),
MoveValue::Bool(is_simulation),

Check warning on line 160 in aptos-move/aptos-vm/src/transaction_validation.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/transaction_validation.rs#L160

Added line #L160 was not covered by tests
];
if txn_data.required_deposit.is_some() {
args.push(txn_data.required_deposit.as_move_value());
Expand Down Expand Up @@ -229,6 +233,7 @@ fn run_epilogue(
txn_data: &TransactionMetadata,
features: &Features,
traversal_context: &mut TraversalContext,
is_simulation: bool,

Check warning on line 236 in aptos-move/aptos-vm/src/transaction_validation.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/transaction_validation.rs#L236

Added line #L236 was not covered by tests
) -> VMResult<()> {
let txn_gas_price = txn_data.gas_unit_price();
let txn_max_gas_units = txn_data.max_gas_amount();
Expand All @@ -244,6 +249,7 @@ fn run_epilogue(
MoveValue::U64(txn_gas_price.into()),
MoveValue::U64(txn_max_gas_units.into()),
MoveValue::U64(gas_remaining.into()),
MoveValue::Bool(is_simulation),

Check warning on line 252 in aptos-move/aptos-vm/src/transaction_validation.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/transaction_validation.rs#L252

Added line #L252 was not covered by tests
];
if txn_data.required_deposit.is_some() {
args.push(txn_data.required_deposit.as_move_value());
Expand Down Expand Up @@ -275,6 +281,7 @@ fn run_epilogue(
MoveValue::U64(txn_gas_price.into()),
MoveValue::U64(txn_max_gas_units.into()),
MoveValue::U64(gas_remaining.into()),
MoveValue::Bool(is_simulation),

Check warning on line 284 in aptos-move/aptos-vm/src/transaction_validation.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/transaction_validation.rs#L284

Added line #L284 was not covered by tests
];
if txn_data.required_deposit.is_some() {
args.push(txn_data.required_deposit.as_move_value());
Expand Down Expand Up @@ -335,6 +342,7 @@ pub(crate) fn run_success_epilogue(
txn_data: &TransactionMetadata,
log_context: &AdapterLogSchema,
traversal_context: &mut TraversalContext,
is_simulation: bool,

Check warning on line 345 in aptos-move/aptos-vm/src/transaction_validation.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/transaction_validation.rs#L345

Added line #L345 was not covered by tests
) -> Result<(), VMStatus> {
fail_point!("move_adapter::run_success_epilogue", |_| {
Err(VMStatus::error(
Expand All @@ -350,6 +358,7 @@ pub(crate) fn run_success_epilogue(
txn_data,
features,
traversal_context,
is_simulation,

Check warning on line 361 in aptos-move/aptos-vm/src/transaction_validation.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/transaction_validation.rs#L361

Added line #L361 was not covered by tests
)
.or_else(|err| convert_epilogue_error(err, log_context))
}
Expand All @@ -364,6 +373,7 @@ pub(crate) fn run_failure_epilogue(
txn_data: &TransactionMetadata,
log_context: &AdapterLogSchema,
traversal_context: &mut TraversalContext,
is_simulation: bool,

Check warning on line 376 in aptos-move/aptos-vm/src/transaction_validation.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/transaction_validation.rs#L376

Added line #L376 was not covered by tests
) -> Result<(), VMStatus> {
run_epilogue(
session,
Expand All @@ -372,6 +382,7 @@ pub(crate) fn run_failure_epilogue(
txn_data,
features,
traversal_context,
is_simulation,

Check warning on line 385 in aptos-move/aptos-vm/src/transaction_validation.rs

View check run for this annotation

Codecov / codecov/patch

aptos-move/aptos-vm/src/transaction_validation.rs#L385

Added line #L385 was not covered by tests
)
.or_else(|e| {
expect_only_successful_execution(
Expand Down
Loading

0 comments on commit 8cfb624

Please sign in to comment.