diff --git a/cairo0-bootloader/bootloader/hash_program.py b/cairo0-bootloader/bootloader/hash_program.py index de59519..40b34ed 100644 --- a/cairo0-bootloader/bootloader/hash_program.py +++ b/cairo0-bootloader/bootloader/hash_program.py @@ -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: @@ -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"), @@ -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__": diff --git a/cairo0-bootloader/bootloader/objects.py b/cairo0-bootloader/bootloader/objects.py index 71fc221..6f27ac8 100644 --- a/cairo0-bootloader/bootloader/objects.py +++ b/cairo0-bootloader/bootloader/objects.py @@ -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" diff --git a/cairo0-bootloader/bootloader/recursive/builtins.py b/cairo0-bootloader/bootloader/recursive/builtins.py index afd5fe2..a94d066 100644 --- a/cairo0-bootloader/bootloader/recursive/builtins.py +++ b/cairo0-bootloader/bootloader/recursive/builtins.py @@ -7,4 +7,4 @@ RANGE_CHECK_BUILTIN, BITWISE_BUILTIN, ] -) \ No newline at end of file +) diff --git a/cairo0-bootloader/bootloader/recursive/execute_task.cairo b/cairo0-bootloader/bootloader/recursive/execute_task.cairo index f7d9a8e..b6ecd6b 100644 --- a/cairo0-bootloader/bootloader/recursive/execute_task.cairo +++ b/cairo0-bootloader/bootloader/recursive/execute_task.cairo @@ -243,4 +243,4 @@ func execute_task{builtin_ptrs: BuiltinData*, self_range_check_ptr}( let builtin_ptrs = &return_builtin_ptrs; return (); -} \ No newline at end of file +} diff --git a/cairo0-bootloader/bootloader/recursive/run_simple_bootloader.cairo b/cairo0-bootloader/bootloader/recursive/run_simple_bootloader.cairo index 93185ef..03d64f6 100644 --- a/cairo0-bootloader/bootloader/recursive/run_simple_bootloader.cairo +++ b/cairo0-bootloader/bootloader/recursive/run_simple_bootloader.cairo @@ -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; @@ -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. @@ -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, ); -} \ No newline at end of file +} diff --git a/cairo0-bootloader/bootloader/recursive/simple_bootloader.cairo b/cairo0-bootloader/bootloader/recursive/simple_bootloader.cairo index 3d4bf30..5b3b309 100644 --- a/cairo0-bootloader/bootloader/recursive/simple_bootloader.cairo +++ b/cairo0-bootloader/bootloader/recursive/simple_bootloader.cairo @@ -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) @@ -44,4 +37,4 @@ func main{ ) %} return (); -} \ No newline at end of file +} diff --git a/cairo0-bootloader/bootloader/recursive_with_poseidon/builtins.py b/cairo0-bootloader/bootloader/recursive_with_poseidon/builtins.py index bb4b337..78f19ac 100644 --- a/cairo0-bootloader/bootloader/recursive_with_poseidon/builtins.py +++ b/cairo0-bootloader/bootloader/recursive_with_poseidon/builtins.py @@ -8,4 +8,4 @@ BITWISE_BUILTIN, POSEIDON_BUILTIN, ] -) \ No newline at end of file +) diff --git a/cairo0-bootloader/bootloader/recursive_with_poseidon/execute_task.cairo b/cairo0-bootloader/bootloader/recursive_with_poseidon/execute_task.cairo index 5213a85..12f6b77 100644 --- a/cairo0-bootloader/bootloader/recursive_with_poseidon/execute_task.cairo +++ b/cairo0-bootloader/bootloader/recursive_with_poseidon/execute_task.cairo @@ -250,4 +250,4 @@ func execute_task{builtin_ptrs: BuiltinData*, self_range_check_ptr}( let builtin_ptrs = &return_builtin_ptrs; return (); -} \ No newline at end of file +} diff --git a/cairo0-bootloader/bootloader/recursive_with_poseidon/run_simple_bootloader.cairo b/cairo0-bootloader/bootloader/recursive_with_poseidon/run_simple_bootloader.cairo index 46d1071..ffaa8f9 100644 --- a/cairo0-bootloader/bootloader/recursive_with_poseidon/run_simple_bootloader.cairo +++ b/cairo0-bootloader/bootloader/recursive_with_poseidon/run_simple_bootloader.cairo @@ -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. @@ -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 @@ -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, ); -} \ No newline at end of file +} diff --git a/cairo0-bootloader/bootloader/recursive_with_poseidon/simple_bootloader.cairo b/cairo0-bootloader/bootloader/recursive_with_poseidon/simple_bootloader.cairo index efec7e5..74c81f6 100644 --- a/cairo0-bootloader/bootloader/recursive_with_poseidon/simple_bootloader.cairo +++ b/cairo0-bootloader/bootloader/recursive_with_poseidon/simple_bootloader.cairo @@ -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 @@ -45,4 +43,4 @@ func main{ ) %} return (); -} \ No newline at end of file +} diff --git a/cairo0-bootloader/bootloader/starknet/builtins.py b/cairo0-bootloader/bootloader/starknet/builtins.py index 5a7ff01..1bb01a3 100644 --- a/cairo0-bootloader/bootloader/starknet/builtins.py +++ b/cairo0-bootloader/bootloader/starknet/builtins.py @@ -10,4 +10,4 @@ EC_OP_BUILTIN, POSEIDON_BUILTIN, ] -) \ No newline at end of file +) diff --git a/cairo0-bootloader/bootloader/starknet/execute_task.cairo b/cairo0-bootloader/bootloader/starknet/execute_task.cairo index 20afb45..ad8b4f4 100644 --- a/cairo0-bootloader/bootloader/starknet/execute_task.cairo +++ b/cairo0-bootloader/bootloader/starknet/execute_task.cairo @@ -254,4 +254,4 @@ func execute_task{builtin_ptrs: BuiltinData*, self_range_check_ptr}( let builtin_ptrs = &return_builtin_ptrs; return (); -} \ No newline at end of file +} diff --git a/cairo0-bootloader/bootloader/starknet/run_simple_bootloader.cairo b/cairo0-bootloader/bootloader/starknet/run_simple_bootloader.cairo index 6dc5478..0487b72 100644 --- a/cairo0-bootloader/bootloader/starknet/run_simple_bootloader.cairo +++ b/cairo0-bootloader/bootloader/starknet/run_simple_bootloader.cairo @@ -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. @@ -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, ); -} \ No newline at end of file +} diff --git a/cairo0-bootloader/bootloader/starknet/simple_bootloader.cairo b/cairo0-bootloader/bootloader/starknet/simple_bootloader.cairo index f462a16..3b76e52 100644 --- a/cairo0-bootloader/bootloader/starknet/simple_bootloader.cairo +++ b/cairo0-bootloader/bootloader/starknet/simple_bootloader.cairo @@ -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 @@ -47,4 +45,4 @@ func main{ ) %} return (); -} \ No newline at end of file +} diff --git a/cairo0-bootloader/bootloader/starknet_with_keccak/builtins.py b/cairo0-bootloader/bootloader/starknet_with_keccak/builtins.py index e5deb82..0e7b9b8 100644 --- a/cairo0-bootloader/bootloader/starknet_with_keccak/builtins.py +++ b/cairo0-bootloader/bootloader/starknet_with_keccak/builtins.py @@ -11,4 +11,4 @@ KECCAK_BUILTIN, POSEIDON_BUILTIN, ] -) \ No newline at end of file +) diff --git a/cairo0-bootloader/bootloader/starknet_with_keccak/execute_task.cairo b/cairo0-bootloader/bootloader/starknet_with_keccak/execute_task.cairo index 667e55b..b8afb4a 100644 --- a/cairo0-bootloader/bootloader/starknet_with_keccak/execute_task.cairo +++ b/cairo0-bootloader/bootloader/starknet_with_keccak/execute_task.cairo @@ -256,4 +256,4 @@ func execute_task{builtin_ptrs: BuiltinData*, self_range_check_ptr}( let builtin_ptrs = &return_builtin_ptrs; return (); -} \ No newline at end of file +} diff --git a/cairo0-bootloader/bootloader/starknet_with_keccak/run_simple_bootloader.cairo b/cairo0-bootloader/bootloader/starknet_with_keccak/run_simple_bootloader.cairo index e11d89f..c4f90f5 100644 --- a/cairo0-bootloader/bootloader/starknet_with_keccak/run_simple_bootloader.cairo +++ b/cairo0-bootloader/bootloader/starknet_with_keccak/run_simple_bootloader.cairo @@ -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. @@ -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, ); -} \ No newline at end of file +} diff --git a/cairo0-bootloader/bootloader/starknet_with_keccak/simple_bootloader.cairo b/cairo0-bootloader/bootloader/starknet_with_keccak/simple_bootloader.cairo index 0051e68..48eade2 100644 --- a/cairo0-bootloader/bootloader/starknet_with_keccak/simple_bootloader.cairo +++ b/cairo0-bootloader/bootloader/starknet_with_keccak/simple_bootloader.cairo @@ -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 @@ -48,4 +46,4 @@ func main{ ) %} return (); -} \ No newline at end of file +} diff --git a/cairo0-bootloader/bootloader/utils.py b/cairo0-bootloader/bootloader/utils.py index 2adf4b5..4aeed90 100644 --- a/cairo0-bootloader/bootloader/utils.py +++ b/cairo0-bootloader/bootloader/utils.py @@ -14,7 +14,11 @@ from starkware.cairo.lang.compiler.program import Program from starkware.cairo.lang.vm.cairo_pie import CairoPie, ExecutionResources from starkware.cairo.lang.vm.output_builtin_runner import OutputBuiltinRunner -from starkware.cairo.lang.vm.relocatable import MaybeRelocatable, RelocatableValue, relocate_value +from starkware.cairo.lang.vm.relocatable import ( + MaybeRelocatable, + RelocatableValue, + relocate_value, +) from starkware.python.utils import WriteOnceDict, from_bytes SIMPLE_BOOTLOADER_COMPILED_PATH = os.path.join( @@ -89,7 +93,7 @@ def write_return_builtins( used_builtins_addr, pre_execution_builtins_addr, task, - all_builtins + all_builtins, ): """ Writes the updated builtin pointers after the program execution to the given return builtins @@ -100,7 +104,9 @@ def write_return_builtins( used_builtin_offset = 0 for index, builtin in enumerate(all_builtins): if builtin in used_builtins: - memory[return_builtins_addr + index] = memory[used_builtins_addr + used_builtin_offset] + memory[return_builtins_addr + index] = memory[ + used_builtins_addr + used_builtin_offset + ] used_builtin_offset += 1 if isinstance(task, CairoPie): @@ -110,7 +116,9 @@ def write_return_builtins( ), "Builtin usage is inconsistent with the CairoPie." else: # The builtin is unused, hence its value is the same as before calling the program. - memory[return_builtins_addr + index] = memory[pre_execution_builtins_addr + index] + memory[return_builtins_addr + index] = memory[ + pre_execution_builtins_addr + index + ] def load_cairo_pie( @@ -168,8 +176,12 @@ def local_relocate_value(value): esdsa_additional_data = task.additional_data.get("ecdsa_builtin") if esdsa_additional_data is not None: ecdsa_builtin = builtin_runners.get("ecdsa_builtin") - assert ecdsa_builtin is not None, "The task requires the ecdsa builtin but it is missing." - ecdsa_builtin.extend_additional_data(esdsa_additional_data, local_relocate_value) + assert ( + ecdsa_builtin is not None + ), "The task requires the ecdsa builtin but it is missing." + ecdsa_builtin.extend_additional_data( + esdsa_additional_data, local_relocate_value + ) for addr, val in task.memory.items(): memory[local_relocate_value(addr)] = local_relocate_value(val) @@ -220,7 +232,9 @@ def get_task_fact_topology( assert output_runner_data is None fact_topology = get_fact_topology_from_additional_data( output_size=output_size, - output_builtin_additional_data=task.cairo_pie.additional_data["output_builtin"], + output_builtin_additional_data=task.cairo_pie.additional_data[ + "output_builtin" + ], ) else: raise NotImplementedError(f"Unexpected task type: {type(task).__name__}.") @@ -237,7 +251,9 @@ def add_consecutive_output_pages( offset = 0 for i, page_size in enumerate(fact_topology.page_sizes): output_builtin.add_page( - page_id=cur_page_id + i, page_start=output_start + offset, page_size=page_size + page_id=cur_page_id + i, + page_start=output_start + offset, + page_size=page_size, ) offset += page_size @@ -268,10 +284,14 @@ def configure_fact_topologies( output_start += sum(fact_topology.page_sizes) -def write_to_fact_topologies_file(fact_topologies_path: str, fact_topologies: List[FactTopology]): +def write_to_fact_topologies_file( + fact_topologies_path: str, fact_topologies: List[FactTopology] +): with open(fact_topologies_path, "w") as fp: json.dump( - FactTopologiesFile.Schema().dump(FactTopologiesFile(fact_topologies=fact_topologies)), + FactTopologiesFile.Schema().dump( + FactTopologiesFile(fact_topologies=fact_topologies) + ), fp, indent=4, sort_keys=True, @@ -279,17 +299,24 @@ def write_to_fact_topologies_file(fact_topologies_path: str, fact_topologies: Li fp.write("\n") -def calc_simple_bootloader_execution_resources(program_length: int) -> ExecutionResources: +def calc_simple_bootloader_execution_resources( + program_length: int, +) -> ExecutionResources: """ Returns an upper bound on the number of steps and builtin instances that the simple bootloader uses. """ - n_steps = SIMPLE_BOOTLOADER_N_STEPS_RATIO * program_length + SIMPLE_BOOTLOADER_N_STEPS_CONSTANT + n_steps = ( + SIMPLE_BOOTLOADER_N_STEPS_RATIO * program_length + + SIMPLE_BOOTLOADER_N_STEPS_CONSTANT + ) builtin_instance_counter = { "pedersen_builtin": SIMPLE_BOOTLOADER_N_PEDERSEN + program_length, "range_check_builtin": SIMPLE_BOOTLOADER_N_RANGE_CHECKS, "output_builtin": SIMPLE_BOOTLOADER_N_OUTPUT, } return ExecutionResources( - n_steps=n_steps, builtin_instance_counter=builtin_instance_counter, n_memory_holes=0 - ) \ No newline at end of file + n_steps=n_steps, + builtin_instance_counter=builtin_instance_counter, + n_memory_holes=0, + ) diff --git a/cairo0-bootloader/common/builtin_poseidon/poseidon.cairo b/cairo0-bootloader/common/builtin_poseidon/poseidon.cairo index fdabd22..54b3b99 100644 --- a/cairo0-bootloader/common/builtin_poseidon/poseidon.cairo +++ b/cairo0-bootloader/common/builtin_poseidon/poseidon.cairo @@ -104,4 +104,4 @@ func poseidon_hash_many{poseidon_ptr: PoseidonBuiltin*}(n: felt, elements: felt* let res = poseidon_ptr.output.s0; let poseidon_ptr = poseidon_ptr + PoseidonBuiltin.SIZE; return (res=res); -} \ No newline at end of file +} diff --git a/cairo0-bootloader/common/cairo_builtins.cairo b/cairo0-bootloader/common/cairo_builtins.cairo index baf3128..f996e96 100644 --- a/cairo0-bootloader/common/cairo_builtins.cairo +++ b/cairo0-bootloader/common/cairo_builtins.cairo @@ -42,4 +42,4 @@ struct KeccakBuiltin { struct PoseidonBuiltin { input: PoseidonBuiltinState, output: PoseidonBuiltinState, -} \ No newline at end of file +} diff --git a/cairo0-bootloader/common/ec_point.cairo b/cairo0-bootloader/common/ec_point.cairo index 9c526fe..40be277 100644 --- a/cairo0-bootloader/common/ec_point.cairo +++ b/cairo0-bootloader/common/ec_point.cairo @@ -2,4 +2,4 @@ struct EcPoint { x: felt, y: felt, -} \ No newline at end of file +} diff --git a/cairo0-bootloader/common/hash_chain.cairo b/cairo0-bootloader/common/hash_chain.cairo index dd255d0..7edfe47 100644 --- a/cairo0-bootloader/common/hash_chain.cairo +++ b/cairo0-bootloader/common/hash_chain.cairo @@ -44,4 +44,4 @@ func hash_chain{hash_ptr: HashBuiltin*}(data_ptr: felt*) -> (hash: felt) { // Set the hash_ptr implicit argument and return the result. let hash_ptr = next_frame.hash_ptr; return (hash=next_frame.cur_hash); -} \ No newline at end of file +} diff --git a/cairo0-bootloader/common/keccak_state.cairo b/cairo0-bootloader/common/keccak_state.cairo index 3a26220..4e8f9d7 100644 --- a/cairo0-bootloader/common/keccak_state.cairo +++ b/cairo0-bootloader/common/keccak_state.cairo @@ -8,4 +8,4 @@ struct KeccakBuiltinState { s5: felt, s6: felt, s7: felt, -} \ No newline at end of file +} diff --git a/cairo0-bootloader/common/poseidon_state.cairo b/cairo0-bootloader/common/poseidon_state.cairo index 4481493..5942917 100644 --- a/cairo0-bootloader/common/poseidon_state.cairo +++ b/cairo0-bootloader/common/poseidon_state.cairo @@ -3,4 +3,4 @@ struct PoseidonBuiltinState { s0: felt, s1: felt, s2: felt, -} \ No newline at end of file +} diff --git a/cairo0-bootloader/common/registers.cairo b/cairo0-bootloader/common/registers.cairo index 0b0ab8c..bdf8e7b 100644 --- a/cairo0-bootloader/common/registers.cairo +++ b/cairo0-bootloader/common/registers.cairo @@ -23,4 +23,4 @@ func get_label_location(label_value: codeoffset) -> (res: felt*) { ret_pc_label: return (res=pc_val + (label_value - ret_pc_label)); -} \ No newline at end of file +} diff --git a/cairo0-bootloader/lang/compiler/lib/registers.cairo b/cairo0-bootloader/lang/compiler/lib/registers.cairo index 7f18f9d..29d0d98 100644 --- a/cairo0-bootloader/lang/compiler/lib/registers.cairo +++ b/cairo0-bootloader/lang/compiler/lib/registers.cairo @@ -15,4 +15,4 @@ func get_ap() -> (ap_val: felt*) { // Hence, the desired ap value is fp - 2. let (fp_val, pc_val) = get_fp_and_pc(); return (ap_val=fp_val - 2); -} \ No newline at end of file +} diff --git a/cairo0-bootloader/setup.py b/cairo0-bootloader/setup.py index 8ae93a0..7ca13a6 100644 --- a/cairo0-bootloader/setup.py +++ b/cairo0-bootloader/setup.py @@ -18,5 +18,5 @@ "common.builtin_poseidon": ["*.cairo", "*/*.cairo"], "common": ["*.cairo", "*/*.cairo"], "lang.compiler": ["cairo.ebnf", "lib/*.cairo"], - } + }, ) diff --git a/format.sh b/format.sh new file mode 100755 index 0000000..4d3e49e --- /dev/null +++ b/format.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# Function to format a file and print a message based on the outcome +format_file() { + cairo-format -i "$1" + local status=$? + if [ $status -eq 0 ]; then + echo "$(date '+%Y-%m-%d %H:%M:%S') - Successfully formatted $1" + else + echo "$(date '+%Y-%m-%d %H:%M:%S') - Failed to format $1" + return $status + fi +} + +# Export the function so it's available in subshells +export -f format_file + +# Find all .cairo files under src/ and tests/ directories and format them in parallel +# Using --halt soon,fail=1 to stop at the first failure +find ./cairo0-bootloader -name '*.cairo' ! -path "./cairo0-bootloader/build/*" | parallel --halt soon,fail=1 format_file + +# Capture the exit status of parallel +exit_status=$? + +# Exit with the captured status +echo "Parallel execution exited with status: $exit_status" +exit $exit_status \ No newline at end of file diff --git a/install.py b/install.py index 7b439f4..d0dfc27 100644 --- a/install.py +++ b/install.py @@ -1,7 +1,9 @@ import subprocess + def log_and_run(commands, description, cwd=None): from colorama import Fore, Style + full_command = " && ".join(commands) try: print(f"{Fore.YELLOW}Starting: {description}...{Style.RESET_ALL}")