Skip to content

Commit

Permalink
Add EIP1962 precompile
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Dec 10, 2019
1 parent 4f2adff commit 13a3d02
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"ecpairing",
"ecrecover",
"ed25519",
"eip1962",
"identity",
"keccak256",
"modexp",
Expand Down
13 changes: 13 additions & 0 deletions chisel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ ed25519:
repack:
preset: "ewasm"

eip1962:
file: "target/wasm32-unknown-unknown/release/ewasm_precompile_eip1962.wasm"
remapimports:
preset: "ewasm"
trimexports:
preset: "ewasm"
verifyimports:
preset: "ewasm"
verifyexports:
preset: "ewasm"
repack:
preset: "ewasm"

identity:
file: "target/wasm32-unknown-unknown/release/ewasm_precompile_identity.wasm"
remapimports:
Expand Down
17 changes: 17 additions & 0 deletions eip1962/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "ewasm-precompile-eip1962"
version = "0.2.0"
authors = ["Alex Beregszaszi <[email protected]>"]
license = "Apache-2.0"
repository = "https://github.com/ewasm/ewasm-precompiles"
description = "Ethereum EIP1962 precompile in Rust"
publish = false
edition = "2018"

[dependencies]
ewasm_api = "0.9"
# 0.2.0
eth_pairings = { git = "https://github.com/matter-labs/eip1962", rev = "6a06b44cd8d5dd9265480312a08b4a7c69fbbbe0" }

[lib]
crate-type = ["cdylib"]
25 changes: 25 additions & 0 deletions eip1962/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
extern crate ewasm_api;

#[cfg(not(test))]
#[no_mangle]
pub extern "C" fn main() {
let input = ewasm_api::calldata_acquire();

let gas_cost = eth_pairings::gas_meter::GasMeter::meter(&input);
let gas_cost = if gas_cost.is_err() {
ewasm_api::abort();
} else {
gas_cost.unwrap()
};

ewasm_api::consume_gas(gas_cost);

let result = eth_pairings::public_interface::API::run(&input);
let result = if result.is_err() {
ewasm_api::abort();
} else {
result.unwrap()
};

ewasm_api::finish_data(&result);
}

0 comments on commit 13a3d02

Please sign in to comment.