Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion executor/wasm/src/install.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{collections::BTreeSet, sync::Arc};

use bytes::Bytes;
use casper_executor_wasm_common::error::CallError;
Expand Down Expand Up @@ -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<AccountHash>,
}

#[derive(Default)]
Expand All @@ -66,6 +68,7 @@ pub struct InstallContractRequestBuilder {
block_height: Option<u64>,
runtime_native_config: Option<RuntimeNativeConfig>,
seed: Option<[u8; 32]>,
authorization_keys: Option<BTreeSet<AccountHash>>,
}

impl InstallContractRequestBuilder {
Expand Down Expand Up @@ -155,6 +158,11 @@ impl InstallContractRequestBuilder {
self
}

pub fn with_authorization_keys(mut self, authorization_keys: BTreeSet<AccountHash>) -> Self {
self.authorization_keys = Some(authorization_keys);
self
}

pub fn build(self) -> Result<InstallContractRequest, &'static str> {
let initiator = self.initiator.ok_or("Initiator not set")?;
let gas_limit = self.gas_limit.ok_or("Gas limit not set")?;
Expand All @@ -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,
Expand All @@ -189,6 +200,7 @@ impl InstallContractRequestBuilder {
parent_block_hash,
block_height,
runtime_native_config,
authorization_keys,
})
}
}
Expand Down
9 changes: 8 additions & 1 deletion executor/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)?;

Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -668,6 +671,7 @@ impl ExecutorV2 {
block_info,
transaction_hash,
gas_limit,
authorization_keys.clone(),
);
}
EntityKind::SmartContract(ContractRuntimeTag::VmCasperV2) => {
Expand Down Expand Up @@ -859,6 +863,7 @@ impl ExecutorV2 {
block_info,
transaction_hash,
gas_limit,
authorization_keys,
);
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1067,11 +1073,11 @@ impl ExecutorV2 {
block_info: BlockInfo,
transaction_hash: TransactionHash,
gas_limit: u64,
authorization_keys: BTreeSet<AccountHash>,
) -> Result<ExecuteResult, ExecuteError>
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()));
Expand Down Expand Up @@ -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))
Expand Down
3 changes: 3 additions & 0 deletions executor/wasm/src/testing.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{
collections::BTreeSet,
env, fs,
path::{Path, PathBuf},
sync::Arc,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 11 additions & 2 deletions executor/wasm/tests/ee_966.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::{collections::BTreeSet, sync::Arc};

use bytes::Bytes;
use casper_execution_engine::engine_state::ExecutionEngineV1;
use casper_executor_wasm::{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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");

Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion executor/wasm_host/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{collections::BTreeSet, sync::Arc};

use bytes::Bytes;
use casper_executor_wasm_interface::executor::Executor;
Expand Down Expand Up @@ -47,4 +47,6 @@ pub struct Context<S: GlobalStateReader, E: Executor> {
pub sandboxed: bool,
/// Runtime native config.
pub runtime_native_config: RuntimeNativeConfig,
/// Authorization keys for this execution.
pub authorization_keys: BTreeSet<AccountHash>,
}
4 changes: 4 additions & 0 deletions executor/wasm_host/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,7 @@ pub fn casper_create<S: GlobalStateReader + 'static, E: Executor + 'static>(
.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)?;

Expand Down Expand Up @@ -1180,6 +1181,7 @@ pub fn casper_system<S: GlobalStateReader + 'static, E: Executor + 'static>(
.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)?;

Expand Down Expand Up @@ -1276,6 +1278,7 @@ pub fn casper_call<S: GlobalStateReader + 'static, E: Executor + 'static>(
.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)?;

Expand Down Expand Up @@ -1864,6 +1867,7 @@ pub fn casper_upgrade<S: GlobalStateReader + 'static, E: Executor>(
.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)?;

Expand Down
15 changes: 14 additions & 1 deletion executor/wasm_interface/src/executor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{collections::BTreeSet, sync::Arc};

use borsh::BorshSerialize;
use bytes::Bytes;
Expand Down Expand Up @@ -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<AccountHash>,
}

/// Builder for `ExecuteRequest`.
Expand All @@ -82,6 +84,7 @@ pub struct ExecuteRequestBuilder {
block_height: Option<u64>,
sandboxed: Option<bool>,
runtime_native_config: Option<RuntimeNativeConfig>,
authorization_keys: Option<BTreeSet<AccountHash>>,
}

impl ExecuteRequestBuilder {
Expand Down Expand Up @@ -216,6 +219,12 @@ impl ExecuteRequestBuilder {
self
}

/// Set the authorization keys.
pub fn with_authorization_keys(mut self, authorization_keys: BTreeSet<AccountHash>) -> Self {
self.authorization_keys = Some(authorization_keys);
self
}

/// Build the `ExecuteRequest`.
pub fn build(self) -> Result<ExecuteRequest, &'static str> {
let initiator = self.initiator.ok_or("Initiator is not set")?;
Expand All @@ -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,
Expand All @@ -255,6 +267,7 @@ impl ExecuteRequestBuilder {
block_height,
sandboxed,
runtime_native_config,
authorization_keys,
})
}
}
Expand Down
1 change: 1 addition & 0 deletions executor/wasmer_backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down Expand Up @@ -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))
}
Expand Down