Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 3 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
28 changes: 27 additions & 1 deletion frame/contracts/src/wasm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ use sp_io::hashing::{
use pallet_contracts_primitives::{ExecResult, ExecReturnValue, ReturnFlags, ExecError};

/// Every error that can be returned to a contract when it calls any of the host functions.
///
/// # Note
///
/// This enum can be extended in the future: New codes can be added but existing codes
/// will not be changed or removed. This means that any contract **must not** exhaustively
/// match return codes. Instead, contracts should prepare for unknown variants and deal with
/// those errors gracefuly in order to be forward compatible.
#[repr(u32)]
pub enum ReturnCode {
/// API call successful.
Expand Down Expand Up @@ -935,6 +942,16 @@ define_env!(Env, <E: Ext>,
Err(TrapReason::Termination)
},

// Stores the input passed by the caller into the supplied buffer.
//
// The value is stored to linear memory at the address pointed to by `out_ptr`.
Comment thread
athei marked this conversation as resolved.
// `out_len_ptr` must point to a u32 value that describes the available space at
// `out_ptr`. This call overwrites it with the size of the value. If the available
// space at `out_ptr` is less than the size of the value a trap is triggered.
//
// # Note
//
// This function can only be called once. Calling it multiple times will trigger a trap.
seal_input(ctx, buf_ptr: u32, buf_len_ptr: u32) => {
ctx.charge_gas(RuntimeToken::InputBase)?;
if let Some(input) = ctx.input_data.take() {
Expand Down Expand Up @@ -1138,8 +1155,16 @@ define_env!(Env, <E: Ext>,
// the caller contract and restore the destination contract and set the specified `rent_allowance`.
// All caller's funds are transfered to the destination.
//
// The tombstone hash is derived as `hash(code_hash, storage_root_hash)`. In order to match
// this hash to its own hash the restorer must make its storage equal to the one of the
// evicted destination contract. In order to allow for additional storage items in the
// restoring contract a delta can be specified to this function. All keys specified as
// delta are disregarded when calculating the storage root hash.
//
// If there is no tombstone at the destination address, the hashes don't match or this contract
// instance is already present on the contract call stack, a trap is generated.
// instance is already present on the contract call stack, a trap is generated. Additionally,
Comment thread
ascjones marked this conversation as resolved.
Outdated
// if the code hash was also evicted this function will trap. Before a restoration can be
// performed the code hash must be redeployed using `instantiate_with_code`.
//
// Otherwise, the destination contract is restored. This function is diverging and stops execution
// even on success.
Expand All @@ -1157,6 +1182,7 @@ define_env!(Env, <E: Ext>,
//
// - Tombstone hashes do not match
// - Calling cantract is live i.e is already on the call stack.
// - The supplied code_hash does not exist on-chain.
seal_restore_to(
ctx,
dest_ptr: u32,
Expand Down