Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pallet-revive] ecrecover #7652

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
575e6ed
pallet-revive fixes
pgherveou Feb 18, 2025
6145b9b
Update from pgherveou running command 'prdoc --audience runtime_dev -…
github-actions[bot] Feb 18, 2025
e8c30e5
rm log
pgherveou Feb 19, 2025
aef6009
nit comment
pgherveou Feb 19, 2025
eac6620
staticall with non-zero value for account addresses should fail
pgherveou Feb 19, 2025
789f94a
wip
pgherveou Feb 19, 2025
189c4ad
wip
pgherveou Feb 20, 2025
cc5fcbe
Update
pgherveou Feb 20, 2025
d1fb416
Merge branch 'master' into pg/ecrecover
pgherveou Feb 20, 2025
32eddaf
rm unneeded changes
pgherveou Feb 20, 2025
8e31809
fix test
pgherveou Feb 20, 2025
1473625
nit space
pgherveou Feb 20, 2025
7eebdcc
charge gas
pgherveou Feb 20, 2025
cab30ae
simplify
pgherveou Feb 20, 2025
009fb3f
add comments
pgherveou Feb 20, 2025
60bfa83
Update from pgherveou running command 'prdoc --audience runtime_dev -…
github-actions[bot] Feb 20, 2025
3ef1dd4
rename fixture
pgherveou Feb 21, 2025
36b645f
fix tracing should wrap around the entire call stack execution
pgherveou Feb 23, 2025
2d63a28
Merge branch 'master' into pg/ecrecover
pgherveou Feb 23, 2025
11c3111
Merge branch 'pg/fix_tracing_2' into pg/ecrecover
pgherveou Feb 23, 2025
4d782f0
PR reviews
pgherveou Feb 23, 2025
055c96b
rm dp from hex_literal
pgherveou Feb 23, 2025
b520a6c
fix bench tests
pgherveou Feb 23, 2025
a7fa9f6
update test
pgherveou Feb 23, 2025
94bc896
update
pgherveou Feb 23, 2025
13f620e
Update substrate/frame/revive/src/exec.rs
pgherveou Feb 24, 2025
d5db37d
No need foe transcoent storage transaction
pgherveou Feb 24, 2025
a6f6469
lint
pgherveou Feb 24, 2025
54f6105
no call charge for precompiles
pgherveou Feb 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions prdoc/pr_7652.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
title: '[pallet-revive] ecrecover'
doc:
- audience: Runtime Dev
description: |-
Add ECrecover 0x1 precompile and remove the unstable equivalent host function.
crates:
- name: asset-hub-westend-runtime
bump: minor
- name: pallet-revive-eth-rpc
bump: minor
- name: pallet-revive
bump: minor
- name: pallet-revive-fixtures
bump: minor
- name: pallet-revive-uapi
bump: minor
2 changes: 1 addition & 1 deletion substrate/frame/revive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ environmental = { workspace = true }
ethabi = { workspace = true }
ethereum-types = { workspace = true, features = ["codec", "rlp", "serialize"] }
hex = { workspace = true }
hex-literal = { workspace = true }
impl-trait-for-tuples = { workspace = true }
log = { workspace = true }
paste = { workspace = true }
Expand Down Expand Up @@ -61,7 +62,6 @@ xcm-builder = { workspace = true }
[dev-dependencies]
array-bytes = { workspace = true, default-features = true }
assert_matches = { workspace = true }
hex-literal = { workspace = true }
pretty_assertions = { workspace = true }
secp256k1 = { workspace = true, features = ["recovery"] }
serde_json = { workspace = true }
Expand Down
57 changes: 57 additions & 0 deletions substrate/frame/revive/fixtures/contracts/call_and_return.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// This file is part of Substrate.

// Copyright (C) Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! This calls another contract as passed as its account id.
#![no_std]
#![no_main]

use common::{input, u256_bytes};
use uapi::{HostFn, HostFnImpl as api, ReturnErrorCode, ReturnFlags};

#[no_mangle]
#[polkavm_derive::polkavm_export]
pub extern "C" fn deploy() {}

#[no_mangle]
#[polkavm_derive::polkavm_export]
pub extern "C" fn call() {
input!(
256,
callee_addr: &[u8; 20],
value: u64,
callee_input: [u8],
);

// Call the callee
let mut output = [0u8; 32];
let output = &mut &mut output[..];

match api::call(
uapi::CallFlags::empty(),
callee_addr,
u64::MAX, // How much ref_time to devote for the execution. u64::MAX = use all.
u64::MAX, // How much proof_size to devote for the execution. u64::MAX = use all.
&[u8::MAX; 32], // No deposit limit.
&u256_bytes(value), // Value transferred to the contract.
callee_input,
Some(output),
) {
Ok(_) => api::return_value(uapi::ReturnFlags::empty(), output),
Err(ReturnErrorCode::CalleeReverted) => api::return_value(ReturnFlags::REVERT, output),
Err(_) => panic!(),
}
}
44 changes: 0 additions & 44 deletions substrate/frame/revive/fixtures/contracts/ecdsa_recover.rs

This file was deleted.

28 changes: 10 additions & 18 deletions substrate/frame/revive/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use crate::{
evm::runtime::GAS_PRICE,
exec::{Ext, Key, MomentOf},
limits,
pure_precompiles::Precompile,
storage::WriteOutcome,
ConversionPrecision, Pallet as Contracts, *,
};
Expand Down Expand Up @@ -1945,30 +1946,21 @@ mod benchmarks {
}

#[benchmark(pov_mode = Measured)]
fn seal_ecdsa_recover() {
let message_hash = sp_io::hashing::blake2_256("Hello world".as_bytes());
let key_type = sp_core::crypto::KeyTypeId(*b"code");
let signature = {
let pub_key = sp_io::crypto::ecdsa_generate(key_type, None);
let sig = sp_io::crypto::ecdsa_sign_prehashed(key_type, &pub_key, &message_hash)
.expect("Generates signature");
AsRef::<[u8; 65]>::as_ref(&sig).to_vec()
};

build_runtime!(runtime, memory: [signature, message_hash, [0u8; 33], ]);
fn ecdsa_recover() {
use hex_literal::hex;
let input = hex!("18c547e4f7b0f325ad1e56f57e26c745b09a3e503d86e00e5255ff7f715d3d1c000000000000000000000000000000000000000000000000000000000000001c73b1693892219d736caba55bdb67216e485557ea6b6af75f37096c9aa6a5a75feeb940b1d03b21e36b0e47e79769f095fe2ab855bd91e3a38756b7d75a9c4549");
let expected = hex!("000000000000000000000000a94f5374fce5edbc8e2a8697c15331677e6ebf0b");
let mut call_setup = CallSetup::<T>::default();
let (mut ext, _) = call_setup.ext();

let result;

#[block]
{
result = runtime.bench_ecdsa_recover(
memory.as_mut_slice(),
0, // signature_ptr
65, // message_hash_ptr
65 + 32, // output_ptr
);
result = pure_precompiles::ECRecover::execute(ext.gas_meter_mut(), &input);
}

assert_eq!(result.unwrap(), ReturnErrorCode::Success);
assert_eq!(result.unwrap().data, expected);
}

// Only calling the function itself for the list of
Expand Down
Loading
Loading