Skip to content

Commit

Permalink
Bump deps & optimize neg_3 (#6)
Browse files Browse the repository at this point in the history
* Bump deps.

* Rewrite.

* Add make rewrite command to file like home.

* inlined neg_3.

* Faster non-inlined neg_3

* clean comment.

* clean

* upd
  • Loading branch information
feltroidprime authored Dec 18, 2024
1 parent dc02aa3 commit 488d1df
Show file tree
Hide file tree
Showing 10 changed files with 65,871 additions and 64,571 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build test coverage run run-profile
.PHONY: build test run
cairo_files = $(shell find ./tests/cairo_programs -name "*.cairo")

build:
Expand Down Expand Up @@ -43,3 +43,7 @@ clean:

hints:
./tools/make/gen_hints_document.py


rewrite:
source venv/bin/activate && python precompiled_circuits/all_circuits.py
9 changes: 8 additions & 1 deletion precompiled_circuits/all_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
DummyCircuit,
EvalFunctionChallengeDuplCircuit,
FinalizeFunctionChallengeDuplCircuit,
FullECIPCircuitBatched,
InitFunctionChallengeDuplCircuit,
IsOnCurveG1Circuit,
IsOnCurveG1G2Circuit,
Expand Down Expand Up @@ -72,6 +73,7 @@ class CircuitID(Enum):
MP_CHECK_FINALIZE_BLS = int.from_bytes(b"mp_check_finalize_bls", "big")
FP12_MUL_ASSERT_ONE = int.from_bytes(b"fp12_mul_assert_one", "big")
EVAL_E12D = int.from_bytes(b"eval_e12d", "big")
FULL_ECIP_BATCHED = int.from_bytes(b"full_ecip_batched", "big")


def find_best_circuit_id_from_int(circuit_id: int) -> CircuitID:
Expand Down Expand Up @@ -185,6 +187,11 @@ def find_best_circuit_id_from_int(circuit_id: int) -> CircuitID:
"params": None,
"filename": "ec",
},
CircuitID.FULL_ECIP_BATCHED: {
"class": FullECIPCircuitBatched,
"params": [{"n_points": k} for k in [1, 2]],
"filename": "ec",
},
}


Expand Down Expand Up @@ -325,7 +332,7 @@ def main(
"""Compiles and writes all circuits to separate .cairo files"""

# Write the header to each file
HEADER = compilation_mode_to_file_header(compilation_mode)
HEADER = compilation_mode_to_file_header(compilation_mode, None)

# Dictionary to store compiled circuits and selectors for each filename
compiled_files = {}
Expand Down
17 changes: 6 additions & 11 deletions precompiled_circuits/compilable_circuits/fustat_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def __init__(
) -> None:
super().__init__(
name="derive_point_from_x",
input_len=3, # X + b + G
curve_id=curve_id,
auto_run=auto_run,
compilation_mode=compilation_mode,
Expand Down Expand Up @@ -58,12 +57,10 @@ def __init__(
init_hash: int = None,
compilation_mode: int = 0,
):
super().__init__(
"fp12_mul", 24, curve_id, auto_run, init_hash, compilation_mode
)
super().__init__("fp12_mul", curve_id, auto_run, init_hash, compilation_mode)

def build_input(self) -> list[PyFelt]:
return [self.field(randint(0, self.field.p - 1)) for _ in range(self.input_len)]
return [self.field(randint(0, self.field.p - 1)) for _ in range(24)]

def _run_circuit_inner(self, input: list[PyFelt]) -> ExtensionFieldModuloCircuit:
circuit = ExtensionFieldModuloCircuit(
Expand Down Expand Up @@ -91,11 +88,11 @@ def __init__(
compilation_mode: int = 0,
):
super().__init__(
"final_exp_part_1", 12, curve_id, auto_run, init_hash, compilation_mode
"final_exp_part_1", curve_id, auto_run, init_hash, compilation_mode
)

def build_input(self) -> list[PyFelt]:
return [self.field(randint(0, self.field.p - 1)) for _ in range(self.input_len)]
return [self.field(randint(0, self.field.p - 1)) for _ in range(12)]

def _run_circuit_inner(self, input: list[PyFelt]) -> ExtensionFieldModuloCircuit:
circuit: final_exp.FinalExpTorusCircuit = final_exp.GaragaFinalExp[
Expand Down Expand Up @@ -123,11 +120,11 @@ def __init__(
compilation_mode: int = 0,
):
super().__init__(
"final_exp_part_2", 12, curve_id, auto_run, init_hash, compilation_mode
"final_exp_part_2", curve_id, auto_run, init_hash, compilation_mode
)

def build_input(self) -> list[PyFelt]:
return [self.field(randint(0, self.field.p - 1)) for _ in range(self.input_len)]
return [self.field(randint(0, self.field.p - 1)) for _ in range(12)]

def _run_circuit_inner(self, input: list[PyFelt]) -> ExtensionFieldModuloCircuit:
circuit: final_exp.FinalExpTorusCircuit = final_exp.GaragaFinalExp[
Expand All @@ -150,7 +147,6 @@ def __init__(
self.n_pairs = n_pairs
super().__init__(
f"multi_miller_loop_{n_pairs}",
6 * n_pairs,
curve_id,
auto_run,
compilation_mode,
Expand Down Expand Up @@ -200,7 +196,6 @@ def __init__(
self.n_pairs = n_pairs
super().__init__(
f"multi_pairing_check_{n_pairs}",
6 * n_pairs,
curve_id,
auto_run,
compilation_mode,
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.0.1"
requires-python = ">=3.10,<3.11"

dependencies = [
"garaga==0.13.3",
"cairo-lang==0.13.2",
"garaga @ git+https://github.com/keep-starknet-strange/garaga.git@hydra_upd",
"cairo-lang==0.13.3",
"protobuf==3.20.3",
"inquirer",
"pandas",
Expand Down
Loading

0 comments on commit 488d1df

Please sign in to comment.