This repository was archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathwasm_validation.rs
More file actions
71 lines (59 loc) · 2.06 KB
/
wasm_validation.rs
File metadata and controls
71 lines (59 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.
// Polkadot is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Polkadot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
//! WASM validation for adder parachain.
use crate::{HeadData, BlockData, RelayChainParams};
use core::{intrinsics, panic};
use parachain::primitives::{ValidationResult, HeadData as GenericHeadData};
use codec::{Encode, Decode};
#[panic_handler]
#[no_mangle]
pub fn panic(_info: &panic::PanicInfo) -> ! {
unsafe {
intrinsics::abort()
}
}
#[alloc_error_handler]
#[no_mangle]
pub fn oom(_: core::alloc::Layout) -> ! {
unsafe {
intrinsics::abort();
}
}
#[no_mangle]
pub extern fn validate_block(params: *const u8, len: usize) -> u64 {
let params = unsafe { parachain::load_params(params, len) };
let parent_head = HeadData::decode(&mut ¶ms.parent_head.0[..])
.expect("invalid parent head format.");
let block_data = BlockData::decode(&mut ¶ms.block_data.0[..])
.expect("invalid block data format.");
let parent_hash = tiny_keccak::keccak256(¶ms.parent_head.0[..]);
let res = crate::execute(
parent_hash,
parent_head,
block_data,
&RelayChainParams {
code_upgrade_allowed: params.code_upgrade_allowed,
max_code_size: params.max_code_size,
relay_chain_block_number: params.relay_chain_height,
},
);
match res {
Ok(output) => parachain::write_result(
&ValidationResult {
head_data: GenericHeadData(output.head_data.encode()),
new_validation_code: output.new_validation_code,
}
),
Err(_) => panic!("execution failure"),
}
}