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

chore: add missing files to git #138

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 30 additions & 0 deletions crates/static-precompiles/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "static-precompiles"
version = "0.1.0"
edition = "2021"

[dependencies]
primitive-types = { version = "^0.12", default-features = false, features = ["rlp"] }
evm = { git = "https://github.com/SigmaGmbH/evm.git", default-features = false, commit = "b76ffcde60078059e99f5f34a32b2b743767619b"}
substrate-bn = { version = "0.6.0", default-features = false }
tiny-keccak = { version = "2.0.2", features = ["fips202"] }
sha2 = { version = "0.9.5", default-features=false }
k256 = { version = "0.11.6", default-features = false, features = ["keccak256", "sha2", "ecdsa"] }
sha3 = { version = "0.10", default-features = false }
num = { version = "0.4", default-features = false, features = ["alloc"] }
ed25519-dalek = { version = "2.0.0", default-features=false }
curve25519-dalek = { version = "=4.1.1", default-features = false, features = ["alloc"] }
sgx_tstd = { git = "https://github.com/apache/teaclave-sgx-sdk.git", rev = "3c903bda", features = ["net", "backtrace"], optional = true }
p256 = { version = "0.13.2",default-features = false, features = ["ecdsa"] }
ripemd = { version = "0.1.3", default-features = false }

[dev-dependencies]
hex = "0.4.3"

[features]
default = []
std = []
sgx = ["sgx_tstd"]

[patch."https://github.com/apache/teaclave-sgx-sdk.git"]
sgx_tstd = { path = "../../sgxvm/sgx-sdk/sgx_tstd" }
61 changes: 61 additions & 0 deletions crates/static-precompiles/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#![cfg_attr(not(feature = "std"), no_std)]

use evm::GasMutState;
use evm::interpreter::error::{ExitError, ExitException, ExitResult};
use evm::interpreter::runtime::RuntimeState;

#[cfg(feature = "std")]
use std::vec::Vec;

#[cfg(not(feature = "std"))]
use sgx_tstd::vec::Vec;

pub mod blake2f;
pub mod bn128;
pub mod curve25519;
pub mod modexp;
pub mod sha3fips;
pub mod ec_recover;
pub mod sha256;
pub mod ripemd160;
pub mod datacopy;
pub mod secp256r1;

pub trait Precompile<G> {
fn execute(input: &[u8], gasometer: &mut G) -> (ExitResult, Vec<u8>);
}

pub trait LinearCostPrecompile {
const BASE: u64;
const WORD: u64;

fn raw_execute(
input: &[u8],
cost: u64,
) -> (ExitResult, Vec<u8>);
}

impl<T: LinearCostPrecompile, G: AsRef<RuntimeState> + GasMutState> Precompile<G> for T {
fn execute(input: &[u8], gasometer: &mut G) -> (ExitResult, Vec<u8>) {
let cost = match linear_cost(input.len() as u64, T::BASE, T::WORD) {
Ok(cost) => cost,
Err(e) => return (Err(e), Vec::new()),
};
if let Err(err) = gasometer.record_gas(cost.into()) {
return (err.into(), Vec::new());
};

T::raw_execute(input, cost)
}
}

pub fn linear_cost(len: u64, base: u64, word: u64) -> Result<u64, ExitError> {
let cost = base
.checked_add(
word.checked_mul(len.saturating_add(31) / 32)
.ok_or(ExitException::OutOfGas)?,
)
.ok_or(ExitException::OutOfGas)?;

Ok(cost)
}
8 changes: 6 additions & 2 deletions go-sgxvm/internal/api/lib_nosgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ func Call(
connector Connector,
from, to, data, value []byte,
accessList ethtypes.AccessList,
gasLimit, nonce uint64,
gasLimit uint64,
gasPrice []byte,
nonce uint64,
txContext *types.TransactionContext,
commit bool,
isUnencrypted bool,
Expand All @@ -89,7 +91,9 @@ func Create(
connector Connector,
from, data, value []byte,
accessList ethtypes.AccessList,
gasLimit, nonce uint64,
gasLimit uint64,
gasPrice []byte,
nonce uint64,
txContext *types.TransactionContext,
commit bool,
) (*types.HandleTransactionResponse, error) {
Expand Down
Loading