diff --git a/Cargo.toml b/Cargo.toml index 57d92f5b6..58870478f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,6 @@ members = [ "src/components/contracts/modules/evm/precompile/basic", "src/components/contracts/modules/evm/precompile/frc20", "src/components/contracts/modules/evm/precompile/modexp", - "src/components/contracts/modules/evm/precompile/sha3fips", "src/components/contracts/modules/evm/precompile/anemoi", "src/components/contracts/modules/evm/precompile/blake2", "src/components/contracts/modules/evm/precompile/bn128", diff --git a/src/components/contracts/baseapp/Cargo.toml b/src/components/contracts/baseapp/Cargo.toml index 65cdd155b..32483d3ba 100644 --- a/src/components/contracts/baseapp/Cargo.toml +++ b/src/components/contracts/baseapp/Cargo.toml @@ -48,7 +48,6 @@ evm-precompile = {path = "../modules/evm/precompile"} evm-precompile-basic = {path = "../modules/evm/precompile/basic"} evm-precompile-frc20 = {path = "../modules/evm/precompile/frc20"} evm-precompile-modexp = {path = "../modules/evm/precompile/modexp"} -evm-precompile-sha3fips = {path = "../modules/evm/precompile/sha3fips"} [features] abci_mock = [] diff --git a/src/components/contracts/baseapp/src/lib.rs b/src/components/contracts/baseapp/src/lib.rs index 19c0c42af..049c4ec9c 100644 --- a/src/components/contracts/baseapp/src/lib.rs +++ b/src/components/contracts/baseapp/src/lib.rs @@ -164,9 +164,6 @@ impl module_evm::Config for BaseApp { evm_precompile_basic::Ripemd160, evm_precompile_basic::Identity, evm_precompile_modexp::Modexp, - evm_precompile_basic::ECRecoverPublicKey, - evm_precompile_sha3fips::Sha3FIPS256, - evm_precompile_sha3fips::Sha3FIPS512, evm_precompile_frc20::FRC20, ); type PrecompilesType = FindoraPrecompiles; diff --git a/src/components/contracts/modules/evm/precompile/Cargo.toml b/src/components/contracts/modules/evm/precompile/Cargo.toml index 875e9a0cf..61af3152e 100644 --- a/src/components/contracts/modules/evm/precompile/Cargo.toml +++ b/src/components/contracts/modules/evm/precompile/Cargo.toml @@ -14,7 +14,6 @@ ethereum-types = "0.13.1" evm-precompile-basic = {path = "./basic"} evm-precompile-frc20 = {path = "./frc20"} evm-precompile-modexp = {path = "./modexp"} -evm-precompile-sha3fips = {path = "./sha3fips"} evm-precompile-anemoi = {path = "./anemoi"} evm-precompile-blake2 = {path = "./blake2"} evm-precompile-bn128 = {path = "./bn128"} diff --git a/src/components/contracts/modules/evm/precompile/basic/src/lib.rs b/src/components/contracts/modules/evm/precompile/basic/src/lib.rs index c1cf4662b..8dce50720 100644 --- a/src/components/contracts/modules/evm/precompile/basic/src/lib.rs +++ b/src/components/contracts/modules/evm/precompile/basic/src/lib.rs @@ -16,7 +16,7 @@ // limitations under the License. use core::cmp::min; -use evm::{executor::stack::PrecompileFailure, ExitError, ExitSucceed}; +use evm::{executor::stack::PrecompileFailure, ExitSucceed}; use module_evm::precompile::{LinearCostPrecompile, PrecompileId}; /// The identity precompile. @@ -127,43 +127,3 @@ impl LinearCostPrecompile for Sha256 { Ok((ExitSucceed::Returned, ret.to_vec())) } } - -/// The ECRecoverPublicKey precompile. -/// Similar to ECRecover, but returns the pubkey (not the corresponding Ethereum address) -pub struct ECRecoverPublicKey; - -impl PrecompileId for ECRecoverPublicKey { - fn contract_id() -> u64 { - 0x6 - } -} - -impl LinearCostPrecompile for ECRecoverPublicKey { - const BASE: u64 = 3000; - const WORD: u64 = 0; - - fn execute( - i: &[u8], - _: u64, - ) -> core::result::Result<(ExitSucceed, Vec), PrecompileFailure> { - let mut input = [0u8; 128]; - input[..min(i.len(), 128)].copy_from_slice(&i[..min(i.len(), 128)]); - - let mut msg = [0u8; 32]; - let mut sig = [0u8; 65]; - - msg[0..32].copy_from_slice(&input[0..32]); - sig[0..32].copy_from_slice(&input[64..96]); - sig[32..64].copy_from_slice(&input[96..128]); - sig[64] = input[63]; - - let pubkey = - fp_types::crypto::secp256k1_ecdsa_recover(&sig, &msg).map_err(|_| { - PrecompileFailure::Error { - exit_status: ExitError::Other("Public key recover failed".into()), - } - })?; - - Ok((ExitSucceed::Returned, pubkey.to_vec())) - } -} diff --git a/src/components/contracts/modules/evm/precompile/sha3fips/Cargo.toml b/src/components/contracts/modules/evm/precompile/sha3fips/Cargo.toml deleted file mode 100644 index 01c867e60..000000000 --- a/src/components/contracts/modules/evm/precompile/sha3fips/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "evm-precompile-sha3fips" -version = "0.1.0" -authors = ["FindoraNetwork"] -edition = "2021" -homepage = "https://findora.org/technology" -repository = "https://github.com/findoranetwork/platform/" -description = "SHA3 FIPS202 precompiles for EVM module." -readme = "README.md" - -[dependencies] -evm = { version = "0.35.0", default-features = false, features = ["with-serde"] } -module-evm = { path = "../../../../modules/evm"} -tiny-keccak = { version = "2.0", features = ["fips202"] } diff --git a/src/components/contracts/modules/evm/precompile/sha3fips/src/lib.rs b/src/components/contracts/modules/evm/precompile/sha3fips/src/lib.rs deleted file mode 100644 index e49880c72..000000000 --- a/src/components/contracts/modules/evm/precompile/sha3fips/src/lib.rs +++ /dev/null @@ -1,69 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 -// This file is part of Frontier. -// -// Copyright (c) 2020 Parity Technologies (UK) Ltd. -// -// 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 evm::executor::stack::PrecompileFailure; -use evm::ExitSucceed; -use module_evm::precompile::{LinearCostPrecompile, PrecompileId}; -use tiny_keccak::Hasher; - -pub struct Sha3FIPS256; - -impl PrecompileId for Sha3FIPS256 { - fn contract_id() -> u64 { - 0x7 - } -} - -impl LinearCostPrecompile for Sha3FIPS256 { - const BASE: u64 = 60; - const WORD: u64 = 12; - - fn execute( - input: &[u8], - _: u64, - ) -> core::result::Result<(ExitSucceed, Vec), PrecompileFailure> { - let mut output = [0; 32]; - let mut sha3 = tiny_keccak::Sha3::v256(); - sha3.update(input); - sha3.finalize(&mut output); - Ok((ExitSucceed::Returned, output.to_vec())) - } -} - -pub struct Sha3FIPS512; - -impl PrecompileId for Sha3FIPS512 { - fn contract_id() -> u64 { - 0x8 - } -} - -impl LinearCostPrecompile for Sha3FIPS512 { - const BASE: u64 = 60; - const WORD: u64 = 12; - - fn execute( - input: &[u8], - _: u64, - ) -> core::result::Result<(ExitSucceed, Vec), PrecompileFailure> { - let mut output = [0; 64]; - let mut sha3 = tiny_keccak::Sha3::v512(); - sha3.update(input); - sha3.finalize(&mut output); - Ok((ExitSucceed::Returned, output.to_vec())) - } -} diff --git a/src/components/contracts/modules/evm/precompile/src/lib.rs b/src/components/contracts/modules/evm/precompile/src/lib.rs index 266b7d6aa..0c4b3afa9 100644 --- a/src/components/contracts/modules/evm/precompile/src/lib.rs +++ b/src/components/contracts/modules/evm/precompile/src/lib.rs @@ -23,7 +23,7 @@ where Self(Default::default(), ctx) } pub fn used_addresses() -> std::vec::Vec { - std::vec![1, 2, 3, 4, 5, 1024, 1025] + std::vec![0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0x1000, 0x2001, 0x2002] .into_iter() .map(hash) .collect() @@ -45,7 +45,7 @@ where let ctx = &self.1; match address { - // Ethereum precompiles : + // Ethereum precompiles: a if a == H160::from_low_u64_be(ECRecover::contract_id()) => { Some(ECRecover::execute(input, target_gas, context, ctx)) }