Skip to content

Commit

Permalink
Fix(modexp): use ibig implementation (#778)
Browse files Browse the repository at this point in the history
## Description

Switch to using the `ibig` implementation for modexp. Its performance is
better than current Aurora implementation in some (but not all) cases,
and it is more battle-tested in terms of correctness.
  • Loading branch information
birchmd committed Jun 22, 2023
1 parent bf5605c commit 9ddcc8c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
6 changes: 3 additions & 3 deletions engine-modexp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ publish = false
autobenches = false

[dependencies]
ibig = { version = "0.3.6", default-features = false, features = ["num-traits"], optional = true }
ibig = { version = "0.3.6", default-features = false, features = ["num-traits"] }
num = { version = "0.4.0", default-features = false, features = ["alloc"] }
hex = { version = "0.4", default-features = false, features = ["alloc"] }

[dev-dependencies]

[features]
default = ["std"]
std = ["num/std", "hex/std"]
bench = ["ibig"]
std = ["num/std", "ibig/std", "hex/std"]
bench = []
3 changes: 1 addition & 2 deletions engine-modexp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct AuroraModExp;

impl ModExpAlgorithm for AuroraModExp {
fn modexp(base: &[u8], exp: &[u8], modulus: &[u8]) -> Vec<u8> {
modexp(base, exp, modulus)
modexp_ibig(base, exp, modulus)
}
}

Expand All @@ -37,7 +37,6 @@ pub fn modexp(base: &[u8], exp: &[u8], modulus: &[u8]) -> Vec<u8> {
result.to_big_endian()
}

#[cfg(feature = "bench")]
pub fn modexp_ibig(base: &[u8], exp: &[u8], modulus: &[u8]) -> Vec<u8> {
use num::Zero;

Expand Down
4 changes: 2 additions & 2 deletions engine-tests/src/tests/modexp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ fn bench_modexp_standalone() {
&mut signer,
"../etc/tests/modexp-bench/res/evm_contract_1.hex",
);
do_bench(
/*do_bench( // TODO: re-enable this in the future
&mut standalone,
&mut signer,
"../etc/tests/modexp-bench/res/evm_contract_2.hex",
);
);*/
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion engine-tests/src/tests/repro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ fn repro_Emufid2() {
block_timestamp: 1_662_118_048_636_713_538,
input_path: "src/tests/res/input_Emufid2.hex",
evm_gas_used: 1_156_364,
near_gas_used: 296,
near_gas_used: 285,
});
}

Expand Down

0 comments on commit 9ddcc8c

Please sign in to comment.