Skip to content

Commit 3c3d580

Browse files
authored
Merge pull request #5326 from igor-casper/core-217
[VM2] Support authorization keys
2 parents c3fcb5d + 291446d commit 3c3d580

File tree

9 files changed

+64
-7
lines changed

9 files changed

+64
-7
lines changed

executor/wasm/src/install.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::sync::Arc;
1+
use std::{collections::BTreeSet, sync::Arc};
22

33
use bytes::Bytes;
44
use casper_executor_wasm_common::error::CallError;
@@ -47,6 +47,8 @@ pub struct InstallContractRequest {
4747
pub(crate) seed: Option<[u8; 32]>,
4848
/// Runtime native config.
4949
pub(crate) runtime_native_config: RuntimeNativeConfig,
50+
/// Authorization keys for this installation.
51+
pub(crate) authorization_keys: BTreeSet<AccountHash>,
5052
}
5153

5254
#[derive(Default)]
@@ -66,6 +68,7 @@ pub struct InstallContractRequestBuilder {
6668
block_height: Option<u64>,
6769
runtime_native_config: Option<RuntimeNativeConfig>,
6870
seed: Option<[u8; 32]>,
71+
authorization_keys: Option<BTreeSet<AccountHash>>,
6972
}
7073

7174
impl InstallContractRequestBuilder {
@@ -155,6 +158,11 @@ impl InstallContractRequestBuilder {
155158
self
156159
}
157160

161+
pub fn with_authorization_keys(mut self, authorization_keys: BTreeSet<AccountHash>) -> Self {
162+
self.authorization_keys = Some(authorization_keys);
163+
self
164+
}
165+
158166
pub fn build(self) -> Result<InstallContractRequest, &'static str> {
159167
let initiator = self.initiator.ok_or("Initiator not set")?;
160168
let gas_limit = self.gas_limit.ok_or("Gas limit not set")?;
@@ -173,6 +181,9 @@ impl InstallContractRequestBuilder {
173181
let runtime_native_config = self
174182
.runtime_native_config
175183
.ok_or("Runtime native config not set")?;
184+
let authorization_keys = self
185+
.authorization_keys
186+
.ok_or("Authorization keys not set")?;
176187
Ok(InstallContractRequest {
177188
initiator,
178189
gas_limit,
@@ -189,6 +200,7 @@ impl InstallContractRequestBuilder {
189200
parent_block_hash,
190201
block_height,
191202
runtime_native_config,
203+
authorization_keys,
192204
})
193205
}
194206
}

executor/wasm/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ impl ExecutorV2 {
227227
parent_block_hash,
228228
block_height,
229229
runtime_native_config,
230+
authorization_keys,
230231
} = install_request;
231232

232233
let bytecode_hash = chain_utils::compute_wasm_bytecode_hash(&wasm_bytes);
@@ -450,6 +451,7 @@ impl ExecutorV2 {
450451
.with_parent_block_hash(parent_block_hash)
451452
.with_block_height(block_height)
452453
.with_runtime_native_config(runtime_native_config)
454+
.with_authorization_keys(authorization_keys)
453455
.build()
454456
.map_err(InstallContractError::FailedBuildingExecuteRequest)?;
455457

@@ -570,6 +572,7 @@ impl ExecutorV2 {
570572
block_height,
571573
sandboxed,
572574
runtime_native_config,
575+
authorization_keys,
573576
} = execute_request;
574577

575578
let (entity_addr, source_purse) = get_purse_for_entity(&mut tracking_copy, caller_key)?;
@@ -668,6 +671,7 @@ impl ExecutorV2 {
668671
block_info,
669672
transaction_hash,
670673
gas_limit,
674+
authorization_keys.clone(),
671675
);
672676
}
673677
EntityKind::SmartContract(ContractRuntimeTag::VmCasperV2) => {
@@ -859,6 +863,7 @@ impl ExecutorV2 {
859863
block_info,
860864
transaction_hash,
861865
gas_limit,
866+
authorization_keys,
862867
);
863868
}
864869
}
@@ -929,6 +934,7 @@ impl ExecutorV2 {
929934
runtime_native_config,
930935
parent_block_hash: parent_block_hash.inner().value(),
931936
block_height,
937+
authorization_keys,
932938
};
933939

934940
// Check that the input argument size does not exceed the VM memory limit
@@ -1067,11 +1073,11 @@ impl ExecutorV2 {
10671073
block_info: BlockInfo,
10681074
transaction_hash: TransactionHash,
10691075
gas_limit: u64,
1076+
authorization_keys: BTreeSet<AccountHash>,
10701077
) -> Result<ExecuteResult, ExecuteError>
10711078
where
10721079
R: GlobalStateReader + 'static,
10731080
{
1074-
let authorization_keys = BTreeSet::from_iter([initiator]);
10751081
let initiator_addr = InitiatorAddr::AccountHash(initiator);
10761082
let executable_item =
10771083
ExecutableItem::Invocation(TransactionInvocationTarget::ByHash(entity_addr.value()));
@@ -1284,6 +1290,7 @@ impl Executor for ExecutorV2 {
12841290
.with_block_height(request.block_height)
12851291
.with_sandboxed(true) // Enable sandboxed mode
12861292
.with_runtime_native_config(runtime_native_config)
1293+
.with_authorization_keys(BTreeSet::from_iter([request.initiator]))
12871294
.build()
12881295
.map_err(|error| {
12891296
ExecuteError::Fatal(FatalHostError::ExecuteRequestBuildFailure(error))

executor/wasm/src/testing.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::{
2+
collections::BTreeSet,
23
env, fs,
34
path::{Path, PathBuf},
45
sync::Arc,
@@ -151,6 +152,7 @@ pub fn base_execute_builder(chainspec_config: &ChainspecConfig) -> ExecuteReques
151152
.with_runtime_native_config(make_runtime_config(chainspec_config))
152153
.with_parent_block_hash(BlockHash::new(Digest::hash(b"block1")))
153154
.with_runtime_native_config(runtime_native_config)
155+
.with_authorization_keys(BTreeSet::from_iter([*DEFAULT_ACCOUNT_HASH]))
154156
}
155157

156158
pub fn make_runtime_config(chainspec_config: &ChainspecConfig) -> RuntimeNativeConfig {
@@ -212,6 +214,7 @@ pub fn base_install_request_builder(
212214
.with_runtime_native_config(make_runtime_config(chainspec_config))
213215
.with_parent_block_hash(BlockHash::new(Digest::hash(b"block1")))
214216
.with_runtime_native_config(runtime_native_config)
217+
.with_authorization_keys(BTreeSet::from_iter([*DEFAULT_ACCOUNT_HASH]))
215218
}
216219

217220
pub fn make_executor(chainspec_config: &ChainspecConfig) -> ExecutorV2 {

executor/wasm/tests/ee_966.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::{collections::BTreeSet, sync::Arc};
2+
13
use bytes::Bytes;
24
use casper_execution_engine::engine_state::ExecutionEngineV1;
35
use casper_executor_wasm::{
@@ -95,6 +97,7 @@ fn argument_size_exceeds_memory_limit() {
9597
.with_block_height(1)
9698
.with_parent_block_hash(BlockHash::new(Digest::hash(b"block1")))
9799
.with_runtime_native_config(runtime_native_config)
100+
.with_authorization_keys(BTreeSet::from_iter([*DEFAULT_ACCOUNT_HASH]))
98101
.build()
99102
.expect("should build");
100103
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() {
136139
.with_block_height(1)
137140
.with_parent_block_hash(BlockHash::new(Digest::hash(b"block1")))
138141
.with_runtime_native_config(runtime_native_config)
142+
.with_authorization_keys(BTreeSet::from_iter([*DEFAULT_ACCOUNT_HASH]))
139143
.build()
140144
.expect("should build");
141145

@@ -174,6 +178,7 @@ fn should_run_ee_966_cant_have_too_much_initial_memory() {
174178
.with_block_height(1)
175179
.with_parent_block_hash(BlockHash::new(Digest::hash(b"block1")))
176180
.with_runtime_native_config(runtime_native_config)
181+
.with_authorization_keys(BTreeSet::from_iter([*DEFAULT_ACCOUNT_HASH]))
177182
.build()
178183
.expect("should build");
179184

@@ -218,6 +223,7 @@ fn should_run_ee_966_cant_have_too_much_max_memory() {
218223
.with_block_height(1)
219224
.with_parent_block_hash(BlockHash::new(Digest::hash(b"block1")))
220225
.with_runtime_native_config(runtime_native_config)
226+
.with_authorization_keys(BTreeSet::from_iter([*DEFAULT_ACCOUNT_HASH]))
221227
.build()
222228
.expect("should build");
223229

@@ -262,6 +268,7 @@ fn should_run_ee_966_cant_have_way_too_much_max_memory() {
262268
.with_block_height(1)
263269
.with_parent_block_hash(BlockHash::new(Digest::hash(b"block1")))
264270
.with_runtime_native_config(runtime_native_config)
271+
.with_authorization_keys(BTreeSet::from_iter([*DEFAULT_ACCOUNT_HASH]))
265272
.build()
266273
.expect("should build");
267274

@@ -306,6 +313,7 @@ fn should_run_ee_966_cant_have_larger_initial_than_max_memory() {
306313
.with_block_height(1)
307314
.with_parent_block_hash(BlockHash::new(Digest::hash(b"block1")))
308315
.with_runtime_native_config(runtime_native_config)
316+
.with_authorization_keys(BTreeSet::from_iter([*DEFAULT_ACCOUNT_HASH]))
309317
.build()
310318
.expect("should build");
311319

@@ -355,6 +363,7 @@ fn should_run_ee_966_should_request_exactly_maximum_as_initial() {
355363
.with_block_height(1)
356364
.with_parent_block_hash(BlockHash::new(Digest::hash(b"block1")))
357365
.with_runtime_native_config(runtime_native_config)
366+
.with_authorization_keys(BTreeSet::from_iter([*DEFAULT_ACCOUNT_HASH]))
358367
.build()
359368
.expect("should build");
360369

@@ -395,6 +404,7 @@ fn should_run_ee_966_should_request_exactly_maximum() {
395404
.with_block_height(1)
396405
.with_parent_block_hash(BlockHash::new(Digest::hash(b"block1")))
397406
.with_runtime_native_config(runtime_native_config)
407+
.with_authorization_keys(BTreeSet::from_iter([*DEFAULT_ACCOUNT_HASH]))
398408
.build()
399409
.expect("should build");
400410

@@ -434,6 +444,7 @@ fn should_run_ee_966_regression_fail_when_growing_mem_past_max() {
434444
.with_block_height(1)
435445
.with_parent_block_hash(BlockHash::new(Digest::hash(b"block1")))
436446
.with_runtime_native_config(runtime_native_config)
447+
.with_authorization_keys(BTreeSet::from_iter([*DEFAULT_ACCOUNT_HASH]))
437448
.build()
438449
.expect("should build");
439450

@@ -444,8 +455,6 @@ fn should_run_ee_966_regression_fail_when_growing_mem_past_max() {
444455
execute_request,
445456
);
446457

447-
println!("{:?}", result);
448-
449458
assert!(matches!(
450459
result,
451460
Ok(ExecuteWithProviderResult {

executor/wasm_host/src/context.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::sync::Arc;
1+
use std::{collections::BTreeSet, sync::Arc};
22

33
use bytes::Bytes;
44
use casper_executor_wasm_interface::executor::Executor;
@@ -47,4 +47,6 @@ pub struct Context<S: GlobalStateReader, E: Executor> {
4747
pub sandboxed: bool,
4848
/// Runtime native config.
4949
pub runtime_native_config: RuntimeNativeConfig,
50+
/// Authorization keys for this execution.
51+
pub authorization_keys: BTreeSet<AccountHash>,
5052
}

executor/wasm_host/src/host.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,7 @@ pub fn casper_create<S: GlobalStateReader + 'static, E: Executor + 'static>(
10301030
.with_block_height(1)
10311031
.with_parent_block_hash(BlockHash::new(Digest::from_raw([0; 32])))
10321032
.with_runtime_native_config(caller.context().runtime_native_config.clone())
1033+
.with_authorization_keys(caller.context().authorization_keys.clone())
10331034
.build()
10341035
.map_err(FatalHostError::ExecuteRequestBuildFailure)?;
10351036

@@ -1180,6 +1181,7 @@ pub fn casper_system<S: GlobalStateReader + 'static, E: Executor + 'static>(
11801181
.with_block_height(1)
11811182
.with_parent_block_hash(BlockHash::new(Digest::from_raw([0; 32])))
11821183
.with_runtime_native_config(caller.context().runtime_native_config.clone())
1184+
.with_authorization_keys(caller.context().authorization_keys.clone())
11831185
.build()
11841186
.map_err(FatalHostError::ExecuteRequestBuildFailure)?;
11851187

@@ -1276,6 +1278,7 @@ pub fn casper_call<S: GlobalStateReader + 'static, E: Executor + 'static>(
12761278
.with_block_height(1)
12771279
.with_parent_block_hash(BlockHash::new(Digest::from_raw([0; 32])))
12781280
.with_runtime_native_config(caller.context().runtime_native_config.clone())
1281+
.with_authorization_keys(caller.context().authorization_keys.clone())
12791282
.build()
12801283
.map_err(FatalHostError::ExecuteRequestBuildFailure)?;
12811284

@@ -1864,6 +1867,7 @@ pub fn casper_upgrade<S: GlobalStateReader + 'static, E: Executor>(
18641867
.with_block_height(1)
18651868
.with_parent_block_hash(BlockHash::new(Digest::from_raw([0; 32])))
18661869
.with_runtime_native_config(caller.context().runtime_native_config.clone())
1870+
.with_authorization_keys(caller.context().authorization_keys.clone())
18671871
.build()
18681872
.map_err(FatalHostError::ExecuteRequestBuildFailure)?;
18691873

executor/wasm_interface/src/executor.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::sync::Arc;
1+
use std::{collections::BTreeSet, sync::Arc};
22

33
use borsh::BorshSerialize;
44
use bytes::Bytes;
@@ -62,6 +62,8 @@ pub struct ExecuteRequest {
6262
pub sandboxed: bool,
6363
/// Runtime native config.
6464
pub runtime_native_config: RuntimeNativeConfig,
65+
/// Authorization keys for this execution.
66+
pub authorization_keys: BTreeSet<AccountHash>,
6567
}
6668

6769
/// Builder for `ExecuteRequest`.
@@ -82,6 +84,7 @@ pub struct ExecuteRequestBuilder {
8284
block_height: Option<u64>,
8385
sandboxed: Option<bool>,
8486
runtime_native_config: Option<RuntimeNativeConfig>,
87+
authorization_keys: Option<BTreeSet<AccountHash>>,
8588
}
8689

8790
impl ExecuteRequestBuilder {
@@ -216,6 +219,12 @@ impl ExecuteRequestBuilder {
216219
self
217220
}
218221

222+
/// Set the authorization keys.
223+
pub fn with_authorization_keys(mut self, authorization_keys: BTreeSet<AccountHash>) -> Self {
224+
self.authorization_keys = Some(authorization_keys);
225+
self
226+
}
227+
219228
/// Build the `ExecuteRequest`.
220229
pub fn build(self) -> Result<ExecuteRequest, &'static str> {
221230
let initiator = self.initiator.ok_or("Initiator is not set")?;
@@ -239,6 +248,9 @@ impl ExecuteRequestBuilder {
239248
let runtime_native_config = self
240249
.runtime_native_config
241250
.ok_or("Runtime native config not set")?;
251+
let authorization_keys = self
252+
.authorization_keys
253+
.ok_or("Authorization keys are not set")?;
242254
Ok(ExecuteRequest {
243255
initiator,
244256
caller_key,
@@ -255,6 +267,7 @@ impl ExecuteRequestBuilder {
255267
block_height,
256268
sandboxed,
257269
runtime_native_config,
270+
authorization_keys,
258271
})
259272
}
260273
}

executor/wasmer_backend/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ where
514514
runtime_native_config: data.context.runtime_native_config.clone(),
515515
parent_block_hash: data.context.parent_block_hash,
516516
block_height: data.context.block_height,
517+
authorization_keys: data.context.authorization_keys.clone(),
517518
}
518519
}
519520
}

node/src/components/contract_runtime/operations/wasm_v2_request.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ impl WasmV2Request {
261261
.with_parent_block_hash(parent_block_hash)
262262
.with_block_height(block_height)
263263
.with_runtime_native_config(runtime_native_config)
264+
.with_authorization_keys(transaction.signers())
264265
.build()
265266
.expect("should build");
266267

@@ -304,7 +305,12 @@ impl WasmV2Request {
304305

305306
builder = builder.with_execution_kind(execution_kind);
306307

307-
let execute_request = builder.build().expect("should build");
308+
let authorization_keys = transaction.signers();
309+
310+
let execute_request = builder
311+
.with_authorization_keys(authorization_keys)
312+
.build()
313+
.expect("should build");
308314

309315
Ok(Self::Execute(execute_request))
310316
}

0 commit comments

Comments
 (0)