diff --git a/aptos-move/aptos-debugger/src/aptos_debugger.rs b/aptos-move/aptos-debugger/src/aptos_debugger.rs index 11008adbec071b..eec38c3132d82b 100644 --- a/aptos-move/aptos-debugger/src/aptos_debugger.rs +++ b/aptos-move/aptos-debugger/src/aptos_debugger.rs @@ -104,7 +104,7 @@ impl AptosDebugger { gas_meter, auto_payload.module_id().clone(), auto_payload.function().to_owned(), - auto_payload.ty_args().to_vec(), + auto_payload.ty_args(), ), TransactionPayload::EntryFunction(entry_func) => GasProfiler::new_function( gas_meter, diff --git a/aptos-move/aptos-gas-schedule/src/gas_schedule/aptos_framework.rs b/aptos-move/aptos-gas-schedule/src/gas_schedule/aptos_framework.rs index f87d65c5f5ce7e..7d3c92bea7c499 100644 --- a/aptos-move/aptos-gas-schedule/src/gas_schedule/aptos_framework.rs +++ b/aptos-move/aptos-gas-schedule/src/gas_schedule/aptos_framework.rs @@ -281,7 +281,6 @@ crate::gas_schedule::macros::define_gas_parameters!( [transaction_context_gas_unit_price_base: InternalGas, {RELEASE_V1_12.. => "transaction_context.gas_unit_price.base"}, 735], [transaction_context_chain_id_base: InternalGas, {RELEASE_V1_12.. => "transaction_context.chain_id.base"}, 735], [transaction_context_entry_function_payload_base: InternalGas, {RELEASE_V1_12.. => "transaction_context.entry_function_payload.base"}, 735], - [transaction_context_automation_registration_base: InternalGas, {RELEASE_V1_12.. => "transaction_context.automation_registration.base"}, 735], [transaction_context_entry_function_payload_per_byte_in_str: InternalGasPerByte, {RELEASE_V1_12.. => "transaction_context.entry_function_payload.per_abstract_memory_unit"}, 18], [transaction_context_multisig_payload_base: InternalGas, {RELEASE_V1_12.. => "transaction_context.multisig_payload.base"}, 735], [transaction_context_multisig_payload_per_byte_in_str: InternalGasPerByte, {RELEASE_V1_12.. => "transaction_context.multisig_payload.per_abstract_memory_unit"}, 18], diff --git a/aptos-move/aptos-vm/src/aptos_vm.rs b/aptos-move/aptos-vm/src/aptos_vm.rs index 33398437f3bab7..9fe0c10748f6e7 100644 --- a/aptos-move/aptos-vm/src/aptos_vm.rs +++ b/aptos-move/aptos-vm/src/aptos_vm.rs @@ -798,6 +798,8 @@ impl AptosVM { Ok(()) } + + fn execute_script_or_entry_function<'a, 'r, 'l>( &'l self, resolver: &'r impl AptosMoveResolver, @@ -913,16 +915,14 @@ impl AptosVM { registration_params.automated_function(), ) })?; - let register_entry_function = EntryFunction::from(registration_params.clone()); + // let register_entry_function = EntryFunction::from(registration_params.clone()); session.execute(|session| { - self.validate_and_execute_entry_function( - resolver, + self.execute_automation_registration( session, gas_meter, traversal_context, - txn_data.senders(), - ®ister_entry_function, - txn_data, + txn_data.sender(), + registration_params ) })?; @@ -953,6 +953,38 @@ impl AptosVM { ) } + fn execute_automation_registration( + &self, + session: &mut SessionExt, + gas_meter: &mut impl AptosGasMeter, + traversal_context: &mut TraversalContext, + sender: AccountAddress, + registration_params: &RegistrationParams, + ) -> Result<(), VMStatus> { + // Note: Feature gating is needed here because the traversal of the dependencies could + // result in shallow-loading of the modules and therefore subtle changes in + // the error semantics. + if self.gas_feature_version >= 15 { + let module_id = traversal_context + .referenced_module_ids + .alloc(registration_params.module_id().clone()); + session.check_dependencies_and_charge_gas( + gas_meter, + traversal_context, + [(module_id.address(), module_id.name())], + )?; + } + let args = registration_params.serialized_args_with_sender(sender); + + session.execute_function_bypass_visibility(registration_params.module_id(), + registration_params.function(), + registration_params.ty_args(), + args, + gas_meter, + traversal_context)?; + Ok(()) + } + fn charge_change_set( &self, change_set: &mut VMChangeSet, diff --git a/aptos-move/e2e-tests/src/executor.rs b/aptos-move/e2e-tests/src/executor.rs index eb340a5a18c116..a18cfa4cabb262 100644 --- a/aptos-move/e2e-tests/src/executor.rs +++ b/aptos-move/e2e-tests/src/executor.rs @@ -689,7 +689,7 @@ impl FakeExecutor { gas_meter, auto_payload.module_id().clone(), auto_payload.function().to_owned(), - auto_payload.ty_args().to_vec(), + auto_payload.ty_args(), ), TransactionPayload::EntryFunction(entry_func) => GasProfiler::new_function( gas_meter, diff --git a/aptos-move/e2e-testsuite/src/tests/automation_registration.rs b/aptos-move/e2e-testsuite/src/tests/automation_registration.rs index e2fdcd56b26709..ac94f4223e9417 100644 --- a/aptos-move/e2e-testsuite/src/tests/automation_registration.rs +++ b/aptos-move/e2e-testsuite/src/tests/automation_registration.rs @@ -133,41 +133,6 @@ fn check_successful_registration() { assert_eq!(next_task_id, 2); } -#[test] -fn check_registration_from_non_automation_context() { - let mut test_context = AutomationRegistrationTestContext::new(); - // Prepare inner-entry-function to be automated. - let dest_account = test_context.new_account_data(0, 0); - let inner_entry_function = - aptos_framework_sdk_builder::supra_coin_mint(dest_account.address().clone(), 100) - .into_entry_function(); - let inner_entry_function_bytes = - bcs::to_bytes(&inner_entry_function).expect("Can't serialize entry function"); - - let entry_with_register = aptos_framework_sdk_builder::automation_registry_register( - inner_entry_function_bytes, - 3600, - 100, - 100, - ); - let user_txn_with_register_entry = test_context - .txn_sender - .account() - .transaction() - .payload(entry_with_register) - .sequence_number(0) - .sign(); - - let output = test_context.execute_transaction(user_txn_with_register_entry); - match output.status() { - TransactionStatus::Keep(ExecutionStatus::MoveAbort { code, .. }) => { - //ENOT_AUTOMATION_TXN_CONTEXT - assert_eq!(*code, 7); - }, - _ => panic!("Unexpected transaction status: {output:?}"), - } -} - #[test] fn check_invalid_automation_txn() { let mut test_context = AutomationRegistrationTestContext::new(); diff --git a/aptos-move/framework/cached-packages/src/aptos_framework_sdk_builder.rs b/aptos-move/framework/cached-packages/src/aptos_framework_sdk_builder.rs index 6d4af36a9bd999..b4f2648fe451a8 100644 --- a/aptos-move/framework/cached-packages/src/aptos_framework_sdk_builder.rs +++ b/aptos-move/framework/cached-packages/src/aptos_framework_sdk_builder.rs @@ -147,14 +147,6 @@ pub enum EntryFunctionCall { cap_update_table: Vec, }, - /// Registers a new automation task entry. - AutomationRegistryRegister { - payload_tx: Vec, - expiry_time: u64, - max_gas_amount: u64, - gas_price_cap: u64, - }, - /// Update Automation gas limit AutomationRegistryUpdateAutomationGasLimit { automation_gas_limit: u64, @@ -1199,14 +1191,6 @@ impl EntryFunctionCall { new_public_key_bytes, cap_update_table, ), - AutomationRegistryRegister { - payload_tx, - expiry_time, - max_gas_amount, - gas_price_cap, - } => { - automation_registry_register(payload_tx, expiry_time, max_gas_amount, gas_price_cap) - }, AutomationRegistryUpdateAutomationGasLimit { automation_gas_limit, } => automation_registry_update_automation_gas_limit(automation_gas_limit), @@ -2149,32 +2133,6 @@ pub fn account_rotate_authentication_key_with_rotation_capability( )) } -/// Registers a new automation task entry. -pub fn automation_registry_register( - payload_tx: Vec, - expiry_time: u64, - max_gas_amount: u64, - gas_price_cap: u64, -) -> TransactionPayload { - TransactionPayload::EntryFunction(EntryFunction::new( - ModuleId::new( - AccountAddress::new([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, - ]), - ident_str!("automation_registry").to_owned(), - ), - ident_str!("register").to_owned(), - vec![], - vec![ - bcs::to_bytes(&payload_tx).unwrap(), - bcs::to_bytes(&expiry_time).unwrap(), - bcs::to_bytes(&max_gas_amount).unwrap(), - bcs::to_bytes(&gas_price_cap).unwrap(), - ], - )) -} - /// Update Automation gas limit pub fn automation_registry_update_automation_gas_limit( automation_gas_limit: u64, @@ -5371,19 +5329,6 @@ mod decoder { } } - pub fn automation_registry_register(payload: &TransactionPayload) -> Option { - if let TransactionPayload::EntryFunction(script) = payload { - Some(EntryFunctionCall::AutomationRegistryRegister { - payload_tx: bcs::from_bytes(script.args().get(0)?).ok()?, - expiry_time: bcs::from_bytes(script.args().get(1)?).ok()?, - max_gas_amount: bcs::from_bytes(script.args().get(2)?).ok()?, - gas_price_cap: bcs::from_bytes(script.args().get(3)?).ok()?, - }) - } else { - None - } - } - pub fn automation_registry_update_automation_gas_limit( payload: &TransactionPayload, ) -> Option { @@ -7265,10 +7210,6 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy, - _args: VecDeque, -) -> SafeNativeResult> { - context.charge(TRANSACTION_CONTEXT_AUTOMATION_REGISTRATION_BASE)?; - - let user_transaction_context_opt = get_user_transaction_context_opt_from_context(context); - - if let Some(transaction_context) = user_transaction_context_opt { - Ok(smallvec![Value::bool(transaction_context.is_automation_registration())]) - } else { - Err(SafeNativeError::Abort { - abort_code: error::invalid_state(abort_codes::ETRANSACTION_CONTEXT_NOT_AVAILABLE), - }) - } -} - fn get_user_transaction_context_opt_from_context<'a>( context: &'a SafeNativeContext, ) -> &'a Option { @@ -451,10 +431,6 @@ pub fn make_all( "multisig_payload_internal", native_multisig_payload_internal, ), - ( - "is_automation_registration_internal", - native_is_automation_registration_internal, - ), ("txn_app_hash_internal", native_txn_app_hash_internal), ]; diff --git a/aptos-move/framework/supra-framework/doc/automation_registry.md b/aptos-move/framework/supra-framework/doc/automation_registry.md index 26c9154c851d8f..bb0c1c6f43b590 100644 --- a/aptos-move/framework/supra-framework/doc/automation_registry.md +++ b/aptos-move/framework/supra-framework/doc/automation_registry.md @@ -261,16 +261,6 @@ Invalid gas price: it cannot be zero - - -Entry function is called not from automation registration transaction context. - - -
const ENOT_AUTOMATION_TXN_CONTEXT: u64 = 7;
-
- - - Registry Id not found @@ -498,7 +488,7 @@ Calculate and collect registry charge from user Registers a new automation task entry. -
public entry fun register(owner: &signer, payload_tx: vector<u8>, expiry_time: u64, max_gas_amount: u64, gas_price_cap: u64)
+
public fun register(owner: &signer, payload_tx: vector<u8>, expiry_time: u64, max_gas_amount: u64, gas_price_cap: u64)
 
@@ -507,14 +497,13 @@ Registers a new automation task entry. Implementation -
public entry fun register(
+
public fun register(
     owner: &signer,
     payload_tx: vector<u8>,
     expiry_time: u64,
     max_gas_amount: u64,
     gas_price_cap: u64
 ) acquires AutomationRegistry {
-    assert!(transaction_context::is_automation_registration(), ENOT_AUTOMATION_TXN_CONTEXT);
     let registry_data = borrow_global_mut<AutomationRegistry>(@supra_framework);
 
     // todo : well formedness check of payload_tx
diff --git a/aptos-move/framework/supra-framework/doc/transaction_context.md b/aptos-move/framework/supra-framework/doc/transaction_context.md
index 1ff08c4670ee5d..c2e2fbd7810325 100644
--- a/aptos-move/framework/supra-framework/doc/transaction_context.md
+++ b/aptos-move/framework/supra-framework/doc/transaction_context.md
@@ -30,8 +30,6 @@
 -  [Function `chain_id_internal`](#0x1_transaction_context_chain_id_internal)
 -  [Function `entry_function_payload`](#0x1_transaction_context_entry_function_payload)
 -  [Function `entry_function_payload_internal`](#0x1_transaction_context_entry_function_payload_internal)
--  [Function `is_automation_registration`](#0x1_transaction_context_is_automation_registration)
--  [Function `is_automation_registration_internal`](#0x1_transaction_context_is_automation_registration_internal)
 -  [Function `txn_app_hash`](#0x1_transaction_context_txn_app_hash)
 -  [Function `txn_app_hash_internal`](#0x1_transaction_context_txn_app_hash_internal)
 -  [Function `account_address`](#0x1_transaction_context_account_address)
@@ -736,55 +734,6 @@ This function aborts if called outside of the transaction prologue, execution, o
 
 
 
-
-
-
-
-## Function `is_automation_registration`
-
-Returns true if current user transaction has automation registration payload type. Otherwise, return false.
-This function aborts if called outside of the transaction prologue, execution, or epilogue phases.
-
-
-
public fun is_automation_registration(): bool
-
- - - -
-Implementation - - -
public fun is_automation_registration(): bool {
-    assert!(features::transaction_context_extension_enabled(), error::invalid_state(ETRANSACTION_CONTEXT_EXTENSION_NOT_ENABLED));
-    is_automation_registration_internal()
-}
-
- - - -
- - - -## Function `is_automation_registration_internal` - - - -
fun is_automation_registration_internal(): bool
-
- - - -
-Implementation - - -
native fun is_automation_registration_internal(): bool;
-
- - -
diff --git a/aptos-move/framework/supra-framework/sources/automation_registry.move b/aptos-move/framework/supra-framework/sources/automation_registry.move index 7dd146f305e1a1..e4abcc32e824d3 100644 --- a/aptos-move/framework/supra-framework/sources/automation_registry.move +++ b/aptos-move/framework/supra-framework/sources/automation_registry.move @@ -36,8 +36,6 @@ module supra_framework::automation_registry { const EGAS_AMOUNT_UPPER: u64 = 5; /// Invalid gas price: it cannot be zero const EINVALID_GAS_PRICE: u64 = 6; - /// Entry function is called not from automation registration transaction context. - const ENOT_AUTOMATION_TXN_CONTEXT: u64 = 7; /// The default automation task gas limit const DEFAULT_AUTOMATION_GAS_LIMIT: u64 = 100000000; @@ -164,14 +162,13 @@ module supra_framework::automation_registry { } /// Registers a new automation task entry. - public entry fun register( + public fun register( owner: &signer, payload_tx: vector, expiry_time: u64, max_gas_amount: u64, gas_price_cap: u64 ) acquires AutomationRegistry { - assert!(transaction_context::is_automation_registration(), ENOT_AUTOMATION_TXN_CONTEXT); let registry_data = borrow_global_mut(@supra_framework); // todo : well formedness check of payload_tx diff --git a/aptos-move/framework/supra-framework/sources/transaction_context.move b/aptos-move/framework/supra-framework/sources/transaction_context.move index a0e3b6bc012b07..f61370518b38eb 100644 --- a/aptos-move/framework/supra-framework/sources/transaction_context.move +++ b/aptos-move/framework/supra-framework/sources/transaction_context.move @@ -132,14 +132,6 @@ module supra_framework::transaction_context { } native fun entry_function_payload_internal(): Option; - /// Returns true if current user transaction has automation registration payload type. Otherwise, return `false`. - /// This function aborts if called outside of the transaction prologue, execution, or epilogue phases. - public fun is_automation_registration(): bool { - assert!(features::transaction_context_extension_enabled(), error::invalid_state(ETRANSACTION_CONTEXT_EXTENSION_NOT_ENABLED)); - is_automation_registration_internal() - } - native fun is_automation_registration_internal(): bool; - /// Returns the original transaction hash calculated on the raw-bytes. /// This function aborts if called outside of the transaction prologue, execution, or epilogue phases. public fun txn_app_hash(): vector { @@ -276,13 +268,6 @@ module supra_framework::transaction_context { let _multisig = multisig_payload(); } - #[test] - #[expected_failure(abort_code=196609, location = Self)] - fun test_call_automation_payload() { - // expected to fail with the error code of `invalid_state(E_TRANSACTION_CONTEXT_NOT_AVAILABLE)` - let _automation = is_automation_registration(); - } - #[test] #[expected_failure(abort_code=196609, location = Self)] fun test_call_txn_app_hash() { diff --git a/types/src/transaction/automation.rs b/types/src/transaction/automation.rs index 8ade9493f052a7..f65ed486c5bd9d 100644 --- a/types/src/transaction/automation.rs +++ b/types/src/transaction/automation.rs @@ -5,6 +5,8 @@ use move_core_types::identifier::{IdentStr, Identifier}; use move_core_types::language_storage::{ModuleId, TypeTag, CORE_CODE_ADDRESS}; use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; +use move_core_types::account_address::AccountAddress; +use move_core_types::value::{serialize_values, MoveValue}; struct AutomationTransactionEntryRef { module_id: ModuleId, @@ -33,6 +35,18 @@ pub struct RegistrationParams { expiration_timestamp_secs: u64, } +impl RegistrationParams { + pub fn serialized_args_with_sender(&self, sender: AccountAddress) -> Vec> { + serialize_values(&[ + MoveValue::Address(sender), + MoveValue::vector_u8(bcs::to_bytes(&self.automated_function).unwrap()), + MoveValue::U64(self.expiration_timestamp_secs), + MoveValue::U64(self.max_gas_amount), + MoveValue::U64(self.gas_price_cap) + ]) + } +} + impl RegistrationParams { pub fn new( automated_function: EntryFunction, @@ -66,29 +80,7 @@ impl RegistrationParams { } /// Type arguments required by registration function. - pub fn ty_args(&self) -> &[TypeTag] { - &[] - } -} - -impl From for EntryFunction { - fn from(value: RegistrationParams) -> EntryFunction { - let RegistrationParams { - automated_function, - max_gas_amount, - gas_price_cap, - expiration_timestamp_secs, - } = value; - EntryFunction::new( - AUTOMATION_REGISTRATION_ENTRY.module_id.clone(), - AUTOMATION_REGISTRATION_ENTRY.function.clone(), - vec![], - vec![ - bcs::to_bytes(&bcs::to_bytes(&automated_function).unwrap()).unwrap(), - bcs::to_bytes(&expiration_timestamp_secs).unwrap(), - bcs::to_bytes(&max_gas_amount).unwrap(), - bcs::to_bytes(&gas_price_cap).unwrap(), - ], - ) + pub fn ty_args(&self) -> Vec { + vec![] } -} +} \ No newline at end of file