-
Notifications
You must be signed in to change notification settings - Fork 835
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ECrecover 0x1 precompile and remove the unstable equivalent host function. - depend on #7676 --------- Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Alexander Theißen <[email protected]>
- Loading branch information
1 parent
0c0d892
commit 86019ed
Showing
13 changed files
with
339 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
substrate/frame/revive/fixtures/contracts/call_and_return.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
44
substrate/frame/revive/fixtures/contracts/ecdsa_recover.rs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// 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. | ||
|
||
use crate::{exec::ExecResult, Config, Error, GasMeter, H160}; | ||
|
||
mod ecrecover; | ||
pub use ecrecover::*; | ||
|
||
/// Determine if the given address is a precompile. | ||
/// For now, we consider that all addresses between 0x1 and 0xff are reserved for precompiles. | ||
pub fn is_precompile(address: &H160) -> bool { | ||
let bytes = address.as_bytes(); | ||
bytes.starts_with(&[0u8; 19]) && bytes[19] != 0 | ||
} | ||
|
||
/// The `Precompile` trait defines the functionality for executing a precompiled contract. | ||
pub trait Precompile<T: Config> { | ||
/// Executes the precompile with the provided input data. | ||
fn execute(gas_meter: &mut GasMeter<T>, input: &[u8]) -> ExecResult; | ||
} | ||
|
||
pub struct Precompiles<T: Config> { | ||
_phantom: core::marker::PhantomData<T>, | ||
} | ||
|
||
impl<T: Config> Precompiles<T> { | ||
pub fn execute(addr: H160, gas_meter: &mut GasMeter<T>, input: &[u8]) -> ExecResult { | ||
if addr == ECRECOVER { | ||
ECRecover::execute(gas_meter, input) | ||
} else { | ||
Err(Error::<T>::UnsupportedPrecompileAddress.into()) | ||
} | ||
} | ||
} |
Oops, something went wrong.