Skip to content

Commit 61308f9

Browse files
authored
Merge branch 'master' into AndreiEres/flaky-zombie-statement
2 parents 9b834e5 + 363bd6b commit 61308f9

34 files changed

+5925
-748
lines changed

Cargo.lock

+20-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+4-1
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ bitvec = { version = "1.0.1", default-features = false }
645645
blake2 = { version = "0.10.4", default-features = false }
646646
blake2b_simd = { version = "1.0.2", default-features = false }
647647
blake3 = { version = "1.5" }
648+
bn = { package = "substrate-bn", version = "0.6", default-features = false }
648649
bounded-collections = { version = "0.2.3", default-features = false }
649650
bounded-vec = { version = "0.7" }
650651
bp-asset-hub-rococo = { path = "bridges/chains/chain-asset-hub-rococo", default-features = false }
@@ -888,8 +889,9 @@ node-rpc = { path = "substrate/bin/node/rpc" }
888889
node-testing = { path = "substrate/bin/node/testing" }
889890
nohash-hasher = { version = "0.2.0" }
890891
novelpoly = { version = "2.0.0", package = "reed-solomon-novelpoly" }
891-
num-bigint = { version = "0.4.3" }
892+
num-bigint = { version = "0.4.3", default-features = false }
892893
num-format = { version = "0.4.3" }
894+
num-integer = { version = "0.1.46", default-features = false }
893895
num-rational = { version = "0.4.1" }
894896
num-traits = { version = "0.2.17", default-features = false }
895897
num_cpus = { version = "1.13.1" }
@@ -1137,6 +1139,7 @@ relay-substrate-client = { path = "bridges/relays/client-substrate" }
11371139
relay-utils = { path = "bridges/relays/utils" }
11381140
remote-externalities = { path = "substrate/utils/frame/remote-externalities", default-features = false, package = "frame-remote-externalities" }
11391141
reqwest = { version = "0.12.9", default-features = false }
1142+
ripemd = { version = "0.1.3", default-features = false }
11401143
rlp = { version = "0.6.1", default-features = false }
11411144
rococo-emulated-chain = { path = "cumulus/parachains/integration-tests/emulated/chains/relays/rococo" }
11421145
rococo-parachain-runtime = { path = "cumulus/parachains/runtimes/testing/rococo-parachain" }

cumulus/client/consensus/aura/src/collator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ where
398398
aura_internal::seal::<_, P>(&pre_hash, &author_pub, keystore).map_err(Box::new)?;
399399
let mut block_import_params = BlockImportParams::new(BlockOrigin::Own, pre_header);
400400
block_import_params.post_digests.push(seal_digest);
401-
block_import_params.body = Some(body.clone());
401+
block_import_params.body = Some(body);
402402
block_import_params.state_action =
403403
StateAction::ApplyChanges(sc_consensus::StorageChanges::Changes(storage_changes));
404404
block_import_params.fork_choice = Some(ForkChoiceStrategy::LongestChain);

prdoc/pr_7810.prdoc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
title: '[pallet-revive] precompiles 2->9'
2+
doc:
3+
- audience: Runtime Dev
4+
description: Add missing pre-compiles 02 -> 09
5+
crates:
6+
- name: pallet-revive
7+
bump: patch
8+
- name: pallet-revive-fixtures
9+
bump: patch
10+
- name: pallet-revive-uapi
11+
bump: patch

substrate/client/consensus/aura/src/standalone.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ where
141141
})?;
142142

143143
let signature = signature
144-
.clone()
144+
.as_slice()
145145
.try_into()
146146
.map_err(|_| ConsensusError::InvalidSignature(signature, public.to_raw_vec()))?;
147147

substrate/frame/revive/Cargo.toml

+9
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ ethereum-types = { workspace = true, features = ["codec", "rlp", "serialize"] }
2626
hex-literal = { workspace = true }
2727
impl-trait-for-tuples = { workspace = true }
2828
log = { workspace = true }
29+
num-bigint = { workspace = true }
30+
num-integer = { workspace = true }
31+
num-traits = { workspace = true }
2932
paste = { workspace = true }
3033
polkavm = { version = "0.21.0", default-features = false }
3134
polkavm-common = { version = "0.21.0", default-features = false, optional = true }
@@ -39,13 +42,15 @@ serde = { features = [
3942
], workspace = true, default-features = false }
4043

4144
# Polkadot SDK Dependencies
45+
bn = { workspace = true }
4246
frame-benchmarking = { optional = true, workspace = true }
4347
frame-support = { workspace = true }
4448
frame-system = { workspace = true }
4549
pallet-revive-fixtures = { workspace = true, optional = true }
4650
pallet-revive-proc-macro = { workspace = true }
4751
pallet-revive-uapi = { workspace = true, features = ["scale"] }
4852
pallet-transaction-payment = { workspace = true }
53+
ripemd = { workspace = true }
4954
sp-api = { workspace = true }
5055
sp-arithmetic = { workspace = true }
5156
sp-consensus-aura = { workspace = true, optional = true }
@@ -89,6 +94,9 @@ std = [
8994
"frame-support/std",
9095
"frame-system/std",
9196
"log/std",
97+
"num-bigint/std",
98+
"num-integer/std",
99+
"num-traits/std",
92100
"pallet-proxy/std",
93101
"pallet-revive-fixtures?/std",
94102
"pallet-timestamp/std",
@@ -97,6 +105,7 @@ std = [
97105
"polkavm-common?/std",
98106
"polkavm/std",
99107
"rand?/std",
108+
"ripemd/std",
100109
"rlp/std",
101110
"scale-info/std",
102111
"secp256k1/std",

substrate/frame/revive/fixtures/contracts/call_and_return.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ pub extern "C" fn deploy() {}
3030
#[polkavm_derive::polkavm_export]
3131
pub extern "C" fn call() {
3232
input!(
33-
256,
33+
512,
3434
callee_addr: &[u8; 20],
3535
value: u64,
3636
callee_input: [u8],
3737
);
3838

3939
// Call the callee
40-
let mut output = [0u8; 32];
40+
let mut output = [0u8; 512];
4141
let output = &mut &mut output[..];
4242

4343
match api::call(

substrate/frame/revive/fixtures/contracts/crypto_hashes.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ pub extern "C" fn deploy() {}
4343
///
4444
/// | value | Algorithm | Bit Width |
4545
/// |-------|-----------|-----------|
46-
/// | 0 | SHA2 | 256 |
47-
/// | 1 | KECCAK | 256 |
48-
/// | 2 | BLAKE2 | 256 |
49-
/// | 3 | BLAKE2 | 128 |
46+
/// | 2 | KECCAK | 256 |
47+
/// | 3 | BLAKE2 | 256 |
48+
/// | 4 | BLAKE2 | 128 |
5049
/// ---------------------------------
5150
5251
#[no_mangle]
@@ -59,11 +58,6 @@ pub extern "C" fn call() {
5958
);
6059

6160
match chosen_hash_fn {
62-
1 => {
63-
let mut output = [0u8; 32];
64-
api::hash_sha2_256(input, &mut output);
65-
api::return_value(uapi::ReturnFlags::empty(), &output);
66-
},
6761
2 => {
6862
let mut output = [0u8; 32];
6963
api::hash_keccak_256(input, &mut output);

substrate/frame/revive/src/benchmarking/mod.rs

+107-5
Original file line numberDiff line numberDiff line change
@@ -1854,16 +1854,50 @@ mod benchmarks {
18541854

18551855
// `n`: Input to hash in bytes
18561856
#[benchmark(pov_mode = Measured)]
1857-
fn seal_hash_sha2_256(n: Linear<0, { limits::code::BLOB_BYTES }>) {
1858-
build_runtime!(runtime, memory: [[0u8; 32], vec![0u8; n as usize], ]);
1857+
fn sha2_256(n: Linear<0, { limits::code::BLOB_BYTES }>) {
1858+
let input = vec![0u8; n as usize];
1859+
let mut call_setup = CallSetup::<T>::default();
1860+
let (mut ext, _) = call_setup.ext();
18591861

18601862
let result;
18611863
#[block]
18621864
{
1863-
result = runtime.bench_hash_sha2_256(memory.as_mut_slice(), 32, n, 0);
1865+
result = pure_precompiles::Sha256::execute(ext.gas_meter_mut(), &input);
18641866
}
1865-
assert_eq!(sp_io::hashing::sha2_256(&memory[32..]), &memory[0..32]);
1866-
assert_ok!(result);
1867+
assert_eq!(sp_io::hashing::sha2_256(&input).to_vec(), result.unwrap().data);
1868+
}
1869+
1870+
#[benchmark(pov_mode = Measured)]
1871+
fn identity(n: Linear<0, { limits::code::BLOB_BYTES }>) {
1872+
let input = vec![0u8; n as usize];
1873+
let mut call_setup = CallSetup::<T>::default();
1874+
let (mut ext, _) = call_setup.ext();
1875+
1876+
let result;
1877+
#[block]
1878+
{
1879+
result = pure_precompiles::Identity::execute(ext.gas_meter_mut(), &input);
1880+
}
1881+
assert_eq!(input, result.unwrap().data);
1882+
}
1883+
1884+
// `n`: Input to hash in bytes
1885+
#[benchmark(pov_mode = Measured)]
1886+
fn ripemd_160(n: Linear<0, { limits::code::BLOB_BYTES }>) {
1887+
use ripemd::Digest;
1888+
let input = vec![0u8; n as usize];
1889+
let mut call_setup = CallSetup::<T>::default();
1890+
let (mut ext, _) = call_setup.ext();
1891+
1892+
let result;
1893+
#[block]
1894+
{
1895+
result = pure_precompiles::Ripemd160::execute(ext.gas_meter_mut(), &input);
1896+
}
1897+
let mut expected = [0u8; 32];
1898+
expected[12..32].copy_from_slice(&ripemd::Ripemd160::digest(input));
1899+
1900+
assert_eq!(expected.to_vec(), result.unwrap().data);
18671901
}
18681902

18691903
// `n`: Input to hash in bytes
@@ -1957,6 +1991,74 @@ mod benchmarks {
19571991
assert_eq!(result.unwrap().data, expected);
19581992
}
19591993

1994+
#[benchmark(pov_mode = Measured)]
1995+
fn bn128_add() {
1996+
use hex_literal::hex;
1997+
let input = hex!("089142debb13c461f61523586a60732d8b69c5b38a3380a74da7b2961d867dbf2d5fc7bbc013c16d7945f190b232eacc25da675c0eb093fe6b9f1b4b4e107b3625f8c89ea3437f44f8fc8b6bfbb6312074dc6f983809a5e809ff4e1d076dd5850b38c7ced6e4daef9c4347f370d6d8b58f4b1d8dc61a3c59d651a0644a2a27cf");
1998+
let expected = hex!("0a6678fd675aa4d8f0d03a1feb921a27f38ebdcb860cc083653519655acd6d79172fd5b3b2bfdd44e43bcec3eace9347608f9f0a16f1e184cb3f52e6f259cbeb");
1999+
let mut call_setup = CallSetup::<T>::default();
2000+
let (mut ext, _) = call_setup.ext();
2001+
2002+
let result;
2003+
2004+
#[block]
2005+
{
2006+
result = pure_precompiles::Bn128Add::execute(ext.gas_meter_mut(), &input);
2007+
}
2008+
2009+
assert_eq!(result.unwrap().data, expected);
2010+
}
2011+
2012+
#[benchmark(pov_mode = Measured)]
2013+
fn bn128_mul() {
2014+
use hex_literal::hex;
2015+
let input = hex!("089142debb13c461f61523586a60732d8b69c5b38a3380a74da7b2961d867dbf2d5fc7bbc013c16d7945f190b232eacc25da675c0eb093fe6b9f1b4b4e107b36ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
2016+
let expected = hex!("0bf982b98a2757878c051bfe7eee228b12bc69274b918f08d9fcb21e9184ddc10b17c77cbf3c19d5d27e18cbd4a8c336afb488d0e92c18d56e64dd4ea5c437e6");
2017+
let mut call_setup = CallSetup::<T>::default();
2018+
let (mut ext, _) = call_setup.ext();
2019+
2020+
let result;
2021+
2022+
#[block]
2023+
{
2024+
result = pure_precompiles::Bn128Mul::execute(ext.gas_meter_mut(), &input);
2025+
}
2026+
2027+
assert_eq!(result.unwrap().data, expected);
2028+
}
2029+
2030+
// `n`: pairings to perform
2031+
#[benchmark(pov_mode = Measured)]
2032+
fn bn128_pairing(n: Linear<0, { limits::code::BLOB_BYTES / 192 }>) {
2033+
let input = pure_precompiles::generate_random_ecpairs(n as usize);
2034+
let mut call_setup = CallSetup::<T>::default();
2035+
let (mut ext, _) = call_setup.ext();
2036+
2037+
let result;
2038+
#[block]
2039+
{
2040+
result = pure_precompiles::Bn128Pairing::execute(ext.gas_meter_mut(), &input);
2041+
}
2042+
assert_ok!(result);
2043+
}
2044+
2045+
// `n`: number of rounds to perform
2046+
#[benchmark(pov_mode = Measured)]
2047+
fn blake2f(n: Linear<0, 1200>) {
2048+
use hex_literal::hex;
2049+
let input = hex!("48c9bdf267e6096a3ba7ca8485ae67bb2bf894fe72f36e3cf1361d5f3af54fa5d182e6ad7f520e511f6c3e2b8c68059b6bbd41fbabd9831f79217e1319cde05b61626300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000001");
2050+
let input = n.to_be_bytes().to_vec().into_iter().chain(input.to_vec()).collect::<Vec<_>>();
2051+
let mut call_setup = CallSetup::<T>::default();
2052+
let (mut ext, _) = call_setup.ext();
2053+
2054+
let result;
2055+
#[block]
2056+
{
2057+
result = pure_precompiles::Blake2F::execute(ext.gas_meter_mut(), &input);
2058+
}
2059+
assert_ok!(result);
2060+
}
2061+
19602062
// Only calling the function itself for the list of
19612063
// generated different ECDSA keys.
19622064
// This is a slow call: We reduce the number of runs.

substrate/frame/revive/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,8 @@ pub mod pallet {
495495
RefcountOverOrUnderflow,
496496
/// Unsupported precompile address
497497
UnsupportedPrecompileAddress,
498+
/// Precompile Error
499+
PrecompileFailure,
498500
}
499501

500502
/// A reason for the pallet contracts placing a hold on funds.

0 commit comments

Comments
 (0)