-
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.
- Loading branch information
Showing
26 changed files
with
1,131 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "cairo/packages/garaga_zero"] | ||
path = cairo/packages/garaga_zero | ||
url = https://github.com/petscheit/garaga-zero.git |
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 @@ | ||
3.10.3 |
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,14 @@ | ||
setup: | ||
./scripts/setup.sh | ||
|
||
buildx: | ||
./scripts/cairo_compile.sh | ||
|
||
run: | ||
./scripts/cairo_run.sh | ||
|
||
build_and_run: | ||
./scripts/cairo_compile.sh | ||
./scripts/cairo_run.sh | ||
|
||
|
Submodule garaga_zero
added at
012bd7
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,25 @@ | ||
|
||
# Used for writing a 384 bit integer to the Cairo struct | ||
def write_uint384(ptr, value: int): | ||
mask = (1 << 96) - 1 # Creates a mask of 96 1's in binary | ||
for i in range(4): | ||
chunk = value & mask | ||
setattr(ptr, f'd{i}', chunk) | ||
value >>= 96 # Shift right by 96 bits | ||
|
||
# Creates a G1Point from a point dictionary | ||
def write_g1(ptr, point: dict): | ||
write_uint384(ptr.x, int(point["x"], 16)) | ||
write_uint384(ptr.y, int(point["y"], 16)) | ||
|
||
# Creates a G2Point from a point dictionary | ||
def write_g2(ptr, point: dict): | ||
write_uint384(ptr.x0, int(point["x0"], 16)) | ||
write_uint384(ptr.x1, int(point["x1"], 16)) | ||
write_uint384(ptr.y0, int(point["y0"], 16)) | ||
write_uint384(ptr.y1, int(point["y1"], 16)) | ||
|
||
# Creates a G1G2Pair | ||
def write_g1g2(ptr, g1: dict, g2: dict): | ||
write_g1(ptr.P, g1) | ||
write_g2(ptr.Q, g2) |
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,18 @@ | ||
from definitions import UInt384, G1Point | ||
|
||
func g1_negative() -> G1Point { | ||
return (G1Point( | ||
x=UInt384( | ||
77209383603911340680728987323, | ||
49921657856232494206459177023, | ||
24654436777218005952848247045, | ||
7410505851925769877053596556 | ||
), | ||
y=UInt384( | ||
4578755106311036904654095050, | ||
31671107278004379566943975610, | ||
64119167930385062737200089033, | ||
5354471328347505754258634440 | ||
) | ||
)); | ||
} |
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,42 @@ | ||
%builtins range_check poseidon range_check96 add_mod mul_mod | ||
|
||
from starkware.cairo.common.cairo_builtins import PoseidonBuiltin, ModBuiltin | ||
from starkware.cairo.common.registers import get_fp_and_pc | ||
from starkware.cairo.common.alloc import alloc | ||
from cairo.src.constants import g1_negative | ||
|
||
from definitions import bn, bls, UInt384, one_E12D, N_LIMBS, BASE, E12D, G1Point, G2Point, G1G2Pair | ||
from pairing import multi_pairing | ||
from modulo_circuit import ExtensionFieldModuloCircuit | ||
|
||
func main{ | ||
range_check_ptr, | ||
poseidon_ptr: PoseidonBuiltin*, | ||
range_check96_ptr: felt*, | ||
add_mod_ptr: ModBuiltin*, | ||
mul_mod_ptr: ModBuiltin*, | ||
}() { | ||
alloc_locals; | ||
|
||
|
||
local pk_msg_pair: G1G2Pair; | ||
local sig_point: G2Point; | ||
%{ | ||
from cairo.py.utils import write_g2, write_g1g2 | ||
write_g2(ids.sig_point, program_input["sig"]) | ||
write_g1g2(ids.pk_msg_pair, program_input["pub"], program_input["msg"]) | ||
%} | ||
let neg_g1: G1Point = g1_negative(); | ||
let g1_sig_pair: G1G2Pair = G1G2Pair(P=neg_g1, Q=sig_point); | ||
|
||
let (inputs: G1G2Pair*) = alloc(); | ||
assert inputs[0] = g1_sig_pair; | ||
assert inputs[1] = pk_msg_pair; | ||
|
||
let (res) = multi_pairing(inputs, 2, 1); | ||
let (one) = one_E12D(); | ||
assert res = one; | ||
|
||
return (); | ||
} |
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,5 @@ | ||
# Bankai Client | ||
|
||
This directory contains the required scripts for generating the inputs for the Bankai Cairo programs. | ||
|
||
## Setup |
Oops, something went wrong.