Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
30e3681
[core] remove get_runtime_storage and invoke_runtime
Robbepop Jul 23, 2020
6ab2037
[core] invalidate all implementations and usages of ext functions
Robbepop Jul 23, 2020
cfb45b7
[core] adjust ext_ functions in ext.rs
Robbepop Jul 23, 2020
7d375cb
[core] add ReturnFlags to public API
Robbepop Jul 23, 2020
a94c397
[core] remove off-chain impls for get_runtime_storage and invoke_runtime
Robbepop Jul 23, 2020
f69bd94
[core] rename ext::ext_input -> ext::input
Robbepop Jul 23, 2020
bcce3b5
[core] change return type of get_contract_storage
Robbepop Jul 23, 2020
7a66772
[core] add conversion from ext::Error to EnvError
Robbepop Jul 23, 2020
c38648f
[core] on-chain: add new utilities for static buffer modifications
Robbepop Jul 23, 2020
4d6444b
[core] add impls for on-chain property getters
Robbepop Jul 23, 2020
a30387e
[core] remove no longer needed utiltiy function
Robbepop Jul 23, 2020
3061018
[core] on-chain: new impl for invoke_contract and eval_contract
Robbepop Jul 23, 2020
6db759c
[core] on-chain: new impl for get_contract_storage
Robbepop Jul 23, 2020
efff63f
[core] on-chain: new impl for decode_input
Robbepop Jul 23, 2020
4de4c3f
[core] on-chain: new impl for output
Robbepop Jul 23, 2020
fcb3965
[core] on-chain: new impl for instantiate_contract
Robbepop Jul 23, 2020
753732b
[core] on-chain: remove unused API
Robbepop Jul 24, 2020
3a0fd5c
[core] on-chain: move EncodeScope and ScopedBuffer to buffer.rs
Robbepop Jul 24, 2020
88eb1d7
[core] on-chain: implement rest of the on-chain API
Robbepop Jul 24, 2020
7a79031
[core] add ScopedBuffer::take_bytes
Robbepop Jul 24, 2020
f98500e
[core] Add Env::call_chain_extension trait method
Robbepop Jul 24, 2020
bc476eb
[core] remove unused helper methods
Robbepop Jul 24, 2020
7bd94e2
[core] on-chain: simplify static buffer
Robbepop Jul 24, 2020
a375469
[core] add env::call_chain_extension public API
Robbepop Jul 24, 2020
b535def
[core] rename Env::output -> return_value
Robbepop Jul 24, 2020
03e252d
[core] off-chain: adjust a bunch of off-chain methods to new interfaces
Robbepop Jul 24, 2020
fc5a9a5
[core] off-chain: adjust get_contract_storage return type
Robbepop Jul 24, 2020
559bb83
[core] off-chain: remove RuntimeCallHandler and RuntimeStorage facili…
Robbepop Jul 24, 2020
4bd3d1f
[core] off-chain: adjust some tests
Robbepop Jul 24, 2020
184bcee
[core] off-chain: remove OffCall utility type
Robbepop Jul 24, 2020
89318e8
[core] off-chain: implement chain extension handler
Robbepop Jul 24, 2020
c6fb977
[core] adjust panic message
Robbepop Jul 24, 2020
51ec933
[core] apply rustfmt
Robbepop Jul 24, 2020
a223d09
[core] apply clippy suggestion
Robbepop Jul 24, 2020
57a9eec
[core] off-chain: re-export ChainExtension and ChainSpec types from t…
Robbepop Jul 24, 2020
3839a5f
[core] on-chain: retain panic messages
Robbepop Jul 24, 2020
2d4af76
[core] rename ext_ to seal_ for all on-chain functions
Robbepop Aug 24, 2020
a1f3ce1
[alloc] fix some warnings and add some minor comments
Robbepop Aug 24, 2020
49f0e66
[core] add wasm_import_module = "seal0"
Robbepop Aug 24, 2020
71acbf5
[core] introduce new Seal error codes
Robbepop Aug 25, 2020
45d58b4
[core] directly return ReturnCode from C-FII
Robbepop Aug 25, 2020
df9ba20
[core] make transfer return Result
Robbepop Aug 25, 2020
91e5025
[core] improve some doc comments
Robbepop Aug 25, 2020
515fecf
rename some old errors to their new names
Robbepop Aug 25, 2020
294fe0b
[core] remove unused env errors and rename some off-chain errors
Robbepop Aug 25, 2020
9e90b61
[core] fix bug in ReturnFlags::set_reverted (formerly known as set_tr…
Robbepop Aug 25, 2020
8ee6899
[core] avoid From impl for () for OffChainError
Robbepop Aug 25, 2020
48bae3a
[lang] adjust lang layer for changes in core
Robbepop Aug 25, 2020
e3b8a3e
[core] turn redundant asserts into debug_assert
Robbepop Aug 25, 2020
4b6c243
[core] be more strict when handling ext::get_storage error
Robbepop Aug 25, 2020
bde67f7
[core] implement clippy suggestion
Robbepop Aug 25, 2020
fcd8cca
[examples] remove no longer useful runtime-storage contract
Robbepop Aug 25, 2020
c71223f
[core] disable chain extensions by default
Robbepop Aug 25, 2020
526075d
[lang] apply clippy suggestion to use matches! macro
Robbepop Aug 25, 2020
e14e378
[core] fix docs for ext_return
Robbepop Aug 25, 2020
8a18087
[core] fix return type of api::return_value
Robbepop Aug 25, 2020
a69bac1
[core] fix doc comment of Env::return_value
Robbepop Aug 25, 2020
08981a1
Merge branch 'sync-substrate-rc5' of github.com:paritytech/ink into s…
Robbepop Aug 25, 2020
fcedd58
[core] introduce RawReturnCode as a layer between Seal error codes an…
Robbepop Aug 25, 2020
52a3fbc
[alloc] make #[alloc_error_handler] private
Robbepop Aug 25, 2020
b6d2145
[alloc, core] move alloc_handler from ink_alloc to ink_core
Robbepop Aug 25, 2020
03e3108
[core] replace useless intermediate ReturnCode type
Robbepop Aug 25, 2020
ddce2f7
[core] rename RawReturnCode -> ReturnCode
Robbepop Aug 25, 2020
5b7d672
[core] apply rustfmt
Robbepop Aug 25, 2020
fc11ce4
[core] apply rustfmt
Robbepop Aug 25, 2020
d22b2cd
[core] off-chain: rename invoke -> eval for chain extension calling
Robbepop Aug 25, 2020
8c84b1d
[core] use Ptr32 and Ptr32Mut to encapsulate pointer -> u32 conversions
Robbepop Aug 25, 2020
402728d
[core] make new Ptr32 and Ptr32Mut abstractions more type safe
Robbepop Aug 25, 2020
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
11 changes: 2 additions & 9 deletions alloc/src/handlers.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018-2019 Parity Technologies (UK) Ltd.
// Copyright 2018-2020 Parity Technologies (UK) Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -12,14 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#[panic_handler]
pub fn panic(_info: &core::panic::PanicInfo) -> ! {
core::intrinsics::abort()
}

// `extern` fn uses type `core::alloc::Layout`, which is not FFI-safe
#[allow(improper_ctypes)]
#[alloc_error_handler]
pub extern "C" fn oom(_: core::alloc::Layout) -> ! {
fn oom(_: core::alloc::Layout) -> ! {
core::intrinsics::abort()
}
5 changes: 3 additions & 2 deletions alloc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018-2019 Parity Technologies (UK) Ltd.
// Copyright 2018-2020 Parity Technologies (UK) Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,8 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc_error_handler, core_intrinsics))]

// Use `wee_alloc` as the global allocator.
// We use `wee_alloc` as the global allocator since it is optimized for binary file size
// so that contracts compiled with it as allocator do not grow too much in size.
#[cfg(not(feature = "std"))]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
Expand Down
1 change: 1 addition & 0 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ std = [
"blake2",
]
ink-fuzz-tests = ["std"]
ink-unstable-chain-extensions = []

[[bench]]
name = "bench_lazy"
Expand Down
82 changes: 38 additions & 44 deletions core/src/env/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use crate::env::{
backend::{
Env,
ReturnFlags,
TypedEnv,
},
call::{
Expand Down Expand Up @@ -65,12 +66,12 @@ where
/// # Errors
///
/// If the returned value cannot be properly decoded.
pub fn gas_price<T>(gas: u64) -> Result<T::Balance>
pub fn weight_to_fee<T>(gas: u64) -> Result<T::Balance>
where
T: EnvTypes,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::gas_price::<T>(instance, gas)
TypedEnv::weight_to_fee::<T>(instance, gas)
})
}

Expand Down Expand Up @@ -208,6 +209,10 @@ where
}

/// Writes the value to the contract storage under the given key.
///
/// # Panics
///
/// - If the encode length of value exceeds the configured maximum value length of a storage entry.
pub fn set_contract_storage<V>(key: &Key, value: &V)
where
V: scale::Encode,
Expand All @@ -221,8 +226,8 @@ where
///
/// # Errors
///
/// - If the decoding of the typed value failed
pub fn get_contract_storage<R>(key: &Key) -> Option<Result<R>>
/// - If the decoding of the typed value failed (`KeyNotFound`)
pub fn get_contract_storage<R>(key: &Key) -> Result<Option<R>>
where
R: scale::Decode,
{
Expand All @@ -238,25 +243,6 @@ pub fn clear_contract_storage(key: &Key) {
})
}

/// Invokes a call to the runtime.
///
/// # Note
///
/// The call is not guaranteed to execute immediately but might be deferred
/// to the end of the contract execution.
///
/// # Errors
///
/// - If the called runtime function does not exist.
pub fn invoke_runtime<T>(params: &T::Call) -> Result<()>
where
T: EnvTypes,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
TypedEnv::invoke_runtime::<T>(instance, params)
})
}

/// Invokes a contract message.
///
/// # Note
Expand All @@ -268,7 +254,8 @@ where
///
/// # Errors
///
/// - If the called contract does not exist.
/// - If the called account does not exist.
/// - If the called account is not a contract.
/// - If the called contract is a tombstone.
/// - If arguments passed to the called contract message are invalid.
/// - If the called contract execution has trapped.
Expand All @@ -292,7 +279,8 @@ where
///
/// # Errors
///
/// - If the called contract does not exist.
/// - If the called account does not exist.
/// - If the called account is not a contract.
/// - If the called contract is a tombstone.
/// - If arguments passed to the called contract message are invalid.
/// - If the called contract execution has trapped.
Expand Down Expand Up @@ -424,7 +412,7 @@ where
/// contract call or invoke a runtime function that performs the
/// transaction.
///
/// # Errors
/// # Panics
///
/// If the contract doesn't have sufficient funds.
pub fn transfer<T>(destination: T::AccountId, value: T::Balance) -> Result<()>
Expand All @@ -436,6 +424,27 @@ where
})
}

/// Calls the chain extension with the given ID and inputs.
///
/// Returns the given output type.
///
/// # Errors
///
/// - If the given function ID does not exist in the runtime.
/// - If the given inputs cannot be properly decoded by the runtime.
/// - If the given output type cannot be properly decoded by the contract.
/// - If some chain extension specific conditions are not met.
#[cfg(feature = "ink-unstable-chain-extensions")]
pub fn call_chain_extension<I, O>(func_id: u32, input: &I) -> Result<O>
where
I: scale::Codec + 'static,
O: scale::Codec + 'static,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
Env::call_chain_extension(instance, func_id, input)
})
}

/// Returns the execution input to the executed contract and decodes it as `T`.
///
/// # Note
Expand Down Expand Up @@ -470,14 +479,13 @@ where
///
/// # Note
///
/// This call must be the last call to the contract
/// environment for every contract execution.
pub fn output<R>(return_value: &R)
/// This function stops the execution of the contract immediately.
pub fn return_value<R>(return_flags: ReturnFlags, return_value: &R) -> !
where
R: scale::Encode,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
Env::output::<R>(instance, return_value)
Env::return_value::<R>(instance, return_flags, return_value)
})
}

Expand Down Expand Up @@ -505,20 +513,6 @@ pub fn println(content: &str) {
<EnvInstance as OnInstance>::on_instance(|instance| Env::println(instance, content))
}

/// Returns the value from the *runtime* storage at the position of the key if any.
///
/// # Errors
///
/// - If the decoding of the typed value failed
pub fn get_runtime_storage<R>(runtime_key: &[u8]) -> Option<Result<R>>
where
R: scale::Decode,
{
<EnvInstance as OnInstance>::on_instance(|instance| {
Env::get_runtime_storage::<R>(instance, runtime_key)
})
}

/// Built-in efficient cryptographic hash functions.
pub mod hash {
use super::*;
Expand Down
75 changes: 51 additions & 24 deletions core/src/env/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,33 @@ use crate::env::{
};
use ink_primitives::Key;

/// The flags to indicate further information about the end of a contract execution.
pub struct ReturnFlags {
value: u32,
}

impl Default for ReturnFlags {
fn default() -> Self {
Self { value: 0 }
}
}

impl ReturnFlags {
/// Sets the bit to indicate that the execution is going to be reverted.
pub fn set_reverted(mut self, has_reverted: bool) -> Self {
match has_reverted {
true => self.value |= has_reverted as u32,
false => self.value &= !has_reverted as u32,
}
self
}

/// Returns the underlying `u32` representation.
pub(crate) fn into_u32(self) -> u32 {
self.value
}
}

/// Environmental contract functionality that does not require `EnvTypes`.
pub trait Env {
/// Writes the value to the contract storage under the given key.
Expand All @@ -36,22 +63,13 @@ pub trait Env {
/// # Errors
///
/// - If the decoding of the typed value failed
fn get_contract_storage<R>(&mut self, key: &Key) -> Option<Result<R>>
fn get_contract_storage<R>(&mut self, key: &Key) -> Result<Option<R>>
where
R: scale::Decode;

/// Clears the contract's storage key entry.
fn clear_contract_storage(&mut self, key: &Key);

/// Returns the value from the *runtime* storage at the position of the key if any.
///
/// # Errors
///
/// - If the decoding of the typed value failed
fn get_runtime_storage<R>(&mut self, runtime_key: &[u8]) -> Option<Result<R>>
where
R: scale::Decode;

/// Returns the execution input to the executed contract and decodes it as `T`.
///
/// # Note
Expand Down Expand Up @@ -83,10 +101,12 @@ pub trait Env {
///
/// # Note
///
/// The setting of this property must be the last interaction between
/// the executed contract and its environment.
/// The environment access asserts this guarantee.
fn output<R>(&mut self, return_value: &R)
/// Calling this method will end contract execution immediately.
/// It will return the given return value back to its caller.
///
/// The `flags` parameter can be used to revert the state changes of the
/// entire execution if necessary.
fn return_value<R>(&mut self, flags: ReturnFlags, return_value: &R) -> !
where
R: scale::Encode;

Expand All @@ -108,6 +128,22 @@ pub trait Env {
/// Conducts the BLAKE2 128-bit hash of the input
/// puts the result into the output buffer.
fn hash_blake2_128(input: &[u8], output: &mut [u8; 16]);

/// Calls the chain extension with the given ID and inputs.
///
/// Returns the output of the chain extension of the specified type.
///
/// # Errors
///
/// - If the chain extension with the given ID does not exist.
/// - If the inputs had an unexpected encoding.
/// - If the output could not be properly decoded.
/// - If some extension specific condition has not been met.
#[cfg(feature = "ink-unstable-chain-extensions")]
fn call_chain_extension<I, O>(&mut self, func_id: u32, input: &I) -> Result<O>
where
I: scale::Codec + 'static,
O: scale::Codec + 'static;
}

/// Environmental contract functionality.
Expand All @@ -131,7 +167,7 @@ pub trait TypedEnv: Env {
/// # Note
///
/// For more details visit: [`ink_core::env::gas_price`]
fn gas_price<T: EnvTypes>(&mut self, gas: u64) -> Result<T::Balance>;
fn weight_to_fee<T: EnvTypes>(&mut self, gas: u64) -> Result<T::Balance>;

/// Returns the amount of gas left for the contract execution.
///
Expand Down Expand Up @@ -208,15 +244,6 @@ pub trait TypedEnv: Env {
where
T: EnvTypes;

/// Invokes a call of the runtime.
///
/// # Note
///
/// For more details visit: [`ink_core::env::invoke_runtime`]
fn invoke_runtime<T>(&mut self, call: &T::Call) -> Result<()>
where
T: EnvTypes;

/// Invokes a contract message.
///
/// # Note
Expand Down
Loading