Contracts verify benchmark block (#4130)

Add verify statement to ensure that benchmarks call do not revert

Also updated
[benchmarks](https://weights.tasty.limo/compare?unit=time&ignore_errors=true&threshold=10&method=asymptotic&repo=polkadot-sdk&old=master&new=pg/verify-benchmarks&path_pattern=substrate%2Fframe%2Fcontracts%2Fsrc%2Fweights.rs)

---------

Co-authored-by: command-bot <>
This commit is contained in:
PG Herveou
2024-04-17 01:38:35 +02:00
committed by GitHub
parent 6f3d890ed3
commit e81322bc3e
2 changed files with 845 additions and 675 deletions
+222 -56
View File
@@ -623,10 +623,13 @@ mod benchmarks {
#[benchmark(pov_mode = Measured)]
fn seal_caller(r: Linear<0, API_BENCHMARK_RUNS>) {
call_builder!(func, WasmModule::getter("seal0", "seal_caller", r));
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
#[benchmark(pov_mode = Measured)]
@@ -659,10 +662,13 @@ mod benchmarks {
for acc in accounts.iter() {
<ContractInfoOf<T>>::insert(acc, info.clone());
}
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
#[benchmark(pov_mode = Measured)]
@@ -703,19 +709,25 @@ mod benchmarks {
for acc in accounts.iter() {
<ContractInfoOf<T>>::insert(acc, info.clone());
}
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
#[benchmark(pov_mode = Measured)]
fn seal_own_code_hash(r: Linear<0, API_BENCHMARK_RUNS>) {
call_builder!(func, WasmModule::getter("seal0", "seal_own_code_hash", r));
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
#[benchmark(pov_mode = Measured)]
@@ -732,10 +744,13 @@ mod benchmarks {
..Default::default()
});
call_builder!(func, code);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
#[benchmark(pov_mode = Measured)]
@@ -754,73 +769,97 @@ mod benchmarks {
let mut setup = CallSetup::<T>::new(code);
setup.set_origin(Origin::Root);
call_builder!(func, setup: setup);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
#[benchmark(pov_mode = Measured)]
fn seal_address(r: Linear<0, API_BENCHMARK_RUNS>) {
call_builder!(func, WasmModule::getter("seal0", "seal_address", r));
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
#[benchmark(pov_mode = Measured)]
fn seal_gas_left(r: Linear<0, API_BENCHMARK_RUNS>) {
call_builder!(func, WasmModule::getter("seal1", "gas_left", r));
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
#[benchmark(pov_mode = Measured)]
fn seal_balance(r: Linear<0, API_BENCHMARK_RUNS>) {
call_builder!(func, WasmModule::getter("seal0", "seal_balance", r));
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
#[benchmark(pov_mode = Measured)]
fn seal_value_transferred(r: Linear<0, API_BENCHMARK_RUNS>) {
call_builder!(func, WasmModule::getter("seal0", "seal_value_transferred", r));
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
#[benchmark(pov_mode = Measured)]
fn seal_minimum_balance(r: Linear<0, API_BENCHMARK_RUNS>) {
call_builder!(func, WasmModule::getter("seal0", "seal_minimum_balance", r));
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
#[benchmark(pov_mode = Measured)]
fn seal_block_number(r: Linear<0, API_BENCHMARK_RUNS>) {
call_builder!(func, WasmModule::getter("seal0", "seal_block_number", r));
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
#[benchmark(pov_mode = Measured)]
fn seal_now(r: Linear<0, API_BENCHMARK_RUNS>) {
call_builder!(func, WasmModule::getter("seal0", "seal_now", r));
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
#[benchmark(pov_mode = Measured)]
@@ -851,10 +890,13 @@ mod benchmarks {
..Default::default()
});
call_builder!(func, code);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
#[benchmark(pov_mode = Measured)]
@@ -880,10 +922,13 @@ mod benchmarks {
});
call_builder!(func, code);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
#[benchmark(pov_mode = Measured)]
@@ -944,10 +989,13 @@ mod benchmarks {
..Default::default()
});
call_builder!(func, code);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
#[benchmark(pov_mode = Measured)]
@@ -970,10 +1018,13 @@ mod benchmarks {
..Default::default()
});
call_builder!(func, code);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
// The same argument as for `seal_return` is true here.
@@ -1108,10 +1159,13 @@ mod benchmarks {
});
call_builder!(func, code);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
// Overhead of calling the function without any topic.
@@ -1140,10 +1194,13 @@ mod benchmarks {
});
call_builder!(func, code);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
// Benchmark the overhead that topics generate.
@@ -1177,10 +1234,13 @@ mod benchmarks {
});
call_builder!(func, code);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
// Benchmark debug_message call with zero input data.
@@ -1210,10 +1270,13 @@ mod benchmarks {
let mut setup = CallSetup::<T>::new(code);
setup.enable_debug_message();
call_builder!(func, setup: setup);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -1260,10 +1323,13 @@ mod benchmarks {
let mut setup = CallSetup::<T>::new(code);
setup.enable_debug_message();
call_builder!(func, setup: setup);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
assert_eq!(setup.debug_message().unwrap().len() as u32, i);
Ok(())
}
@@ -1324,10 +1390,13 @@ mod benchmarks {
)
.map_err(|_| "Failed to write to storage during setup.")?;
}
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -1366,10 +1435,13 @@ mod benchmarks {
false,
)
.map_err(|_| "Failed to write to storage during setup.")?;
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -1409,10 +1481,13 @@ mod benchmarks {
false,
)
.map_err(|_| "Failed to write to storage during setup.")?;
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -1463,10 +1538,13 @@ mod benchmarks {
.map_err(|_| "Failed to write to storage during setup.")?;
}
<ContractInfoOf<T>>::insert(&instance.account_id, info);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -1504,10 +1582,12 @@ mod benchmarks {
)
.map_err(|_| "Failed to write to storage during setup.")?;
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -1564,10 +1644,13 @@ mod benchmarks {
.map_err(|_| "Failed to write to storage during setup.")?;
}
<ContractInfoOf<T>>::insert(&instance.account_id, info);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -1613,10 +1696,13 @@ mod benchmarks {
)
.map_err(|_| "Failed to write to storage during setup.")?;
<ContractInfoOf<T>>::insert(&instance.account_id, info);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -1667,10 +1753,13 @@ mod benchmarks {
.map_err(|_| "Failed to write to storage during setup.")?;
}
<ContractInfoOf<T>>::insert(&instance.account_id, info);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -1708,10 +1797,13 @@ mod benchmarks {
)
.map_err(|_| "Failed to write to storage during setup.")?;
<ContractInfoOf<T>>::insert(&instance.account_id, info);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -1767,10 +1859,13 @@ mod benchmarks {
.map_err(|_| "Failed to write to storage during setup.")?;
}
<ContractInfoOf<T>>::insert(&instance.account_id, info);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -1816,10 +1911,13 @@ mod benchmarks {
)
.map_err(|_| "Failed to write to storage during setup.")?;
<ContractInfoOf<T>>::insert(&instance.account_id, info);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -1867,10 +1965,12 @@ mod benchmarks {
assert_eq!(T::Currency::total_balance(account), 0u32.into());
}
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
for account in &accounts {
assert_eq!(T::Currency::total_balance(account), value);
@@ -1947,10 +2047,13 @@ mod benchmarks {
let mut setup = CallSetup::<T>::new(code);
setup.set_storage_deposit_limit(BalanceOf::<T>::from(u32::MAX.into()));
call_builder!(func, setup: setup);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -2002,10 +2105,13 @@ mod benchmarks {
..Default::default()
});
call_builder!(func, code);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -2057,10 +2163,13 @@ mod benchmarks {
let mut setup = CallSetup::<T>::new(code);
setup.set_data(vec![42; c as usize]);
call_builder!(func, setup: setup);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -2165,10 +2274,13 @@ mod benchmarks {
return Err("Expected that contract does not exist at this point.".into());
}
}
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
for addr in &addresses {
ContractInfoOf::<T>::get(&addr).ok_or("Contract should have been instantiated")?;
}
@@ -2240,10 +2352,13 @@ mod benchmarks {
let mut setup = CallSetup::<T>::new(code);
setup.set_balance(value + (Pallet::<T>::min_balance() * 2u32.into()));
call_builder!(func, setup: setup);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -2251,80 +2366,104 @@ mod benchmarks {
#[benchmark(pov_mode = Measured)]
fn seal_hash_sha2_256(r: Linear<0, API_BENCHMARK_RUNS>) {
call_builder!(func, WasmModule::hasher("seal_hash_sha2_256", r, 0));
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
// `n`: Input to hash in bytes
#[benchmark(pov_mode = Measured)]
fn seal_hash_sha2_256_per_byte(n: Linear<0, { code::max_pages::<T>() * 64 * 1024 }>) {
call_builder!(func, WasmModule::hasher("seal_hash_sha2_256", 1, n));
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
// Only the overhead of calling the function itself with minimal arguments.
#[benchmark(pov_mode = Measured)]
fn seal_hash_keccak_256(r: Linear<0, API_BENCHMARK_RUNS>) {
call_builder!(func, WasmModule::hasher("seal_hash_keccak_256", r, 0));
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
// `n`: Input to hash in bytes
#[benchmark(pov_mode = Measured)]
fn seal_hash_keccak_256_per_byte(n: Linear<0, { code::max_pages::<T>() * 64 * 1024 }>) {
call_builder!(func, WasmModule::hasher("seal_hash_keccak_256", 1, n));
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
// Only the overhead of calling the function itself with minimal arguments.
#[benchmark(pov_mode = Measured)]
fn seal_hash_blake2_256(r: Linear<0, API_BENCHMARK_RUNS>) {
call_builder!(func, WasmModule::hasher("seal_hash_blake2_256", r, 0));
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
// `n`: Input to hash in bytes
#[benchmark(pov_mode = Measured)]
fn seal_hash_blake2_256_per_byte(n: Linear<0, { code::max_pages::<T>() * 64 * 1024 }>) {
call_builder!(func, WasmModule::hasher("seal_hash_blake2_256", 1, n));
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
// Only the overhead of calling the function itself with minimal arguments.
#[benchmark(pov_mode = Measured)]
fn seal_hash_blake2_128(r: Linear<0, API_BENCHMARK_RUNS>) {
call_builder!(func, WasmModule::hasher("seal_hash_blake2_128", r, 0));
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
// `n`: Input to hash in bytes
#[benchmark(pov_mode = Measured)]
fn seal_hash_blake2_128_per_byte(n: Linear<0, { code::max_pages::<T>() * 64 * 1024 }>) {
call_builder!(func, WasmModule::hasher("seal_hash_blake2_128", 1, n));
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
// `n`: Message input length to verify in bytes.
@@ -2368,10 +2507,13 @@ mod benchmarks {
});
call_builder!(func, code);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -2425,10 +2567,13 @@ mod benchmarks {
..Default::default()
});
call_builder!(func, code);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -2475,10 +2620,13 @@ mod benchmarks {
..Default::default()
});
call_builder!(func, code);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -2515,10 +2663,13 @@ mod benchmarks {
..Default::default()
});
call_builder!(func, code);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -2556,10 +2707,13 @@ mod benchmarks {
..Default::default()
});
call_builder!(func, code);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -2598,10 +2752,13 @@ mod benchmarks {
..Default::default()
});
call_builder!(func, code);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -2656,10 +2813,13 @@ mod benchmarks {
..Default::default()
});
call_builder!(func, code);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -2713,10 +2873,13 @@ mod benchmarks {
..Default::default()
});
call_builder!(func, code);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
Ok(())
}
@@ -2734,10 +2897,13 @@ mod benchmarks {
..Default::default()
});
call_builder!(func, code);
let res;
#[block]
{
func.call();
res = func.call();
}
assert_eq!(res.did_revert(), false);
}
// We load `i64` values from random linear memory locations and store the loaded
+623 -619
View File
File diff suppressed because it is too large Load Diff