mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 04:07:57 +00:00
contracts: Upgrade to wasmi 0.28 (#13312)
* Upgrade to wasmi 0.28 * ".git/.scripts/commands/bench/bench.sh" pallet dev pallet_contracts * Update stale comment * Renamed variants of `Determinism` * Compile fix --------- Co-authored-by: command-bot <>
This commit is contained in:
committed by
GitHub
parent
d5650ba07b
commit
82cb69922f
Generated
+11
-10
@@ -5751,7 +5751,7 @@ dependencies = [
|
||||
"sp-runtime",
|
||||
"sp-std",
|
||||
"wasm-instrument 0.4.0",
|
||||
"wasmi 0.20.0",
|
||||
"wasmi 0.28.0",
|
||||
"wasmparser-nostd",
|
||||
"wat",
|
||||
]
|
||||
@@ -12188,13 +12188,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasmi"
|
||||
version = "0.20.0"
|
||||
version = "0.28.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "01bf50edb2ea9d922aa75a7bf3c15e26a6c9e2d18c56e862b49737a582901729"
|
||||
checksum = "8e61a7006b0fdf24f6bbe8dcfdad5ca1b350de80061fb2827f31c82fbbb9565a"
|
||||
dependencies = [
|
||||
"spin 0.9.5",
|
||||
"wasmi_arena",
|
||||
"wasmi_core 0.5.0",
|
||||
"wasmi_core 0.12.0",
|
||||
"wasmparser-nostd",
|
||||
]
|
||||
|
||||
@@ -12209,9 +12209,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasmi_arena"
|
||||
version = "0.1.0"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1ea379cbb0b41f3a9f0bf7b47036d036aae7f43383d8cc487d4deccf40dee0a"
|
||||
checksum = "401c1f35e413fac1846d4843745589d9ec678977ab35a384db8ae7830525d468"
|
||||
|
||||
[[package]]
|
||||
name = "wasmi_core"
|
||||
@@ -12229,13 +12229,14 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasmi_core"
|
||||
version = "0.5.0"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c5bf998ab792be85e20e771fe14182b4295571ad1d4f89d3da521c1bef5f597a"
|
||||
checksum = "624e6333e861ef49095d2d678b76ebf30b06bf37effca845be7e5b87c90071b7"
|
||||
dependencies = [
|
||||
"downcast-rs",
|
||||
"libm 0.2.6",
|
||||
"num-traits",
|
||||
"paste",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -12250,9 +12251,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "wasmparser-nostd"
|
||||
version = "0.91.0"
|
||||
version = "0.100.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c37f310b5a62bfd5ae7c0f1d8e6f98af16a5d6d84ba764e9c36439ec14e318b"
|
||||
checksum = "9157cab83003221bfd385833ab587a039f5d6fa7304854042ba358a3b09e0724"
|
||||
dependencies = [
|
||||
"indexmap-nostd",
|
||||
]
|
||||
|
||||
@@ -2147,7 +2147,7 @@ impl_runtime_apis! {
|
||||
storage_deposit_limit,
|
||||
input_data,
|
||||
true,
|
||||
pallet_contracts::Determinism::Deterministic,
|
||||
pallet_contracts::Determinism::Enforced,
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,8 @@ serde = { version = "1", optional = true, features = ["derive"] }
|
||||
smallvec = { version = "1", default-features = false, features = [
|
||||
"const_generics",
|
||||
] }
|
||||
wasmi = { version = "0.20", default-features = false }
|
||||
wasmparser = { package = "wasmparser-nostd", version = "0.91", default-features = false }
|
||||
wasmi = { version = "0.28", default-features = false }
|
||||
wasmparser = { package = "wasmparser-nostd", version = "0.100", default-features = false }
|
||||
impl-trait-for-tuples = "0.2"
|
||||
|
||||
# Only used in benchmarking to generate random contract code
|
||||
|
||||
@@ -613,7 +613,7 @@ fn expand_functions(def: &EnvDef, expand_blocks: bool, host_state: TokenStream2)
|
||||
let inner = if expand_blocks {
|
||||
quote! { || #output {
|
||||
let (memory, ctx) = __caller__
|
||||
.host_data()
|
||||
.data()
|
||||
.memory()
|
||||
.expect("Memory must be set when setting up host data; qed")
|
||||
.data_and_store_mut(&mut __caller__);
|
||||
@@ -630,7 +630,7 @@ fn expand_functions(def: &EnvDef, expand_blocks: bool, host_state: TokenStream2)
|
||||
let map_err = if expand_blocks {
|
||||
quote! {
|
||||
|reason| {
|
||||
::wasmi::core::Trap::host(reason)
|
||||
::wasmi::core::Trap::from(reason)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -512,7 +512,7 @@ pub fn max_pages<T: Config>() -> u32 {
|
||||
|
||||
fn inject_gas_metering<T: Config>(module: Module) -> Module {
|
||||
let schedule = T::Schedule::get();
|
||||
let gas_rules = schedule.rules(Determinism::Deterministic);
|
||||
let gas_rules = schedule.rules(Determinism::Enforced);
|
||||
let backend = gas_metering::host_function::Injector::new("seal0", "gas");
|
||||
gas_metering::inject(module, backend, &gas_rules).unwrap()
|
||||
}
|
||||
|
||||
@@ -381,7 +381,7 @@ benchmarks! {
|
||||
T::Currency::make_free_balance_be(&caller, caller_funding::<T>());
|
||||
let WasmModule { code, hash, .. } = WasmModule::<T>::sized(c, Location::Call);
|
||||
let origin = RawOrigin::Signed(caller.clone());
|
||||
}: _(origin, code, None, Determinism::Deterministic)
|
||||
}: _(origin, code, None, Determinism::Enforced)
|
||||
verify {
|
||||
// uploading the code reserves some balance in the callers account
|
||||
assert!(T::Currency::reserved_balance(&caller) > 0u32.into());
|
||||
@@ -397,7 +397,7 @@ benchmarks! {
|
||||
T::Currency::make_free_balance_be(&caller, caller_funding::<T>());
|
||||
let WasmModule { code, hash, .. } = WasmModule::<T>::dummy();
|
||||
let origin = RawOrigin::Signed(caller.clone());
|
||||
let uploaded = <Contracts<T>>::bare_upload_code(caller.clone(), code, None, Determinism::Deterministic)?;
|
||||
let uploaded = <Contracts<T>>::bare_upload_code(caller.clone(), code, None, Determinism::Enforced)?;
|
||||
assert_eq!(uploaded.code_hash, hash);
|
||||
assert_eq!(uploaded.deposit, T::Currency::reserved_balance(&caller));
|
||||
assert!(<Contract<T>>::code_exists(&hash));
|
||||
@@ -941,7 +941,7 @@ benchmarks! {
|
||||
None,
|
||||
vec![],
|
||||
true,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result?;
|
||||
}
|
||||
@@ -990,7 +990,7 @@ benchmarks! {
|
||||
None,
|
||||
vec![],
|
||||
true,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result?;
|
||||
}
|
||||
@@ -3063,7 +3063,7 @@ benchmarks! {
|
||||
None,
|
||||
data,
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result?;
|
||||
}
|
||||
@@ -3112,7 +3112,7 @@ benchmarks! {
|
||||
None,
|
||||
data,
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result?;
|
||||
}
|
||||
|
||||
@@ -665,7 +665,7 @@ where
|
||||
schedule,
|
||||
value,
|
||||
debug_message,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)?;
|
||||
let account_id = stack.top_frame().account_id.clone();
|
||||
stack.run(executable, input_data).map(|ret| (account_id, ret))
|
||||
@@ -759,10 +759,10 @@ where
|
||||
},
|
||||
};
|
||||
|
||||
// `AllowIndeterminism` will only be ever set in case of off-chain execution.
|
||||
// `Relaxed` will only be ever set in case of off-chain execution.
|
||||
// Instantiations are never allowed even when executing off-chain.
|
||||
if !(executable.is_deterministic() ||
|
||||
(matches!(determinism, Determinism::AllowIndeterminism) &&
|
||||
(matches!(determinism, Determinism::Relaxed) &&
|
||||
matches!(entry_point, ExportedFunction::Call)))
|
||||
{
|
||||
return Err(Error::<T>::Indeterministic.into())
|
||||
@@ -1607,7 +1607,7 @@ mod tests {
|
||||
value,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
),
|
||||
Ok(_)
|
||||
);
|
||||
@@ -1661,7 +1661,7 @@ mod tests {
|
||||
value,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -1703,7 +1703,7 @@ mod tests {
|
||||
value,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -1739,7 +1739,7 @@ mod tests {
|
||||
55,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -1791,7 +1791,7 @@ mod tests {
|
||||
0,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
|
||||
let output = result.unwrap();
|
||||
@@ -1824,7 +1824,7 @@ mod tests {
|
||||
0,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
|
||||
let output = result.unwrap();
|
||||
@@ -1855,7 +1855,7 @@ mod tests {
|
||||
0,
|
||||
vec![1, 2, 3, 4],
|
||||
None,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
assert_matches!(result, Ok(_));
|
||||
});
|
||||
@@ -1935,7 +1935,7 @@ mod tests {
|
||||
value,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
|
||||
assert_matches!(result, Ok(_));
|
||||
@@ -1981,7 +1981,7 @@ mod tests {
|
||||
0,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
|
||||
assert_matches!(result, Ok(_));
|
||||
@@ -2015,7 +2015,7 @@ mod tests {
|
||||
0,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
assert_matches!(result, Ok(_));
|
||||
});
|
||||
@@ -2045,7 +2045,7 @@ mod tests {
|
||||
0,
|
||||
vec![0],
|
||||
None,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
assert_matches!(result, Ok(_));
|
||||
});
|
||||
@@ -2073,7 +2073,7 @@ mod tests {
|
||||
0,
|
||||
vec![0],
|
||||
None,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
assert_matches!(result, Ok(_));
|
||||
});
|
||||
@@ -2109,7 +2109,7 @@ mod tests {
|
||||
0,
|
||||
vec![0],
|
||||
None,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
assert_matches!(result, Ok(_));
|
||||
});
|
||||
@@ -2145,7 +2145,7 @@ mod tests {
|
||||
0,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
|
||||
assert_matches!(result, Ok(_));
|
||||
@@ -2304,7 +2304,7 @@ mod tests {
|
||||
min_balance * 10,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
),
|
||||
Ok(_)
|
||||
);
|
||||
@@ -2369,7 +2369,7 @@ mod tests {
|
||||
0,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
),
|
||||
Ok(_)
|
||||
);
|
||||
@@ -2455,7 +2455,7 @@ mod tests {
|
||||
0,
|
||||
vec![0],
|
||||
None,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
assert_matches!(result, Ok(_));
|
||||
});
|
||||
@@ -2521,7 +2521,7 @@ mod tests {
|
||||
0,
|
||||
vec![],
|
||||
Some(&mut debug_buffer),
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.unwrap();
|
||||
});
|
||||
@@ -2555,7 +2555,7 @@ mod tests {
|
||||
0,
|
||||
vec![],
|
||||
Some(&mut debug_buffer),
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
assert!(result.is_err());
|
||||
});
|
||||
@@ -2592,7 +2592,7 @@ mod tests {
|
||||
0,
|
||||
vec![],
|
||||
Some(&mut debug_buf_after),
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(debug_buf_before, debug_buf_after);
|
||||
@@ -2625,7 +2625,7 @@ mod tests {
|
||||
0,
|
||||
CHARLIE.encode(),
|
||||
None,
|
||||
Determinism::Deterministic
|
||||
Determinism::Enforced
|
||||
));
|
||||
|
||||
// Calling into oneself fails
|
||||
@@ -2639,7 +2639,7 @@ mod tests {
|
||||
0,
|
||||
BOB.encode(),
|
||||
None,
|
||||
Determinism::Deterministic
|
||||
Determinism::Enforced
|
||||
)
|
||||
.map_err(|e| e.error),
|
||||
<Error<Test>>::ReentranceDenied,
|
||||
@@ -2678,7 +2678,7 @@ mod tests {
|
||||
0,
|
||||
vec![0],
|
||||
None,
|
||||
Determinism::Deterministic
|
||||
Determinism::Enforced
|
||||
)
|
||||
.map_err(|e| e.error),
|
||||
<Error<Test>>::ReentranceDenied,
|
||||
@@ -2713,7 +2713,7 @@ mod tests {
|
||||
0,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -2798,7 +2798,7 @@ mod tests {
|
||||
0,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
@@ -3007,7 +3007,7 @@ mod tests {
|
||||
0,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic
|
||||
Determinism::Enforced
|
||||
));
|
||||
});
|
||||
}
|
||||
@@ -3134,7 +3134,7 @@ mod tests {
|
||||
0,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic
|
||||
Determinism::Enforced
|
||||
));
|
||||
});
|
||||
}
|
||||
@@ -3173,7 +3173,7 @@ mod tests {
|
||||
0,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic
|
||||
Determinism::Enforced
|
||||
));
|
||||
});
|
||||
}
|
||||
@@ -3212,7 +3212,7 @@ mod tests {
|
||||
0,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic
|
||||
Determinism::Enforced
|
||||
));
|
||||
});
|
||||
}
|
||||
@@ -3268,7 +3268,7 @@ mod tests {
|
||||
0,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic
|
||||
Determinism::Enforced
|
||||
));
|
||||
});
|
||||
}
|
||||
@@ -3324,7 +3324,7 @@ mod tests {
|
||||
0,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic
|
||||
Determinism::Enforced
|
||||
));
|
||||
});
|
||||
}
|
||||
@@ -3356,7 +3356,7 @@ mod tests {
|
||||
0,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
assert_matches!(result, Ok(_));
|
||||
});
|
||||
@@ -3402,7 +3402,7 @@ mod tests {
|
||||
0,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic
|
||||
Determinism::Enforced
|
||||
));
|
||||
});
|
||||
}
|
||||
@@ -3432,7 +3432,7 @@ mod tests {
|
||||
0,
|
||||
vec![],
|
||||
None,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
assert_matches!(result, Ok(_));
|
||||
});
|
||||
|
||||
@@ -509,9 +509,9 @@ pub mod pallet {
|
||||
/// the in storage version to the current
|
||||
/// [`InstructionWeights::version`](InstructionWeights).
|
||||
///
|
||||
/// - `determinism`: If this is set to any other value but [`Determinism::Deterministic`]
|
||||
/// then the only way to use this code is to delegate call into it from an offchain
|
||||
/// execution. Set to [`Determinism::Deterministic`] if in doubt.
|
||||
/// - `determinism`: If this is set to any other value but [`Determinism::Enforced`] then
|
||||
/// the only way to use this code is to delegate call into it from an offchain execution.
|
||||
/// Set to [`Determinism::Enforced`] if in doubt.
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
@@ -625,8 +625,8 @@ pub mod pallet {
|
||||
storage_deposit_limit: storage_deposit_limit.map(Into::into),
|
||||
debug_message: None,
|
||||
};
|
||||
let mut output = CallInput::<T> { dest, determinism: Determinism::Deterministic }
|
||||
.run_guarded(common);
|
||||
let mut output =
|
||||
CallInput::<T> { dest, determinism: Determinism::Enforced }.run_guarded(common);
|
||||
if let Ok(retval) = &output.result {
|
||||
if retval.did_revert() {
|
||||
output.result = Err(<Error<T>>::ContractReverted.into());
|
||||
@@ -1096,7 +1096,7 @@ impl<T: Config> Invokable<T> for InstantiateInput<T> {
|
||||
binary.clone(),
|
||||
&schedule,
|
||||
common.origin.clone(),
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
TryInstantiate::Skip,
|
||||
)
|
||||
.map_err(|(err, msg)| {
|
||||
|
||||
@@ -394,7 +394,7 @@ mod v9 {
|
||||
initial: old.initial,
|
||||
maximum: old.maximum,
|
||||
code: old.code,
|
||||
determinism: Determinism::Deterministic,
|
||||
determinism: Determinism::Enforced,
|
||||
})
|
||||
});
|
||||
}
|
||||
@@ -464,7 +464,7 @@ mod post_checks {
|
||||
fn v9<T: Config>() -> Result<(), &'static str> {
|
||||
for value in CodeStorage::<T>::iter_values() {
|
||||
ensure!(
|
||||
value.determinism == Determinism::Deterministic,
|
||||
value.determinism == Determinism::Enforced,
|
||||
"All pre-existing codes need to be deterministic."
|
||||
);
|
||||
}
|
||||
|
||||
@@ -175,9 +175,9 @@ pub struct InstructionWeights<T: Config> {
|
||||
pub version: u32,
|
||||
/// Weight to be used for instructions which don't have benchmarks assigned.
|
||||
///
|
||||
/// This weight is used whenever a code is uploaded with [`Determinism::AllowIndeterminism`]
|
||||
/// This weight is used whenever a code is uploaded with [`Determinism::Relaxed`]
|
||||
/// and an instruction (usually a float instruction) is encountered. This weight is **not**
|
||||
/// used if a contract is uploaded with [`Determinism::Deterministic`]. If this field is set to
|
||||
/// used if a contract is uploaded with [`Determinism::Enforced`]. If this field is set to
|
||||
/// `0` (the default) only deterministic codes are allowed to be uploaded.
|
||||
pub fallback: u32,
|
||||
pub i64const: u32,
|
||||
@@ -715,8 +715,7 @@ impl<'a, T: Config> gas_metering::Rules for ScheduleRules<'a, T> {
|
||||
// Returning None makes the gas instrumentation fail which we intend for
|
||||
// unsupported or unknown instructions. Offchain we might allow indeterminism and hence
|
||||
// use the fallback weight for those instructions.
|
||||
_ if matches!(self.determinism, Determinism::AllowIndeterminism) && w.fallback > 0 =>
|
||||
w.fallback,
|
||||
_ if matches!(self.determinism, Determinism::Relaxed) && w.fallback > 0 => w.fallback,
|
||||
_ => return None,
|
||||
};
|
||||
Some(weight)
|
||||
|
||||
@@ -529,7 +529,7 @@ fn instantiate_and_call_and_deposit_event() {
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
wasm,
|
||||
None,
|
||||
Determinism::Deterministic
|
||||
Determinism::Enforced
|
||||
));
|
||||
|
||||
// Drop previous events
|
||||
@@ -726,13 +726,8 @@ fn instantiate_unique_trie_id() {
|
||||
|
||||
ExtBuilder::default().existential_deposit(500).build().execute_with(|| {
|
||||
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
|
||||
Contracts::upload_code(
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
wasm,
|
||||
None,
|
||||
Determinism::Deterministic,
|
||||
)
|
||||
.unwrap();
|
||||
Contracts::upload_code(RuntimeOrigin::signed(ALICE), wasm, None, Determinism::Enforced)
|
||||
.unwrap();
|
||||
|
||||
// Instantiate the contract and store its trie id for later comparison.
|
||||
let addr = Contracts::bare_instantiate(
|
||||
@@ -860,7 +855,7 @@ fn deploy_and_call_other_contract() {
|
||||
.result
|
||||
.unwrap()
|
||||
.account_id;
|
||||
Contracts::bare_upload_code(ALICE, callee_wasm, None, Determinism::Deterministic).unwrap();
|
||||
Contracts::bare_upload_code(ALICE, callee_wasm, None, Determinism::Enforced).unwrap();
|
||||
|
||||
let callee_addr = Contracts::contract_address(
|
||||
&caller_addr,
|
||||
@@ -1011,7 +1006,7 @@ fn delegate_call() {
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
callee_wasm,
|
||||
Some(codec::Compact(100_000)),
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
));
|
||||
|
||||
assert_ok!(Contracts::call(
|
||||
@@ -1321,7 +1316,7 @@ fn destroy_contract_and_transfer_funds() {
|
||||
ExtBuilder::default().existential_deposit(50).build().execute_with(|| {
|
||||
// Create code hash for bob to instantiate
|
||||
let _ = Balances::deposit_creating(&ALICE, 1_000_000);
|
||||
Contracts::bare_upload_code(ALICE, callee_wasm, None, Determinism::Deterministic).unwrap();
|
||||
Contracts::bare_upload_code(ALICE, callee_wasm, None, Determinism::Enforced).unwrap();
|
||||
|
||||
// This deploys the BOB contract, which in turn deploys the CHARLIE contract during
|
||||
// construction.
|
||||
@@ -1431,7 +1426,7 @@ fn crypto_hashes() {
|
||||
None,
|
||||
params,
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
@@ -1473,7 +1468,7 @@ fn transfer_return_code() {
|
||||
None,
|
||||
vec![],
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
@@ -1514,7 +1509,7 @@ fn call_return_code() {
|
||||
None,
|
||||
AsRef::<[u8]>::as_ref(&DJANGO).to_vec(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
@@ -1548,7 +1543,7 @@ fn call_return_code() {
|
||||
.cloned()
|
||||
.collect(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
@@ -1568,7 +1563,7 @@ fn call_return_code() {
|
||||
.cloned()
|
||||
.collect(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
@@ -1587,7 +1582,7 @@ fn call_return_code() {
|
||||
.cloned()
|
||||
.collect(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
@@ -1639,7 +1634,7 @@ fn instantiate_return_code() {
|
||||
None,
|
||||
callee_hash.clone(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
@@ -1655,7 +1650,7 @@ fn instantiate_return_code() {
|
||||
None,
|
||||
vec![0; 33],
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
@@ -1670,7 +1665,7 @@ fn instantiate_return_code() {
|
||||
None,
|
||||
callee_hash.iter().chain(&1u32.to_le_bytes()).cloned().collect(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
@@ -1685,7 +1680,7 @@ fn instantiate_return_code() {
|
||||
None,
|
||||
callee_hash.iter().chain(&2u32.to_le_bytes()).cloned().collect(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
@@ -1772,7 +1767,7 @@ fn chain_extension_works() {
|
||||
None,
|
||||
input.clone(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
assert_eq!(TestExtension::last_seen_buffer(), input);
|
||||
assert_eq!(result.result.unwrap().data, input);
|
||||
@@ -1786,7 +1781,7 @@ fn chain_extension_works() {
|
||||
None,
|
||||
ExtensionInput { extension_id: 0, func_id: 1, extra: &[] }.into(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
@@ -1802,7 +1797,7 @@ fn chain_extension_works() {
|
||||
None,
|
||||
ExtensionInput { extension_id: 0, func_id: 2, extra: &[0] }.into(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
assert_ok!(result.result);
|
||||
let gas_consumed = result.gas_consumed;
|
||||
@@ -1814,7 +1809,7 @@ fn chain_extension_works() {
|
||||
None,
|
||||
ExtensionInput { extension_id: 0, func_id: 2, extra: &[42] }.into(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
assert_ok!(result.result);
|
||||
assert_eq!(result.gas_consumed.ref_time(), gas_consumed.ref_time() + 42);
|
||||
@@ -1826,7 +1821,7 @@ fn chain_extension_works() {
|
||||
None,
|
||||
ExtensionInput { extension_id: 0, func_id: 2, extra: &[95] }.into(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
assert_ok!(result.result);
|
||||
assert_eq!(result.gas_consumed.ref_time(), gas_consumed.ref_time() + 95);
|
||||
@@ -1840,7 +1835,7 @@ fn chain_extension_works() {
|
||||
None,
|
||||
ExtensionInput { extension_id: 0, func_id: 3, extra: &[] }.into(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
@@ -1858,7 +1853,7 @@ fn chain_extension_works() {
|
||||
None,
|
||||
ExtensionInput { extension_id: 1, func_id: 0, extra: &[] }.into(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
@@ -1919,7 +1914,7 @@ fn chain_extension_temp_storage_works() {
|
||||
None,
|
||||
input.clone(),
|
||||
false,
|
||||
Determinism::Deterministic
|
||||
Determinism::Enforced
|
||||
)
|
||||
.result
|
||||
);
|
||||
@@ -2480,7 +2475,7 @@ fn reinstrument_does_charge() {
|
||||
None,
|
||||
zero.clone(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
assert!(!result0.result.unwrap().did_revert());
|
||||
|
||||
@@ -2492,7 +2487,7 @@ fn reinstrument_does_charge() {
|
||||
None,
|
||||
zero.clone(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
assert!(!result1.result.unwrap().did_revert());
|
||||
|
||||
@@ -2514,7 +2509,7 @@ fn reinstrument_does_charge() {
|
||||
None,
|
||||
zero.clone(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
assert!(!result2.result.unwrap().did_revert());
|
||||
assert!(result2.gas_consumed.ref_time() > result1.gas_consumed.ref_time());
|
||||
@@ -2553,7 +2548,7 @@ fn debug_message_works() {
|
||||
None,
|
||||
vec![],
|
||||
true,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
|
||||
assert_matches!(result.result, Ok(_));
|
||||
@@ -2589,7 +2584,7 @@ fn debug_message_logging_disabled() {
|
||||
None,
|
||||
vec![],
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
assert_matches!(result.result, Ok(_));
|
||||
// the dispatchables always run without debugging
|
||||
@@ -2625,7 +2620,7 @@ fn debug_message_invalid_utf8() {
|
||||
None,
|
||||
vec![],
|
||||
true,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
assert_ok!(result.result);
|
||||
assert!(result.debug_message.is_empty());
|
||||
@@ -2684,7 +2679,7 @@ fn gas_estimation_nested_call_fixed_limit() {
|
||||
None,
|
||||
input.clone(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
assert_ok!(&result.result);
|
||||
|
||||
@@ -2701,7 +2696,7 @@ fn gas_estimation_nested_call_fixed_limit() {
|
||||
Some(result.storage_deposit.charge_or_zero()),
|
||||
input,
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
);
|
||||
@@ -2760,7 +2755,7 @@ fn gas_estimation_call_runtime() {
|
||||
None,
|
||||
call.encode(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
);
|
||||
// contract encodes the result of the dispatch runtime
|
||||
let outcome = u32::decode(&mut result.result.unwrap().data.as_ref()).unwrap();
|
||||
@@ -2777,7 +2772,7 @@ fn gas_estimation_call_runtime() {
|
||||
None,
|
||||
call.encode(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
);
|
||||
@@ -2840,7 +2835,7 @@ fn gas_call_runtime_reentrancy_guarded() {
|
||||
None,
|
||||
call.encode(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
@@ -2902,7 +2897,7 @@ fn ecdsa_recover() {
|
||||
None,
|
||||
params,
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
@@ -2926,7 +2921,7 @@ fn upload_code_works() {
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
wasm,
|
||||
Some(codec::Compact(1_000)),
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
));
|
||||
assert!(<CodeStorage<Test>>::contains_key(code_hash));
|
||||
|
||||
@@ -2966,7 +2961,7 @@ fn upload_code_limit_too_low() {
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
wasm,
|
||||
Some(codec::Compact(100)),
|
||||
Determinism::Deterministic
|
||||
Determinism::Enforced
|
||||
),
|
||||
<Error<Test>>::StorageDepositLimitExhausted,
|
||||
);
|
||||
@@ -2990,7 +2985,7 @@ fn upload_code_not_enough_balance() {
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
wasm,
|
||||
Some(codec::Compact(1_000)),
|
||||
Determinism::Deterministic
|
||||
Determinism::Enforced
|
||||
),
|
||||
<Error<Test>>::StorageDepositNotEnoughFunds,
|
||||
);
|
||||
@@ -3013,7 +3008,7 @@ fn remove_code_works() {
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
wasm,
|
||||
Some(codec::Compact(1_000)),
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
));
|
||||
|
||||
assert!(<CodeStorage<Test>>::contains_key(code_hash));
|
||||
@@ -3068,7 +3063,7 @@ fn remove_code_wrong_origin() {
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
wasm,
|
||||
Some(codec::Compact(1_000)),
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
));
|
||||
|
||||
assert_noop!(
|
||||
@@ -3538,7 +3533,7 @@ fn set_code_extrinsic() {
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
new_wasm,
|
||||
None,
|
||||
Determinism::Deterministic
|
||||
Determinism::Enforced
|
||||
));
|
||||
|
||||
// Drop previous events
|
||||
@@ -3658,7 +3653,7 @@ fn contract_reverted() {
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
wasm.clone(),
|
||||
None,
|
||||
Determinism::Deterministic
|
||||
Determinism::Enforced
|
||||
));
|
||||
|
||||
// Calling extrinsic: revert leads to an error
|
||||
@@ -3746,7 +3741,7 @@ fn contract_reverted() {
|
||||
None,
|
||||
input,
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
@@ -3766,7 +3761,7 @@ fn code_rejected_error_works() {
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
wasm.clone(),
|
||||
None,
|
||||
Determinism::Deterministic
|
||||
Determinism::Enforced
|
||||
),
|
||||
<Error<Test>>::CodeRejected,
|
||||
);
|
||||
@@ -3792,7 +3787,7 @@ fn code_rejected_error_works() {
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
wasm.clone(),
|
||||
None,
|
||||
Determinism::Deterministic
|
||||
Determinism::Enforced
|
||||
),
|
||||
<Error<Test>>::CodeRejected,
|
||||
);
|
||||
@@ -3842,7 +3837,7 @@ fn set_code_hash() {
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
new_wasm.clone(),
|
||||
None,
|
||||
Determinism::Deterministic
|
||||
Determinism::Enforced
|
||||
));
|
||||
|
||||
System::reset_events();
|
||||
@@ -3856,7 +3851,7 @@ fn set_code_hash() {
|
||||
None,
|
||||
new_code_hash.as_ref().to_vec(),
|
||||
true,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
@@ -3871,7 +3866,7 @@ fn set_code_hash() {
|
||||
None,
|
||||
vec![],
|
||||
true,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
@@ -4268,7 +4263,7 @@ fn cannot_instantiate_indeterministic_code() {
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
wasm.clone(),
|
||||
None,
|
||||
Determinism::Deterministic
|
||||
Determinism::Enforced
|
||||
),
|
||||
<Error<Test>>::CodeRejected,
|
||||
);
|
||||
@@ -4278,7 +4273,7 @@ fn cannot_instantiate_indeterministic_code() {
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
wasm,
|
||||
None,
|
||||
Determinism::AllowIndeterminism,
|
||||
Determinism::Relaxed,
|
||||
));
|
||||
assert_err_ignore_postinfo!(
|
||||
Contracts::instantiate(
|
||||
@@ -4332,7 +4327,7 @@ fn cannot_instantiate_indeterministic_code() {
|
||||
None,
|
||||
code_hash.encode(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result,
|
||||
<Error<Test>>::Indeterministic,
|
||||
@@ -4348,7 +4343,7 @@ fn cannot_instantiate_indeterministic_code() {
|
||||
None,
|
||||
code_hash.encode(),
|
||||
false,
|
||||
Determinism::AllowIndeterminism,
|
||||
Determinism::Relaxed,
|
||||
)
|
||||
.result,
|
||||
<Error<Test>>::Indeterministic,
|
||||
@@ -4368,7 +4363,7 @@ fn cannot_set_code_indeterministic_code() {
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
wasm,
|
||||
None,
|
||||
Determinism::AllowIndeterminism,
|
||||
Determinism::Relaxed,
|
||||
));
|
||||
|
||||
// Create the contract that will call `seal_set_code_hash`
|
||||
@@ -4396,7 +4391,7 @@ fn cannot_set_code_indeterministic_code() {
|
||||
None,
|
||||
code_hash.encode(),
|
||||
false,
|
||||
Determinism::AllowIndeterminism,
|
||||
Determinism::Relaxed,
|
||||
)
|
||||
.result,
|
||||
<Error<Test>>::Indeterministic,
|
||||
@@ -4416,7 +4411,7 @@ fn delegate_call_indeterministic_code() {
|
||||
RuntimeOrigin::signed(ALICE),
|
||||
wasm,
|
||||
None,
|
||||
Determinism::AllowIndeterminism,
|
||||
Determinism::Relaxed,
|
||||
));
|
||||
|
||||
// Create the contract that will call `seal_delegate_call`
|
||||
@@ -4444,7 +4439,7 @@ fn delegate_call_indeterministic_code() {
|
||||
None,
|
||||
code_hash.encode(),
|
||||
false,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result,
|
||||
<Error<Test>>::Indeterministic,
|
||||
@@ -4460,7 +4455,7 @@ fn delegate_call_indeterministic_code() {
|
||||
None,
|
||||
code_hash.encode(),
|
||||
false,
|
||||
Determinism::AllowIndeterminism,
|
||||
Determinism::Relaxed,
|
||||
)
|
||||
.result
|
||||
);
|
||||
@@ -4499,7 +4494,7 @@ fn reentrance_count_works_with_call() {
|
||||
None,
|
||||
input,
|
||||
true,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
@@ -4538,7 +4533,7 @@ fn reentrance_count_works_with_delegated_call() {
|
||||
None,
|
||||
input,
|
||||
true,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
@@ -4590,7 +4585,7 @@ fn account_reentrance_count_works() {
|
||||
None,
|
||||
contract_addr.encode(),
|
||||
true,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
@@ -4603,7 +4598,7 @@ fn account_reentrance_count_works() {
|
||||
None,
|
||||
another_contract_addr.encode(),
|
||||
true,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
)
|
||||
.result
|
||||
.unwrap();
|
||||
|
||||
@@ -127,7 +127,7 @@ pub enum Determinism {
|
||||
/// allowed.
|
||||
///
|
||||
/// Dispatchables always use this mode in order to make on-chain execution deterministic.
|
||||
Deterministic,
|
||||
Enforced,
|
||||
/// Allow calling or uploading an indeterministic code.
|
||||
///
|
||||
/// This is only possible when calling into `pallet-contracts` directly via
|
||||
@@ -136,7 +136,7 @@ pub enum Determinism {
|
||||
/// # Note
|
||||
///
|
||||
/// **Never** use this mode for on-chain execution.
|
||||
AllowIndeterminism,
|
||||
Relaxed,
|
||||
}
|
||||
|
||||
impl ExportedFunction {
|
||||
@@ -225,7 +225,7 @@ impl<T: Config> PrefabWasmModule<T> {
|
||||
let engine = Engine::new(&config);
|
||||
let module = Module::new(&engine, code)?;
|
||||
let mut store = Store::new(&engine, host_state);
|
||||
let mut linker = Linker::new();
|
||||
let mut linker = Linker::new(&engine);
|
||||
E::define(
|
||||
&mut store,
|
||||
&mut linker,
|
||||
@@ -329,7 +329,7 @@ impl<T: Config> Executable<T> for PrefabWasmModule<T> {
|
||||
log::debug!(target: "runtime::contracts", "failed to instantiate code: {}", msg);
|
||||
Error::<T>::CodeRejected
|
||||
})?;
|
||||
store.state_mut().set_memory(memory);
|
||||
store.data_mut().set_memory(memory);
|
||||
|
||||
let exported_func = instance
|
||||
.get_export(&store, function.identifier())
|
||||
@@ -346,7 +346,7 @@ impl<T: Config> Executable<T> for PrefabWasmModule<T> {
|
||||
|
||||
let result = exported_func.call(&mut store, &[], &mut []);
|
||||
|
||||
store.into_state().to_execution_result(result)
|
||||
store.into_data().to_execution_result(result)
|
||||
}
|
||||
|
||||
fn code_hash(&self) -> &CodeHash<T> {
|
||||
@@ -358,7 +358,7 @@ impl<T: Config> Executable<T> for PrefabWasmModule<T> {
|
||||
}
|
||||
|
||||
fn is_deterministic(&self) -> bool {
|
||||
matches!(self.determinism, Determinism::Deterministic)
|
||||
matches!(self.determinism, Determinism::Enforced)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -653,7 +653,7 @@ mod tests {
|
||||
wasm,
|
||||
&schedule,
|
||||
ALICE,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
TryInstantiate::Instantiate,
|
||||
)
|
||||
.map_err(|err| err.0)?
|
||||
@@ -3058,12 +3058,8 @@ mod tests {
|
||||
let schedule = crate::Schedule::<Test>::default();
|
||||
#[cfg(not(feature = "runtime-benchmarks"))]
|
||||
assert_err!(execute(CODE_RANDOM, vec![], MockExt::default()), <Error<Test>>::CodeRejected);
|
||||
self::prepare::reinstrument::<runtime::Env, Test>(
|
||||
&wasm,
|
||||
&schedule,
|
||||
Determinism::Deterministic,
|
||||
)
|
||||
.unwrap();
|
||||
self::prepare::reinstrument::<runtime::Env, Test>(&wasm, &schedule, Determinism::Enforced)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
/// This test check that an unstable interface cannot be deployed. In case of runtime
|
||||
|
||||
@@ -155,52 +155,6 @@ impl<'a, T: Config> ContractModule<'a, T> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Ensures that no floating point types are in use.
|
||||
fn ensure_no_floating_types(&self) -> Result<(), &'static str> {
|
||||
if let Some(global_section) = self.module.global_section() {
|
||||
for global in global_section.entries() {
|
||||
match global.global_type().content_type() {
|
||||
ValueType::F32 | ValueType::F64 =>
|
||||
return Err("use of floating point type in globals is forbidden"),
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(code_section) = self.module.code_section() {
|
||||
for func_body in code_section.bodies() {
|
||||
for local in func_body.locals() {
|
||||
match local.value_type() {
|
||||
ValueType::F32 | ValueType::F64 =>
|
||||
return Err("use of floating point type in locals is forbidden"),
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(type_section) = self.module.type_section() {
|
||||
for wasm_type in type_section.types() {
|
||||
match wasm_type {
|
||||
Type::Function(func_type) => {
|
||||
let return_type = func_type.results().get(0);
|
||||
for value_type in func_type.params().iter().chain(return_type) {
|
||||
match value_type {
|
||||
ValueType::F32 | ValueType::F64 =>
|
||||
return Err(
|
||||
"use of floating point type in function types is forbidden",
|
||||
),
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Ensure that no function exists that has more parameters than allowed.
|
||||
fn ensure_parameter_limit(&self, limit: u32) -> Result<(), &'static str> {
|
||||
let type_section = if let Some(type_section) = self.module.type_section() {
|
||||
@@ -411,10 +365,9 @@ where
|
||||
memory64: false,
|
||||
extended_const: false,
|
||||
component_model: false,
|
||||
// This is not our only defense: We check for float types later in the preparation
|
||||
// process. Additionally, all instructions explicitly need to have weights assigned
|
||||
// This is not our only defense: All instructions explicitly need to have weights assigned
|
||||
// or the deployment will fail. We have none assigned for float instructions.
|
||||
deterministic_only: matches!(determinism, Determinism::Deterministic),
|
||||
floats: matches!(determinism, Determinism::Relaxed),
|
||||
mutable_global: false,
|
||||
saturating_float_to_int: false,
|
||||
sign_extension: false,
|
||||
@@ -422,6 +375,7 @@ where
|
||||
multi_value: false,
|
||||
reference_types: false,
|
||||
simd: false,
|
||||
memory_control: false,
|
||||
})
|
||||
.validate_all(original_code)
|
||||
.map_err(|err| {
|
||||
@@ -439,10 +393,6 @@ where
|
||||
contract_module.ensure_parameter_limit(schedule.limits.parameters)?;
|
||||
contract_module.ensure_br_table_size_limit(schedule.limits.br_table_size)?;
|
||||
|
||||
if matches!(determinism, Determinism::Deterministic) {
|
||||
contract_module.ensure_no_floating_types()?;
|
||||
}
|
||||
|
||||
// We disallow importing `gas` function here since it is treated as implementation detail.
|
||||
let disallowed_imports = [b"gas".as_ref()];
|
||||
let memory_limits =
|
||||
@@ -608,7 +558,7 @@ pub mod benchmarking {
|
||||
deposit: Default::default(),
|
||||
refcount: 0,
|
||||
}),
|
||||
determinism: Determinism::Deterministic,
|
||||
determinism: Determinism::Enforced,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -682,7 +632,7 @@ mod tests {
|
||||
wasm,
|
||||
&schedule,
|
||||
ALICE,
|
||||
Determinism::Deterministic,
|
||||
Determinism::Enforced,
|
||||
TryInstantiate::Instantiate,
|
||||
);
|
||||
assert_matches::assert_matches!(r.map_err(|(_, msg)| msg), $($expected)*);
|
||||
@@ -704,7 +654,7 @@ mod tests {
|
||||
)
|
||||
(func (export "deploy"))
|
||||
)"#,
|
||||
Err("gas instrumentation failed")
|
||||
Err("validation of new code failed")
|
||||
);
|
||||
|
||||
mod functions {
|
||||
@@ -1214,7 +1164,7 @@ mod tests {
|
||||
(func (export "deploy"))
|
||||
)
|
||||
"#,
|
||||
Err("use of floating point type in globals is forbidden")
|
||||
Err("validation of new code failed")
|
||||
);
|
||||
|
||||
prepare_test!(
|
||||
@@ -1226,7 +1176,7 @@ mod tests {
|
||||
(func (export "deploy"))
|
||||
)
|
||||
"#,
|
||||
Err("use of floating point type in locals is forbidden")
|
||||
Err("validation of new code failed")
|
||||
);
|
||||
|
||||
prepare_test!(
|
||||
@@ -1238,7 +1188,7 @@ mod tests {
|
||||
(func (export "deploy"))
|
||||
)
|
||||
"#,
|
||||
Err("use of floating point type in function types is forbidden")
|
||||
Err("validation of new code failed")
|
||||
);
|
||||
|
||||
prepare_test!(
|
||||
@@ -1250,7 +1200,7 @@ mod tests {
|
||||
(func (export "deploy"))
|
||||
)
|
||||
"#,
|
||||
Err("use of floating point type in function types is forbidden")
|
||||
Err("validation of new code failed")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -482,11 +482,7 @@ impl<'a, E: Ext + 'a> Runtime<'a, E> {
|
||||
Err(wasmi::Error::Trap(trap)) => {
|
||||
// If we encoded a reason then it is some abort generated by a host function.
|
||||
// Otherwise the trap came from the contract.
|
||||
let reason: TrapReason = *trap
|
||||
.into_host()
|
||||
.ok_or(Error::<E::T>::ContractTrapped)?
|
||||
.downcast()
|
||||
.expect("`TrapReason` is the only type we use to encode host errors; qed");
|
||||
let reason: TrapReason = trap.downcast().ok_or(Error::<E::T>::ContractTrapped)?;
|
||||
match reason {
|
||||
Return(ReturnData { flags, data }) => {
|
||||
let flags =
|
||||
|
||||
Generated
+1185
-1177
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user