[contracts] stabilize seal_code_hash, seal_set_code_hash and seal_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>
This commit is contained in:
Alexander Gryaznov
2022-05-04 10:35:30 +03:00
committed by GitHub
parent e8c688e301
commit 9fd4df9ccf
5 changed files with 10 additions and 20 deletions
@@ -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))
@@ -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),
@@ -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![])
@@ -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,
-1
View File
@@ -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();
+3 -6
View File
@@ -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
@@ -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
@@ -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
@@ -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,
@@ -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")]
@@ -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,
@@ -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,
@@ -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)?;
@@ -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)?)
@@ -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) {