From a1c25519583d28190ac2091336ca594cdfb110fa Mon Sep 17 00:00:00 2001 From: Bartosz Nowak Date: Mon, 27 May 2024 15:46:48 +0200 Subject: [PATCH] works WIP --- bootloader_input.json | 5 +- .../contract/execute_entry_point.cairo | 49 +++++++++---------- .../contract/run_contract_bootloader.cairo | 36 +++++++++++--- 3 files changed, 53 insertions(+), 37 deletions(-) diff --git a/bootloader_input.json b/bootloader_input.json index 9f9ad48..0b5879a 100644 --- a/bootloader_input.json +++ b/bootloader_input.json @@ -3,8 +3,6 @@ "prime": "0x800000000000011000000000000000000000000000000000000000000000001", "compiler_version": "2.6.3", "bytecode": [ - "0xa0680017fff8000", - "0x7", "0x482680017ffa8000", "0x100000000000000000000000000000000", "0x400280007ff97fff", @@ -81,6 +79,7 @@ "0x482480017ff98000", "0x1", "0x208b7fff7fff7ffe", + "0x208b7fff7fff7ffe", "0x40780017fff7fff", "0x1", "0x480680017fff8000", @@ -98,7 +97,7 @@ "0x208b7fff7fff7ffe" ], "bytecode_segment_lengths": [ - 93 + 92 ], "hints": [ [ diff --git a/cairo0-bootloader/bootloader/contract/execute_entry_point.cairo b/cairo0-bootloader/bootloader/contract/execute_entry_point.cairo index 40ce9c2..01cd720 100644 --- a/cairo0-bootloader/bootloader/contract/execute_entry_point.cairo +++ b/cairo0-bootloader/bootloader/contract/execute_entry_point.cairo @@ -32,17 +32,6 @@ from starkware.starknet.core.os.constants import ( from contract_class.compiled_class import CompiledClass, CompiledClassEntryPoint, CompiledClassFact from starkware.starknet.core.os.output import OsCarriedOutputs -struct BuiltinData { - output: felt, - pedersen: felt, - range_check: felt, - ecdsa: felt, - bitwise: felt, - ec_op: felt, - keccak: felt, - poseidon: felt, -} - struct ExecutionInfo { selector: felt, } @@ -142,7 +131,7 @@ func get_entry_point{range_check_ptr}( // block_context - a global context that is fixed throughout the block. // execution_context - The context for the current execution. func execute_entry_point{ - range_check_ptr, builtin_ptrs: BuiltinPointers*, builtin_encodings: BuiltinData* + range_check_ptr, builtin_ptrs: BuiltinPointers*, builtin_params: BuiltinParams* }(compiled_class: CompiledClass*, execution_context: ExecutionContext*) -> ( retdata_size: felt, retdata: felt* ) { @@ -176,7 +165,7 @@ func execute_entry_point{ local entry_point_builtin_list: felt* = compiled_class_entry_point.builtin_list; // Call select_input_builtins to push the relevant builtin pointer arguments on the stack. select_input_builtins( - all_encodings=builtin_encodings, + all_encodings=builtin_params.builtin_encodings, all_ptrs=builtin_ptrs, n_all_builtins=n_builtins, selected_encodings=entry_point_builtin_list, @@ -186,33 +175,39 @@ func execute_entry_point{ // Use tempvar to pass the rest of the arguments to contract_entry_point(). let current_ap = ap; tempvar args = EntryPointCallArguments( - gas_builtin=10000000000, + gas_builtin=100000, syscall_ptr=syscall_ptr, calldata_start=calldata_start, calldata_end=calldata_end, ); static_assert ap == current_ap + EntryPointCallArguments.SIZE; - %{ - print(ids.compiled_class_entry_point.n_builtins) - print(ids.calldata_start) - print(ids.calldata_end) - print(ids.contract_entry_point) - print(ids.syscall_ptr) - %} - %{ vm_enter_scope() %} + call abs contract_entry_point; + %{ vm_exit_scope() %} // Retrieve returned_builtin_ptrs_subset. // Note that returned_builtin_ptrs_subset cannot be set in a hint because doing so will allow a // malicious prover to lie about the storage changes of a valid contract. - // let (ap_val) = get_ap(); - // local return_values_ptr: felt* = ap_val - EntryPointReturnValues.SIZE; - // local returned_builtin_ptrs_subset: felt* = return_values_ptr - entry_point_n_builtins; - // local entry_point_return_values: EntryPointReturnValues* = cast( - // return_values_ptr, EntryPointReturnValues* + let (ap_val) = get_ap(); + local return_values_ptr: felt* = ap_val - EntryPointReturnValues.SIZE; + local returned_builtin_ptrs_subset: felt* = return_values_ptr - entry_point_n_builtins; + local entry_point_return_values: EntryPointReturnValues* = cast( + return_values_ptr, EntryPointReturnValues* + ); + + let remaining_gas = entry_point_return_values.gas_builtin; + let retdata_start = entry_point_return_values.retdata_start; + let retdata_end = entry_point_return_values.retdata_end; + + // let return_builtin_ptrs = update_builtin_ptrs( + // builtin_params=builtin_params, + // builtin_ptrs=builtin_ptrs, + // n_selected_builtins=entry_point_n_builtins, + // selected_encodings=entry_point_builtin_list, + // selected_ptrs=returned_builtin_ptrs_subset, // ); return (retdata_size=0, retdata=cast(0, felt*)); diff --git a/cairo0-bootloader/bootloader/contract/run_contract_bootloader.cairo b/cairo0-bootloader/bootloader/contract/run_contract_bootloader.cairo index 823fc41..487ac57 100644 --- a/cairo0-bootloader/bootloader/contract/run_contract_bootloader.cairo +++ b/cairo0-bootloader/bootloader/contract/run_contract_bootloader.cairo @@ -3,20 +3,28 @@ from starkware.cairo.common.cairo_builtins import ( PoseidonBuiltin, BitwiseBuiltin, KeccakBuiltin, + SignatureBuiltin, + EcOpBuiltin, ) from starkware.cairo.common.registers import get_fp_and_pc from contract_class.compiled_class import CompiledClass -from starkware.starknet.builtins.segment_arena.segment_arena import new_arena +from starkware.starknet.builtins.segment_arena.segment_arena import ( + new_arena, + SegmentArenaBuiltin +) from starkware.starknet.core.os.builtins import ( + BuiltinEncodings, + BuiltinParams, BuiltinPointers, NonSelectableBuiltins, + BuiltinInstanceSizes, SelectableBuiltins, + update_builtin_ptrs, ) from bootloader.contract.execute_entry_point import ( execute_entry_point, ExecutionContext, ExecutionInfo, - BuiltinData, ) // Loads the programs and executes them. @@ -57,17 +65,31 @@ func run_contract_bootloader{ ); let builtin_ptrs = &local_builtin_ptrs; - local local_builtin_encodings: BuiltinData = BuiltinData( - output='output', + local local_builtin_encodings: BuiltinEncodings = BuiltinEncodings( pedersen='pedersen', range_check='range_check', ecdsa='ecdsa', bitwise='bitwise', ec_op='ec_op', - keccak='keccak', poseidon='poseidon', + segment_arena='segment_arena', + ); + + local local_builtin_instance_sizes: BuiltinInstanceSizes = BuiltinInstanceSizes( + pedersen=HashBuiltin.SIZE, + range_check=1, + ecdsa=SignatureBuiltin.SIZE, + bitwise=BitwiseBuiltin.SIZE, + ec_op=EcOpBuiltin.SIZE, + poseidon=PoseidonBuiltin.SIZE, + segment_arena=SegmentArenaBuiltin.SIZE, + ); + + local local_builtin_params: BuiltinParams = BuiltinParams( + builtin_encodings=&local_builtin_encodings, + builtin_instance_sizes=&local_builtin_instance_sizes ); - let builtin_encodings = &local_builtin_encodings; + let builtin_params = &local_builtin_params; local calldata: felt*; %{ ids.calldata = segments.add() %} @@ -90,7 +112,7 @@ func run_contract_bootloader{ execution_info=&execution_info, ); - with builtin_ptrs, builtin_encodings { + with builtin_ptrs, builtin_params { let (retdata_size, retdata) = execute_entry_point(compiled_class, &execution_context); }