Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
[contracts] stabilize seal_code_hash, seal_set_code_hash and `sea…
Browse files Browse the repository at this point in the history
…l_own_code_hash` (#11337)

* stabilize seal_code_hash, seal_set_code_hash, seal_own_code_hash

* fix missed place found by CI

* Fixed missed __unstable__

Co-authored-by: Alexander Theißen <alex.theissen@me.com>
  • Loading branch information
agryaznov and athei committed May 4, 2022
1 parent 1a32a31 commit 392f0b1
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 20 deletions.
2 changes: 1 addition & 1 deletion frame/contracts/fixtures/set_code_hash.wat
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(module
(import "seal0" "seal_input" (func $seal_input (param i32 i32)))
(import "seal0" "seal_return" (func $seal_return (param i32 i32 i32)))
(import "__unstable__" "seal_set_code_hash" (func $seal_set_code_hash (param i32) (result i32)))
(import "seal0" "seal_set_code_hash" (func $seal_set_code_hash (param i32) (result i32)))

(import "env" "memory" (memory 1 1))

Expand Down
6 changes: 3 additions & 3 deletions frame/contracts/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ benchmarks! {
let code = WasmModule::<T>::from(ModuleDefinition {
memory: Some(ImportedMemory::max::<T>()),
imported_functions: vec![ImportedFunction {
module: "__unstable__",
module: "seal0",
name: "seal_code_hash",
params: vec![ValueType::I32, ValueType::I32, ValueType::I32],
return_type: Some(ValueType::I32),
Expand Down Expand Up @@ -484,7 +484,7 @@ benchmarks! {
seal_own_code_hash {
let r in 0 .. API_BENCHMARK_BATCHES;
let instance = Contract::<T>::new(WasmModule::getter(
"__unstable__", "seal_own_code_hash", r * API_BENCHMARK_BATCH_SIZE
"seal0", "seal_own_code_hash", r * API_BENCHMARK_BATCH_SIZE
), vec![])?;
let origin = RawOrigin::Signed(instance.caller.clone());
}: call(origin, instance.addr, 0u32.into(), Weight::MAX, None, vec![])
Expand Down Expand Up @@ -2017,7 +2017,7 @@ benchmarks! {
let code = WasmModule::<T>::from(ModuleDefinition {
memory: Some(ImportedMemory::max::<T>()),
imported_functions: vec![ImportedFunction {
module: "__unstable__",
module: "seal0",
name: "seal_set_code_hash",
params: vec![
ValueType::I32,
Expand Down
1 change: 0 additions & 1 deletion frame/contracts/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3088,7 +3088,6 @@ fn code_rejected_error_works() {
}

#[test]
#[cfg(feature = "unstable-interface")]
fn set_code_hash() {
let (wasm, code_hash) = compile_module::<Test>("set_code_hash").unwrap();
let (new_wasm, new_code_hash) = compile_module::<Test>("new_set_code_hash_contract").unwrap();
Expand Down
9 changes: 3 additions & 6 deletions frame/contracts/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2407,12 +2407,11 @@ mod tests {
}

#[test]
#[cfg(feature = "unstable-interface")]
fn code_hash_works() {
/// calls `seal_code_hash` and compares the result with the constant.
const CODE_CODE_HASH: &str = r#"
(module
(import "__unstable__" "seal_code_hash" (func $seal_code_hash (param i32 i32 i32) (result i32)))
(import "seal0" "seal_code_hash" (func $seal_code_hash (param i32 i32 i32) (result i32)))
(import "env" "memory" (memory 1 1))
;; size of our buffer is 32 bytes
Expand Down Expand Up @@ -2460,12 +2459,11 @@ mod tests {
}

#[test]
#[cfg(feature = "unstable-interface")]
fn own_code_hash_works() {
/// calls `seal_own_code_hash` and compares the result with the constant.
const CODE_OWN_CODE_HASH: &str = r#"
(module
(import "__unstable__" "seal_own_code_hash" (func $seal_own_code_hash (param i32 i32)))
(import "seal0" "seal_own_code_hash" (func $seal_own_code_hash (param i32 i32)))
(import "env" "memory" (memory 1 1))
;; size of our buffer is 32 bytes
Expand Down Expand Up @@ -2546,11 +2544,10 @@ mod tests {
}

#[test]
#[cfg(feature = "unstable-interface")]
fn set_code_hash() {
const CODE: &str = r#"
(module
(import "__unstable__" "seal_set_code_hash" (func $seal_set_code_hash (param i32) (result i32)))
(import "seal0" "seal_set_code_hash" (func $seal_set_code_hash (param i32) (result i32)))
(import "env" "memory" (memory 1 1))
(func $assert (param i32)
(block $ok
Expand Down
12 changes: 3 additions & 9 deletions frame/contracts/src/wasm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,8 @@ pub enum RuntimeCosts {
/// Weight of calling `seal_is_contract`.
IsContract,
/// Weight of calling `seal_code_hash`.
#[cfg(feature = "unstable-interface")]
CodeHash,
/// Weight of calling `seal_own_code_hash`.
#[cfg(feature = "unstable-interface")]
OwnCodeHash,
/// Weight of calling `seal_caller_is_origin`.
CallerIsOrigin,
Expand Down Expand Up @@ -225,7 +223,6 @@ pub enum RuntimeCosts {
#[cfg(feature = "unstable-interface")]
CallRuntime(Weight),
/// Weight of calling `seal_set_code_hash`
#[cfg(feature = "unstable-interface")]
SetCodeHash,
/// Weight of calling `ecdsa_to_eth_address`
#[cfg(feature = "unstable-interface")]
Expand All @@ -245,9 +242,7 @@ impl RuntimeCosts {
CopyToContract(len) => s.input_per_byte.saturating_mul(len.into()),
Caller => s.caller,
IsContract => s.is_contract,
#[cfg(feature = "unstable-interface")]
CodeHash => s.code_hash,
#[cfg(feature = "unstable-interface")]
OwnCodeHash => s.own_code_hash,
CallerIsOrigin => s.caller_is_origin,
Address => s.address,
Expand Down Expand Up @@ -312,7 +307,6 @@ impl RuntimeCosts {

#[cfg(feature = "unstable-interface")]
CallRuntime(weight) => weight,
#[cfg(feature = "unstable-interface")]
SetCodeHash => s.set_code_hash,
#[cfg(feature = "unstable-interface")]
EcdsaToEthAddress => s.ecdsa_to_eth_address,
Expand Down Expand Up @@ -1401,7 +1395,7 @@ define_env!(Env, <E: Ext>,
// # Errors
//
// `ReturnCode::KeyNotFound`
[__unstable__] seal_code_hash(ctx, account_ptr: u32, out_ptr: u32, out_len_ptr: u32) -> ReturnCode => {
[seal0] seal_code_hash(ctx, account_ptr: u32, out_ptr: u32, out_len_ptr: u32) -> ReturnCode => {
ctx.charge_gas(RuntimeCosts::CodeHash)?;
let address: <<E as Ext>::T as frame_system::Config>::AccountId =
ctx.read_sandbox_memory_as(account_ptr)?;
Expand All @@ -1420,7 +1414,7 @@ define_env!(Env, <E: Ext>,
// - `out_ptr`: pointer to the linear memory where the returning value is written to.
// - `out_len_ptr`: in-out pointer into linear memory where the buffer length
// is read from and the value length is written to.
[__unstable__] seal_own_code_hash(ctx, out_ptr: u32, out_len_ptr: u32) => {
[seal0] seal_own_code_hash(ctx, out_ptr: u32, out_len_ptr: u32) => {
ctx.charge_gas(RuntimeCosts::OwnCodeHash)?;
let code_hash_encoded = &ctx.ext.own_code_hash().encode();
Ok(ctx.write_sandbox_output(out_ptr, out_len_ptr, code_hash_encoded, false, already_charged)?)
Expand Down Expand Up @@ -2048,7 +2042,7 @@ define_env!(Env, <E: Ext>,
// # Errors
//
// `ReturnCode::CodeNotFound`
[__unstable__] seal_set_code_hash(ctx, code_hash_ptr: u32) -> ReturnCode => {
[seal0] seal_set_code_hash(ctx, code_hash_ptr: u32) -> ReturnCode => {
ctx.charge_gas(RuntimeCosts::SetCodeHash)?;
let code_hash: CodeHash<<E as Ext>::T> = ctx.read_sandbox_memory_as(code_hash_ptr)?;
match ctx.ext.set_code_hash(code_hash) {
Expand Down

0 comments on commit 392f0b1

Please sign in to comment.