Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Sep 23, 2024
1 parent 8a45c9c commit 591429d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 19 deletions.
30 changes: 12 additions & 18 deletions crates/evm/src/precompiles/ec_add.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use core::circuit::CircuitElement as CE;
use core::circuit::CircuitInput as CI;
use core::circuit::u96;

use core::circuit::{
u384, CircuitElement, CircuitInput, circuit_add, circuit_sub, circuit_mul, circuit_inverse,
Expand All @@ -13,12 +14,15 @@ use evm::precompiles::Precompile;
use garaga::core::circuit::AddInputResultTrait2;
use utils::helpers::ToBytes;
use utils::helpers::{load_word, U8SpanExTrait};
use core::circuit::u96;


const BASE_COST: u64 = 150;
const U256_BYTES_LEN: usize = 32;
const PRIME: [u96; 4] = [0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0];
const PRIME: [
u96
; 4] = [
0x6871ca8d3c208c16d87cfd47, 0xb85045b68181585d97816a91, 0x30644e72e131a029, 0x0
];

pub impl EcAdd of Precompile {
#[inline(always)]
Expand Down Expand Up @@ -155,9 +159,7 @@ pub fn is_on_curve(x: u384, y: u384) -> bool {
let rhs = circuit_add(x3, b);
let check = circuit_sub(y2, rhs);

let modulus = TryInto::<
_, CircuitModulus
>::try_into(PRIME)
let modulus = TryInto::<_, CircuitModulus>::try_into(PRIME)
.unwrap(); // BN254 prime field modulus

let mut circuit_inputs = (check,).new_inputs();
Expand Down Expand Up @@ -190,9 +192,7 @@ fn add_ec_point_unchecked(xP: u384, yP: u384, xQ: u384, yQ: u384) -> (u384, u384
let nx = circuit_sub(circuit_sub(slope_sqr, _xP), _xQ);
let ny = circuit_sub(circuit_mul(slope, circuit_sub(_xP, nx)), _yP);

let modulus = TryInto::<
_, CircuitModulus
>::try_into(PRIME)
let modulus = TryInto::<_, CircuitModulus>::try_into(PRIME)
.unwrap(); // BN254 prime field modulus

let mut circuit_inputs = (nx, ny,).new_inputs();
Expand Down Expand Up @@ -224,9 +224,7 @@ pub fn double_ec_point_unchecked(x: u384, y: u384) -> (u384, u384) {
let nx = circuit_sub(circuit_sub(slope_sqr, _x), _x);
let ny = circuit_sub(circuit_mul(slope, circuit_sub(_x, nx)), _y);

let modulus = TryInto::<
_, CircuitModulus
>::try_into(PRIME)
let modulus = TryInto::<_, CircuitModulus>::try_into(PRIME)
.unwrap(); // BN254 prime field modulus

let mut circuit_inputs = (nx, ny,).new_inputs();
Expand All @@ -246,9 +244,7 @@ fn eq_mod_p(a: u384, b: u384) -> bool {
let in2 = CircuitElement::<CircuitInput<1>> {};
let sub = circuit_sub(in1, in2);

let modulus = TryInto::<
_, CircuitModulus
>::try_into(PRIME)
let modulus = TryInto::<_, CircuitModulus>::try_into(PRIME)
.unwrap(); // BN254 prime field modulus

let outputs = (sub,).new_inputs().next_2(a).next_2(b).done_2().eval(modulus).unwrap();
Expand All @@ -262,9 +258,7 @@ fn eq_neg_mod_p(a: u384, b: u384) -> bool {
let _b = CE::<CI<1>> {};
let check = circuit_add(_a, _b);

let modulus = TryInto::<
_, CircuitModulus
>::try_into(PRIME)
let modulus = TryInto::<_, CircuitModulus>::try_into(PRIME)
.unwrap(); // BN254 prime field modulus

let outputs = (check,).new_inputs().next_2(a).next_2(b).done_2().eval(modulus).unwrap();
Expand All @@ -273,7 +267,7 @@ fn eq_neg_mod_p(a: u384, b: u384) -> bool {
}

#[cfg(test)]
mod tests{
mod tests {
use super::ec_add;
#[test]
fn test_ec_add() {
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/src/precompiles/ec_mul.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ mod tests {

#[test]
fn test_ec_mul() {
let (x1,y1,s) = (1,2,2);
let (x1, y1, s) = (1, 2, 2);
let (x, y) = ec_mul(x1, y1, s).expect('ec_mul failed');
assert_eq!(x, 0x030644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd3);
assert_eq!(y, 0x15ed738c0e0a7c92e7845f96b2ae9c0a68a6a449e3538fc7ff3ebf7a5a18a2c4);
Expand Down

0 comments on commit 591429d

Please sign in to comment.