Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed May 26, 2024
1 parent 84639c7 commit 80fbb3e
Show file tree
Hide file tree
Showing 30 changed files with 133 additions and 100 deletions.
31 changes: 25 additions & 6 deletions cairo0-bootloader/bootloader/hash_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@
from starkware.cairo.common.hash_chain import compute_hash_chain
from starkware.cairo.lang.compiler.program import Program, ProgramBase
from starkware.cairo.lang.version import __version__
from starkware.cairo.lang.vm.crypto import get_crypto_lib_context_manager, poseidon_hash_many
from starkware.cairo.lang.vm.crypto import (
get_crypto_lib_context_manager,
poseidon_hash_many,
)
from starkware.python.utils import from_bytes


def compute_program_hash_chain(program: ProgramBase, use_poseidon: bool, bootloader_version=0):
def compute_program_hash_chain(
program: ProgramBase, use_poseidon: bool, bootloader_version=0
):
"""
Computes a hash chain over a program, including the length of the data chain.
"""
builtin_list = [from_bytes(builtin.encode("ascii")) for builtin in program.builtins]
# The program header below is missing the data length, which is later added to the data_chain.
program_header = [bootloader_version, program.main, len(program.builtins)] + builtin_list
program_header = [
bootloader_version,
program.main,
len(program.builtins),
] + builtin_list
data_chain = program_header + program.data

if use_poseidon:
Expand All @@ -23,8 +32,12 @@ def compute_program_hash_chain(program: ProgramBase, use_poseidon: bool, bootloa


def main():
parser = argparse.ArgumentParser(description="A tool to compute the hash of a cairo program")
parser.add_argument("-v", "--version", action="version", version=f"%(prog)s {__version__}")
parser = argparse.ArgumentParser(
description="A tool to compute the hash of a cairo program"
)
parser.add_argument(
"-v", "--version", action="version", version=f"%(prog)s {__version__}"
)
parser.add_argument(
"--program",
type=argparse.FileType("r"),
Expand All @@ -48,7 +61,13 @@ def main():

with get_crypto_lib_context_manager(args.flavor):
program = Program.Schema().load(json.load(args.program))
print(hex(compute_program_hash_chain(program=program, use_poseidon=args.use_poseidon)))
print(
hex(
compute_program_hash_chain(
program=program, use_poseidon=args.use_poseidon
)
)
)


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions cairo0-bootloader/bootloader/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def load_task(self, memory=None, args_start=None, args_len=None) -> "CairoPieTas
use_poseidon=self.use_poseidon,
)


@marshmallow_dataclass.dataclass(frozen=True)
class CairoSierra(TaskSpec):
TYPE: ClassVar[str] = "CairoSierra"
Expand Down
2 changes: 1 addition & 1 deletion cairo0-bootloader/bootloader/recursive/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
RANGE_CHECK_BUILTIN,
BITWISE_BUILTIN,
]
)
)
2 changes: 1 addition & 1 deletion cairo0-bootloader/bootloader/recursive/execute_task.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,4 @@ func execute_task{builtin_ptrs: BuiltinData*, self_range_check_ptr}(

let builtin_ptrs = &return_builtin_ptrs;
return ();
}
}
17 changes: 4 additions & 13 deletions cairo0-bootloader/bootloader/recursive/run_simple_bootloader.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ from common.registers import get_fp_and_pc
// Updated builtin pointers after executing all programs.
// fact_topologies - that corresponds to the tasks (hint variable).
func run_simple_bootloader{
output_ptr: felt*,
pedersen_ptr: HashBuiltin*,
range_check_ptr,
bitwise_ptr,
output_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr, bitwise_ptr
}() {
alloc_locals;
local task_range_check_ptr;
Expand Down Expand Up @@ -45,17 +42,11 @@ func run_simple_bootloader{

// A struct containing the encoding of each builtin.
local builtin_encodings: BuiltinData = BuiltinData(
output='output',
pedersen='pedersen',
range_check='range_check',
bitwise='bitwise',
output='output', pedersen='pedersen', range_check='range_check', bitwise='bitwise'
);

local builtin_instance_sizes: BuiltinData = BuiltinData(
output=1,
pedersen=3,
range_check=1,
bitwise=5,
output=1, pedersen=3, range_check=1, bitwise=5
);

// Call execute_tasks.
Expand Down Expand Up @@ -152,4 +143,4 @@ func execute_tasks{builtin_ptrs: BuiltinData*, self_range_check_ptr}(
builtin_instance_sizes=builtin_instance_sizes,
n_tasks=n_tasks - 1,
);
}
}
13 changes: 3 additions & 10 deletions cairo0-bootloader/bootloader/recursive/simple_bootloader.cairo
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
%builtins output pedersen range_check bitwise

from bootloader.recursive.run_simple_bootloader import (
run_simple_bootloader,
)
from bootloader.recursive.run_simple_bootloader import run_simple_bootloader
from common.cairo_builtins import HashBuiltin
from common.registers import get_fp_and_pc

func main{
output_ptr: felt*,
pedersen_ptr: HashBuiltin*,
range_check_ptr,
bitwise_ptr,
}() {
func main{output_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr, bitwise_ptr}() {
%{
from bootloader.objects import SimpleBootloaderInput
simple_bootloader_input = SimpleBootloaderInput.Schema().load(program_input)
Expand Down Expand Up @@ -44,4 +37,4 @@ func main{
)
%}
return ();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
BITWISE_BUILTIN,
POSEIDON_BUILTIN,
]
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,4 @@ func execute_task{builtin_ptrs: BuiltinData*, self_range_check_ptr}(

let builtin_ptrs = &return_builtin_ptrs;
return ();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ func run_simple_bootloader{
);

local builtin_instance_sizes: BuiltinData = BuiltinData(
output=1,
pedersen=3,
range_check=1,
bitwise=5,
poseidon=6,
output=1, pedersen=3, range_check=1, bitwise=5, poseidon=6
);

// Call execute_tasks.
Expand Down Expand Up @@ -153,11 +149,7 @@ func execute_tasks{builtin_ptrs: BuiltinData*, self_range_check_ptr}(
}

local input_size = Input.SIZE;
local input: Input = Input(
a=3,
b=4,
c=5,
);
local input: Input = Input(a=3, b=4, c=5);

%{
from bootloader.objects import Task
Expand Down Expand Up @@ -188,4 +180,4 @@ func execute_tasks{builtin_ptrs: BuiltinData*, self_range_check_ptr}(
builtin_instance_sizes=builtin_instance_sizes,
n_tasks=n_tasks - 1,
);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
%builtins output pedersen range_check bitwise poseidon

from bootloader.recursive_with_poseidon.run_simple_bootloader import (
run_simple_bootloader,
)
from bootloader.recursive_with_poseidon.run_simple_bootloader import run_simple_bootloader
from common.cairo_builtins import HashBuiltin, PoseidonBuiltin
from common.registers import get_fp_and_pc

Expand Down Expand Up @@ -45,4 +43,4 @@ func main{
)
%}
return ();
}
}
2 changes: 1 addition & 1 deletion cairo0-bootloader/bootloader/starknet/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
EC_OP_BUILTIN,
POSEIDON_BUILTIN,
]
)
)
2 changes: 1 addition & 1 deletion cairo0-bootloader/bootloader/starknet/execute_task.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,4 @@ func execute_task{builtin_ptrs: BuiltinData*, self_range_check_ptr}(

let builtin_ptrs = &return_builtin_ptrs;
return ();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,7 @@ func run_simple_bootloader{
);

local builtin_instance_sizes: BuiltinData = BuiltinData(
output=1,
pedersen=3,
range_check=1,
ecdsa=2,
bitwise=5,
ec_op=7,
poseidon=6,
output=1, pedersen=3, range_check=1, ecdsa=2, bitwise=5, ec_op=7, poseidon=6
);

// Call execute_tasks.
Expand Down Expand Up @@ -167,4 +161,4 @@ func execute_tasks{builtin_ptrs: BuiltinData*, self_range_check_ptr}(
builtin_instance_sizes=builtin_instance_sizes,
n_tasks=n_tasks - 1,
);
}
}
6 changes: 2 additions & 4 deletions cairo0-bootloader/bootloader/starknet/simple_bootloader.cairo
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
%builtins output pedersen range_check ecdsa bitwise ec_op poseidon

from bootloader.starknet.run_simple_bootloader import (
run_simple_bootloader,
)
from bootloader.starknet.run_simple_bootloader import run_simple_bootloader
from common.cairo_builtins import HashBuiltin, PoseidonBuiltin
from common.registers import get_fp_and_pc

Expand Down Expand Up @@ -47,4 +45,4 @@ func main{
)
%}
return ();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
KECCAK_BUILTIN,
POSEIDON_BUILTIN,
]
)
)
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,4 @@ func execute_task{builtin_ptrs: BuiltinData*, self_range_check_ptr}(

let builtin_ptrs = &return_builtin_ptrs;
return ();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,7 @@ func run_simple_bootloader{
);

local builtin_instance_sizes: BuiltinData = BuiltinData(
output=1,
pedersen=3,
range_check=1,
ecdsa=2,
bitwise=5,
ec_op=7,
keccak=16,
poseidon=6,
output=1, pedersen=3, range_check=1, ecdsa=2, bitwise=5, ec_op=7, keccak=16, poseidon=6
);

// Call execute_tasks.
Expand Down Expand Up @@ -172,4 +165,4 @@ func execute_tasks{builtin_ptrs: BuiltinData*, self_range_check_ptr}(
builtin_instance_sizes=builtin_instance_sizes,
n_tasks=n_tasks - 1,
);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
%builtins output pedersen range_check ecdsa bitwise ec_op keccak poseidon

from bootloader.starknet_with_keccak.run_simple_bootloader import (
run_simple_bootloader,
)
from bootloader.starknet_with_keccak.run_simple_bootloader import run_simple_bootloader
from common.cairo_builtins import HashBuiltin, PoseidonBuiltin
from common.registers import get_fp_and_pc

Expand Down Expand Up @@ -48,4 +46,4 @@ func main{
)
%}
return ();
}
}
Loading

0 comments on commit 80fbb3e

Please sign in to comment.