diff --git a/executor/wasm/src/install.rs b/executor/wasm/src/install.rs index 4b61fba9bf..4cea73e0b0 100644 --- a/executor/wasm/src/install.rs +++ b/executor/wasm/src/install.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::{collections::BTreeSet, sync::Arc}; use bytes::Bytes; use casper_executor_wasm_common::error::CallError; @@ -47,6 +47,8 @@ pub struct InstallContractRequest { pub(crate) seed: Option<[u8; 32]>, /// Runtime native config. pub(crate) runtime_native_config: RuntimeNativeConfig, + /// Authorization keys for this installation. + pub(crate) authorization_keys: BTreeSet, } #[derive(Default)] @@ -66,6 +68,7 @@ pub struct InstallContractRequestBuilder { block_height: Option, runtime_native_config: Option, seed: Option<[u8; 32]>, + authorization_keys: Option>, } impl InstallContractRequestBuilder { @@ -155,6 +158,11 @@ impl InstallContractRequestBuilder { self } + pub fn with_authorization_keys(mut self, authorization_keys: BTreeSet) -> Self { + self.authorization_keys = Some(authorization_keys); + self + } + pub fn build(self) -> Result { let initiator = self.initiator.ok_or("Initiator not set")?; let gas_limit = self.gas_limit.ok_or("Gas limit not set")?; @@ -173,6 +181,9 @@ impl InstallContractRequestBuilder { let runtime_native_config = self .runtime_native_config .ok_or("Runtime native config not set")?; + let authorization_keys = self + .authorization_keys + .ok_or("Authorization keys not set")?; Ok(InstallContractRequest { initiator, gas_limit, @@ -189,6 +200,7 @@ impl InstallContractRequestBuilder { parent_block_hash, block_height, runtime_native_config, + authorization_keys, }) } } diff --git a/executor/wasm/src/lib.rs b/executor/wasm/src/lib.rs index 8f046464ea..6bcdb8629d 100644 --- a/executor/wasm/src/lib.rs +++ b/executor/wasm/src/lib.rs @@ -227,6 +227,7 @@ impl ExecutorV2 { parent_block_hash, block_height, runtime_native_config, + authorization_keys, } = install_request; let bytecode_hash = chain_utils::compute_wasm_bytecode_hash(&wasm_bytes); @@ -450,6 +451,7 @@ impl ExecutorV2 { .with_parent_block_hash(parent_block_hash) .with_block_height(block_height) .with_runtime_native_config(runtime_native_config) + .with_authorization_keys(authorization_keys) .build() .map_err(InstallContractError::FailedBuildingExecuteRequest)?; @@ -570,6 +572,7 @@ impl ExecutorV2 { block_height, sandboxed, runtime_native_config, + authorization_keys, } = execute_request; let (entity_addr, source_purse) = get_purse_for_entity(&mut tracking_copy, caller_key)?; @@ -668,6 +671,7 @@ impl ExecutorV2 { block_info, transaction_hash, gas_limit, + authorization_keys.clone(), ); } EntityKind::SmartContract(ContractRuntimeTag::VmCasperV2) => { @@ -859,6 +863,7 @@ impl ExecutorV2 { block_info, transaction_hash, gas_limit, + authorization_keys, ); } } @@ -929,6 +934,7 @@ impl ExecutorV2 { runtime_native_config, parent_block_hash: parent_block_hash.inner().value(), block_height, + authorization_keys, }; // Check that the input argument size does not exceed the VM memory limit @@ -1067,11 +1073,11 @@ impl ExecutorV2 { block_info: BlockInfo, transaction_hash: TransactionHash, gas_limit: u64, + authorization_keys: BTreeSet, ) -> Result where R: GlobalStateReader + 'static, { - let authorization_keys = BTreeSet::from_iter([initiator]); let initiator_addr = InitiatorAddr::AccountHash(initiator); let executable_item = ExecutableItem::Invocation(TransactionInvocationTarget::ByHash(entity_addr.value())); @@ -1284,6 +1290,7 @@ impl Executor for ExecutorV2 { .with_block_height(request.block_height) .with_sandboxed(true) // Enable sandboxed mode .with_runtime_native_config(runtime_native_config) + .with_authorization_keys(BTreeSet::from_iter([request.initiator])) .build() .map_err(|error| { ExecuteError::Fatal(FatalHostError::ExecuteRequestBuildFailure(error)) diff --git a/executor/wasm/src/testing.rs b/executor/wasm/src/testing.rs index 6d07ec9857..3cc25b1f2f 100644 --- a/executor/wasm/src/testing.rs +++ b/executor/wasm/src/testing.rs @@ -1,4 +1,5 @@ use std::{ + collections::BTreeSet, env, fs, path::{Path, PathBuf}, sync::Arc, @@ -151,6 +152,7 @@ pub fn base_execute_builder(chainspec_config: &ChainspecConfig) -> ExecuteReques .with_runtime_native_config(make_runtime_config(chainspec_config)) .with_parent_block_hash(BlockHash::new(Digest::hash(b"block1"))) .with_runtime_native_config(runtime_native_config) + .with_authorization_keys(BTreeSet::from_iter([*DEFAULT_ACCOUNT_HASH])) } pub fn make_runtime_config(chainspec_config: &ChainspecConfig) -> RuntimeNativeConfig { @@ -212,6 +214,7 @@ pub fn base_install_request_builder( .with_runtime_native_config(make_runtime_config(chainspec_config)) .with_parent_block_hash(BlockHash::new(Digest::hash(b"block1"))) .with_runtime_native_config(runtime_native_config) + .with_authorization_keys(BTreeSet::from_iter([*DEFAULT_ACCOUNT_HASH])) } pub fn make_executor(chainspec_config: &ChainspecConfig) -> ExecutorV2 { diff --git a/executor/wasm/tests/ee_966.rs b/executor/wasm/tests/ee_966.rs index 0a9175b6ae..4ff9ae81a9 100644 --- a/executor/wasm/tests/ee_966.rs +++ b/executor/wasm/tests/ee_966.rs @@ -1,3 +1,5 @@ +use std::{collections::BTreeSet, sync::Arc}; + use bytes::Bytes; use casper_execution_engine::engine_state::ExecutionEngineV1; use casper_executor_wasm::{ @@ -95,6 +97,7 @@ fn argument_size_exceeds_memory_limit() { .with_block_height(1) .with_parent_block_hash(BlockHash::new(Digest::hash(b"block1"))) .with_runtime_native_config(runtime_native_config) + .with_authorization_keys(BTreeSet::from_iter([*DEFAULT_ACCOUNT_HASH])) .build() .expect("should build"); let result = executor.execute_with_provider(state_root_hash, &global_state, execute_request); @@ -136,6 +139,7 @@ fn should_run_ee_966_with_zero_min_and_zero_max_memory() { .with_block_height(1) .with_parent_block_hash(BlockHash::new(Digest::hash(b"block1"))) .with_runtime_native_config(runtime_native_config) + .with_authorization_keys(BTreeSet::from_iter([*DEFAULT_ACCOUNT_HASH])) .build() .expect("should build"); @@ -174,6 +178,7 @@ fn should_run_ee_966_cant_have_too_much_initial_memory() { .with_block_height(1) .with_parent_block_hash(BlockHash::new(Digest::hash(b"block1"))) .with_runtime_native_config(runtime_native_config) + .with_authorization_keys(BTreeSet::from_iter([*DEFAULT_ACCOUNT_HASH])) .build() .expect("should build"); @@ -218,6 +223,7 @@ fn should_run_ee_966_cant_have_too_much_max_memory() { .with_block_height(1) .with_parent_block_hash(BlockHash::new(Digest::hash(b"block1"))) .with_runtime_native_config(runtime_native_config) + .with_authorization_keys(BTreeSet::from_iter([*DEFAULT_ACCOUNT_HASH])) .build() .expect("should build"); @@ -262,6 +268,7 @@ fn should_run_ee_966_cant_have_way_too_much_max_memory() { .with_block_height(1) .with_parent_block_hash(BlockHash::new(Digest::hash(b"block1"))) .with_runtime_native_config(runtime_native_config) + .with_authorization_keys(BTreeSet::from_iter([*DEFAULT_ACCOUNT_HASH])) .build() .expect("should build"); @@ -306,6 +313,7 @@ fn should_run_ee_966_cant_have_larger_initial_than_max_memory() { .with_block_height(1) .with_parent_block_hash(BlockHash::new(Digest::hash(b"block1"))) .with_runtime_native_config(runtime_native_config) + .with_authorization_keys(BTreeSet::from_iter([*DEFAULT_ACCOUNT_HASH])) .build() .expect("should build"); @@ -355,6 +363,7 @@ fn should_run_ee_966_should_request_exactly_maximum_as_initial() { .with_block_height(1) .with_parent_block_hash(BlockHash::new(Digest::hash(b"block1"))) .with_runtime_native_config(runtime_native_config) + .with_authorization_keys(BTreeSet::from_iter([*DEFAULT_ACCOUNT_HASH])) .build() .expect("should build"); @@ -395,6 +404,7 @@ fn should_run_ee_966_should_request_exactly_maximum() { .with_block_height(1) .with_parent_block_hash(BlockHash::new(Digest::hash(b"block1"))) .with_runtime_native_config(runtime_native_config) + .with_authorization_keys(BTreeSet::from_iter([*DEFAULT_ACCOUNT_HASH])) .build() .expect("should build"); @@ -434,6 +444,7 @@ fn should_run_ee_966_regression_fail_when_growing_mem_past_max() { .with_block_height(1) .with_parent_block_hash(BlockHash::new(Digest::hash(b"block1"))) .with_runtime_native_config(runtime_native_config) + .with_authorization_keys(BTreeSet::from_iter([*DEFAULT_ACCOUNT_HASH])) .build() .expect("should build"); @@ -444,8 +455,6 @@ fn should_run_ee_966_regression_fail_when_growing_mem_past_max() { execute_request, ); - println!("{:?}", result); - assert!(matches!( result, Ok(ExecuteWithProviderResult { diff --git a/executor/wasm_host/src/context.rs b/executor/wasm_host/src/context.rs index 71e406927f..ff98a59be9 100644 --- a/executor/wasm_host/src/context.rs +++ b/executor/wasm_host/src/context.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::{collections::BTreeSet, sync::Arc}; use bytes::Bytes; use casper_executor_wasm_interface::executor::Executor; @@ -47,4 +47,6 @@ pub struct Context { pub sandboxed: bool, /// Runtime native config. pub runtime_native_config: RuntimeNativeConfig, + /// Authorization keys for this execution. + pub authorization_keys: BTreeSet, } diff --git a/executor/wasm_host/src/host.rs b/executor/wasm_host/src/host.rs index d97a54dd69..a793b6a8aa 100644 --- a/executor/wasm_host/src/host.rs +++ b/executor/wasm_host/src/host.rs @@ -1030,6 +1030,7 @@ pub fn casper_create( .with_block_height(1) .with_parent_block_hash(BlockHash::new(Digest::from_raw([0; 32]))) .with_runtime_native_config(caller.context().runtime_native_config.clone()) + .with_authorization_keys(caller.context().authorization_keys.clone()) .build() .map_err(FatalHostError::ExecuteRequestBuildFailure)?; @@ -1180,6 +1181,7 @@ pub fn casper_system( .with_block_height(1) .with_parent_block_hash(BlockHash::new(Digest::from_raw([0; 32]))) .with_runtime_native_config(caller.context().runtime_native_config.clone()) + .with_authorization_keys(caller.context().authorization_keys.clone()) .build() .map_err(FatalHostError::ExecuteRequestBuildFailure)?; @@ -1276,6 +1278,7 @@ pub fn casper_call( .with_block_height(1) .with_parent_block_hash(BlockHash::new(Digest::from_raw([0; 32]))) .with_runtime_native_config(caller.context().runtime_native_config.clone()) + .with_authorization_keys(caller.context().authorization_keys.clone()) .build() .map_err(FatalHostError::ExecuteRequestBuildFailure)?; @@ -1864,6 +1867,7 @@ pub fn casper_upgrade( .with_block_height(1) .with_parent_block_hash(BlockHash::new(Digest::from_raw([0; 32]))) .with_runtime_native_config(caller.context().runtime_native_config.clone()) + .with_authorization_keys(caller.context().authorization_keys.clone()) .build() .map_err(FatalHostError::ExecuteRequestBuildFailure)?; diff --git a/executor/wasm_interface/src/executor.rs b/executor/wasm_interface/src/executor.rs index 4a224b25ab..62514730b0 100644 --- a/executor/wasm_interface/src/executor.rs +++ b/executor/wasm_interface/src/executor.rs @@ -1,4 +1,4 @@ -use std::sync::Arc; +use std::{collections::BTreeSet, sync::Arc}; use borsh::BorshSerialize; use bytes::Bytes; @@ -62,6 +62,8 @@ pub struct ExecuteRequest { pub sandboxed: bool, /// Runtime native config. pub runtime_native_config: RuntimeNativeConfig, + /// Authorization keys for this execution. + pub authorization_keys: BTreeSet, } /// Builder for `ExecuteRequest`. @@ -82,6 +84,7 @@ pub struct ExecuteRequestBuilder { block_height: Option, sandboxed: Option, runtime_native_config: Option, + authorization_keys: Option>, } impl ExecuteRequestBuilder { @@ -216,6 +219,12 @@ impl ExecuteRequestBuilder { self } + /// Set the authorization keys. + pub fn with_authorization_keys(mut self, authorization_keys: BTreeSet) -> Self { + self.authorization_keys = Some(authorization_keys); + self + } + /// Build the `ExecuteRequest`. pub fn build(self) -> Result { let initiator = self.initiator.ok_or("Initiator is not set")?; @@ -239,6 +248,9 @@ impl ExecuteRequestBuilder { let runtime_native_config = self .runtime_native_config .ok_or("Runtime native config not set")?; + let authorization_keys = self + .authorization_keys + .ok_or("Authorization keys are not set")?; Ok(ExecuteRequest { initiator, caller_key, @@ -255,6 +267,7 @@ impl ExecuteRequestBuilder { block_height, sandboxed, runtime_native_config, + authorization_keys, }) } } diff --git a/executor/wasmer_backend/src/lib.rs b/executor/wasmer_backend/src/lib.rs index f684e30dc2..ff2c2f0ba4 100644 --- a/executor/wasmer_backend/src/lib.rs +++ b/executor/wasmer_backend/src/lib.rs @@ -514,6 +514,7 @@ where runtime_native_config: data.context.runtime_native_config.clone(), parent_block_hash: data.context.parent_block_hash, block_height: data.context.block_height, + authorization_keys: data.context.authorization_keys.clone(), } } } diff --git a/node/src/components/contract_runtime/operations/wasm_v2_request.rs b/node/src/components/contract_runtime/operations/wasm_v2_request.rs index aa2b6347d8..3def39da62 100644 --- a/node/src/components/contract_runtime/operations/wasm_v2_request.rs +++ b/node/src/components/contract_runtime/operations/wasm_v2_request.rs @@ -261,6 +261,7 @@ impl WasmV2Request { .with_parent_block_hash(parent_block_hash) .with_block_height(block_height) .with_runtime_native_config(runtime_native_config) + .with_authorization_keys(transaction.signers()) .build() .expect("should build"); @@ -304,7 +305,12 @@ impl WasmV2Request { builder = builder.with_execution_kind(execution_kind); - let execute_request = builder.build().expect("should build"); + let authorization_keys = transaction.signers(); + + let execute_request = builder + .with_authorization_keys(authorization_keys) + .build() + .expect("should build"); Ok(Self::Execute(execute_request)) }