Skip to content

Commit

Permalink
Implement precompile dispatch. (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
artob committed Mar 19, 2021
1 parent b3be59b commit b184b46
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
8 changes: 1 addition & 7 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,7 @@ impl Engine {
input: Vec<u8>,
) -> (ExitReason, Vec<u8>) {
let mut executor = self.make_executor();
executor.transact_call(
origin,
contract,
value,
input,
u64::max_value(),
)
executor.transact_call(origin, contract, value, input, u64::max_value())
}

fn make_executor(&self) -> StackExecutor<MemoryStackState<Engine>> {
Expand Down
24 changes: 22 additions & 2 deletions src/precompiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,32 @@ pub fn no_precompiles(

#[allow(dead_code)]
pub fn istanbul_precompiles(
_address: Address,
address: Address,
_input: &[u8],
_target_gas: Option<u64>,
_context: &Context,
) -> Option<PrecompileResult> {
None // TODO: implement Istanbul precompiles
if address == Address::from_low_u64_be(1) {
None // TODO: implement ecrecover()
} else if address == Address::from_low_u64_be(2) {
None // TODO: implement sha256()
} else if address == Address::from_low_u64_be(3) {
None // TODO: implement ripemd160()
} else if address == Address::from_low_u64_be(4) {
None // TODO: implement identity()
} else if address == Address::from_low_u64_be(5) {
None // TODO: implement modexp()
} else if address == Address::from_low_u64_be(6) {
None // TODO: implement alt_bn128_add()
} else if address == Address::from_low_u64_be(7) {
None // TODO: implement alt_bn128_mul()
} else if address == Address::from_low_u64_be(8) {
None // TODO: implement alt_bn128_pair()
} else if address == Address::from_low_u64_be(9) {
None // TODO: implement blake2f()
} else {
None // not supported
}
}

/// See: https://ethereum.github.io/yellowpaper/paper.pdf
Expand Down

0 comments on commit b184b46

Please sign in to comment.