-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fast compile, mpcheck interfaces, improve circuits. (#4)
* Split files for faster compilation, add mpcheck interfaces, improve circuits. * temp patch before new pip package
- Loading branch information
1 parent
b500600
commit 8e10d78
Showing
63 changed files
with
427,915 additions
and
422,852 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from starkware.cairo.common.registers import get_fp_and_pc | ||
from starkware.cairo.common.memcpy import memcpy | ||
from starkware.cairo.common.alloc import alloc | ||
from starkware.cairo.common.cairo_builtins import PoseidonBuiltin, ModBuiltin | ||
from definitions import E12D, E6D, is_zero_E6D, one_E6D, one_E12D, bls, TRUE | ||
|
||
from precompiled_circuits.final_exp_part_1_bls12_381 import get_BLS12_381_FINAL_EXP_PART_1_circuit | ||
from precompiled_circuits.final_exp_part_2_bls12_381 import get_BLS12_381_FINAL_EXP_PART_2_circuit | ||
|
||
from modulo_circuit import ( | ||
run_extension_field_modulo_circuit, | ||
run_extension_field_modulo_circuit_continuation, | ||
) | ||
func final_exponentiation{ | ||
range_check_ptr, | ||
poseidon_ptr: PoseidonBuiltin*, | ||
range_check96_ptr: felt*, | ||
add_mod_ptr: ModBuiltin*, | ||
mul_mod_ptr: ModBuiltin*, | ||
}(input: E12D*) -> (res: E12D) { | ||
alloc_locals; | ||
let (__fp__, _) = get_fp_and_pc(); | ||
|
||
local num: E6D = E6D( | ||
v0=input.w0, v1=input.w2, v2=input.w4, v3=input.w6, v4=input.w8, v5=input.w10 | ||
); | ||
local den: E6D = E6D( | ||
v0=input.w1, v1=input.w3, v2=input.w5, v3=input.w7, v4=input.w9, v5=input.w11 | ||
); | ||
let (local circuit_input: felt*) = alloc(); | ||
memcpy(dst=circuit_input, src=cast(&num, felt*), len=24); | ||
|
||
let (den_is_zero) = is_zero_E6D(den, bls.CURVE_ID); | ||
if (den_is_zero == TRUE) { | ||
let (local one_E6: E6D) = one_E6D(); | ||
memcpy(dst=circuit_input + 24, src=cast(&one_E6, felt*), len=24); | ||
} else { | ||
memcpy(dst=circuit_input + 24, src=cast(&den, felt*), len=24); | ||
} | ||
|
||
let (local circuit) = get_BLS12_381_FINAL_EXP_PART_1_circuit(); | ||
let (output: felt*, Z: felt) = run_extension_field_modulo_circuit(circuit, circuit_input); | ||
// %{ | ||
// part1 = pack_bigint_ptr(memory, ids.output, 4, 2**96, ids.circuit.output_len//4) | ||
// for x in part1: | ||
// print(f"T0/T2/_SUM = {hex(x)}") | ||
// %} | ||
let _sum = [cast(output + 2 * E6D.SIZE, E6D*)]; | ||
let (_sum_is_zero) = is_zero_E6D(_sum, bls.CURVE_ID); | ||
|
||
if (_sum_is_zero == TRUE) { | ||
let (one_E12: E12D) = one_E12D(); | ||
return (res=one_E12); | ||
} else { | ||
let (circuit) = get_BLS12_381_FINAL_EXP_PART_2_circuit(); | ||
let (output: felt*, _: felt) = run_extension_field_modulo_circuit_continuation( | ||
circuit, output, Z | ||
); | ||
return (res=[cast(output, E12D*)]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from starkware.cairo.common.registers import get_fp_and_pc | ||
from starkware.cairo.common.cairo_builtins import PoseidonBuiltin, ModBuiltin, UInt384 | ||
from definitions import E12D, E6D, G1G2Pair, TRUE, bls | ||
|
||
from precompiled_circuits.multi_miller_loop_bls12_381_1 import ( | ||
get_BLS12_381_MULTI_MILLER_LOOP_1_circuit, | ||
) | ||
|
||
from modulo_circuit import ( | ||
run_extension_field_modulo_circuit, | ||
run_extension_field_modulo_circuit_continuation, | ||
) | ||
from bls12_381.final_exp import final_exponentiation | ||
from ec_ops import all_g1_g2_pairs_are_on_curve | ||
|
||
func multi_pairing_1P{ | ||
range_check_ptr, | ||
poseidon_ptr: PoseidonBuiltin*, | ||
range_check96_ptr: felt*, | ||
add_mod_ptr: ModBuiltin*, | ||
mul_mod_ptr: ModBuiltin*, | ||
}(input: G1G2Pair*) -> (res: E12D) { | ||
alloc_locals; | ||
let n_pairs = 1; | ||
let (all_on_curve) = all_g1_g2_pairs_are_on_curve(input, n_pairs, bls.CURVE_ID); | ||
assert all_on_curve = TRUE; | ||
|
||
let (m) = multi_miller_loop_1P(cast(input, felt*)); | ||
|
||
let (f) = final_exponentiation(m); | ||
|
||
return (res=f); | ||
} | ||
|
||
func multi_miller_loop_1P{ | ||
range_check_ptr, | ||
poseidon_ptr: PoseidonBuiltin*, | ||
range_check96_ptr: felt*, | ||
add_mod_ptr: ModBuiltin*, | ||
mul_mod_ptr: ModBuiltin*, | ||
}(input: felt*) -> (res: E12D*) { | ||
alloc_locals; | ||
let (__fp__, _) = get_fp_and_pc(); | ||
let (circuit) = get_BLS12_381_MULTI_MILLER_LOOP_1_circuit(); | ||
let (output: felt*, _) = run_extension_field_modulo_circuit(circuit, input); | ||
return (res=cast(output, E12D*)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from starkware.cairo.common.registers import get_fp_and_pc | ||
from starkware.cairo.common.cairo_builtins import PoseidonBuiltin, ModBuiltin, UInt384 | ||
from definitions import E12D, E6D, G1G2Pair, TRUE, bls | ||
|
||
from precompiled_circuits.multi_miller_loop_bls12_381_2 import ( | ||
get_BLS12_381_MULTI_MILLER_LOOP_2_circuit, | ||
) | ||
|
||
from modulo_circuit import ( | ||
run_extension_field_modulo_circuit, | ||
run_extension_field_modulo_circuit_continuation, | ||
) | ||
from bls12_381.final_exp import final_exponentiation | ||
from ec_ops import all_g1_g2_pairs_are_on_curve | ||
|
||
func multi_pairing_2P{ | ||
range_check_ptr, | ||
poseidon_ptr: PoseidonBuiltin*, | ||
range_check96_ptr: felt*, | ||
add_mod_ptr: ModBuiltin*, | ||
mul_mod_ptr: ModBuiltin*, | ||
}(input: G1G2Pair*) -> (res: E12D) { | ||
alloc_locals; | ||
let n_pairs = 2; | ||
let (all_on_curve) = all_g1_g2_pairs_are_on_curve(input, n_pairs, bls.CURVE_ID); | ||
assert all_on_curve = TRUE; | ||
|
||
let (m) = multi_miller_loop_2P(cast(input, felt*)); | ||
|
||
let (f) = final_exponentiation(m); | ||
|
||
return (res=f); | ||
} | ||
|
||
func multi_miller_loop_2P{ | ||
range_check_ptr, | ||
poseidon_ptr: PoseidonBuiltin*, | ||
range_check96_ptr: felt*, | ||
add_mod_ptr: ModBuiltin*, | ||
mul_mod_ptr: ModBuiltin*, | ||
}(input: felt*) -> (res: E12D*) { | ||
alloc_locals; | ||
let (__fp__, _) = get_fp_and_pc(); | ||
let (circuit) = get_BLS12_381_MULTI_MILLER_LOOP_2_circuit(); | ||
let (output: felt*, _) = run_extension_field_modulo_circuit(circuit, input); | ||
return (res=cast(output, E12D*)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from starkware.cairo.common.registers import get_fp_and_pc | ||
from starkware.cairo.common.cairo_builtins import PoseidonBuiltin, ModBuiltin, UInt384 | ||
from definitions import E12D, E6D, G1G2Pair, TRUE, bls | ||
|
||
from precompiled_circuits.multi_miller_loop_bls12_381_3 import ( | ||
get_BLS12_381_MULTI_MILLER_LOOP_3_circuit, | ||
) | ||
|
||
from modulo_circuit import ( | ||
run_extension_field_modulo_circuit, | ||
run_extension_field_modulo_circuit_continuation, | ||
) | ||
from bls12_381.final_exp import final_exponentiation | ||
from ec_ops import all_g1_g2_pairs_are_on_curve | ||
|
||
func multi_pairing_3P{ | ||
range_check_ptr, | ||
poseidon_ptr: PoseidonBuiltin*, | ||
range_check96_ptr: felt*, | ||
add_mod_ptr: ModBuiltin*, | ||
mul_mod_ptr: ModBuiltin*, | ||
}(input: G1G2Pair*) -> (res: E12D) { | ||
alloc_locals; | ||
let n_pairs = 3; | ||
let (all_on_curve) = all_g1_g2_pairs_are_on_curve(input, n_pairs, bls.CURVE_ID); | ||
assert all_on_curve = TRUE; | ||
|
||
let (m) = multi_miller_loop_3P(cast(input, felt*)); | ||
|
||
let (f) = final_exponentiation(m); | ||
|
||
return (res=f); | ||
} | ||
|
||
func multi_miller_loop_3P{ | ||
range_check_ptr, | ||
poseidon_ptr: PoseidonBuiltin*, | ||
range_check96_ptr: felt*, | ||
add_mod_ptr: ModBuiltin*, | ||
mul_mod_ptr: ModBuiltin*, | ||
}(input: felt*) -> (res: E12D*) { | ||
alloc_locals; | ||
let (__fp__, _) = get_fp_and_pc(); | ||
let (circuit) = get_BLS12_381_MULTI_MILLER_LOOP_3_circuit(); | ||
let (output: felt*, _) = run_extension_field_modulo_circuit(circuit, input); | ||
return (res=cast(output, E12D*)); | ||
} |
Oops, something went wrong.