Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed May 28, 2024
1 parent 9c00d9d commit 1509d14
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 23 deletions.
6 changes: 4 additions & 2 deletions bootloader_input.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"prime": "0x800000000000011000000000000000000000000000000000000000000000001",
"compiler_version": "2.6.3",
"bytecode": [
"0xa0680017fff8000",
"0x7",
"0x482680017ffa8000",
"0x100000000000000000000000000000000",
"0x400280007ff97fff",
Expand Down Expand Up @@ -64,6 +66,7 @@
"0x482480017ff98000",
"0x1",
"0x208b7fff7fff7ffe",
"0x208b7fff7fff7ffe",
"0x40780017fff7fff",
"0x1",
"0x480680017fff8000",
Expand All @@ -79,7 +82,6 @@
"0x482480017ff98000",
"0x1",
"0x208b7fff7fff7ffe",
"0x208b7fff7fff7ffe",
"0x40780017fff7fff",
"0x1",
"0x480680017fff8000",
Expand All @@ -97,7 +99,7 @@
"0x208b7fff7fff7ffe"
],
"bytecode_segment_lengths": [
92
94
],
"hints": [
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ func main{
ids.compiled_class = segments.gen_arg(cairo_contract)
%}

assert compiled_class.bytecode_ptr[compiled_class.bytecode_length] = 0x208b7fff7fff7ffe;

%{
vm_load_program(
contract_bootloader_input.compiled_class.get_runnable_program(entrypoint_builtins=[]),
ids.compiled_class.bytecode_ptr
)
%}

run_contract_bootloader(compiled_class);

return ();
Expand Down
58 changes: 47 additions & 11 deletions cairo0-bootloader/bootloader/contract/execute_entry_point.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,13 @@ func execute_entry_point{

local syscall_ptr: felt*;

%{ ids.syscall_ptr = segments.add() %}
%{
print("contract_entry_point:" , ids.contract_entry_point)
ids.syscall_ptr = segments.add()
from bootloader.contract.syscall_handler import SyscallHandler
syscall_handler = SyscallHandler(segments=segments)
syscall_handler.set_syscall_ptr(syscall_ptr=ids.syscall_ptr)
%}

let builtin_ptrs: BuiltinPointers* = prepare_builtin_ptrs_for_execute(builtin_ptrs);

Expand All @@ -175,17 +181,22 @@ 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=100000,
gas_builtin=0,
syscall_ptr=syscall_ptr,
calldata_start=calldata_start,
calldata_end=calldata_end,
);
static_assert ap == current_ap + EntryPointCallArguments.SIZE;

%{ vm_enter_scope() %}
%{
print("builtin_ptrs:" , ids.builtin_ptrs)
print("syscall_ptr:" , ids.syscall_ptr)
print("calldata_start:" , ids.calldata_start)
print("calldata_end:" , ids.calldata_end)
%}

%{ vm_enter_scope({'syscall_handler': syscall_handler}) %}
call abs contract_entry_point;

%{ vm_exit_scope() %}

// Retrieve returned_builtin_ptrs_subset.
Expand All @@ -198,17 +209,42 @@ func execute_entry_point{
return_values_ptr, EntryPointReturnValues*
);

assert entry_point_return_values.failure_flag = 0;

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,
// );
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,
);

// Validate the segment_arena builtin.
// Note that as the segment_arena pointer points to the first unused element, we need to
// take segment_arena[-1] to get the actual values.
tempvar prev_segment_arena = &builtin_ptrs.selectable.segment_arena[-1];
tempvar current_segment_arena = &return_builtin_ptrs.selectable.segment_arena[-1];
assert prev_segment_arena.infos = current_segment_arena.infos;
validate_segment_arena(segment_arena=current_segment_arena);

let builtin_ptrs = return_builtin_ptrs;
// with syscall_ptr {
// call_execute_syscalls(
// block_context=block_context,
// execution_context=execution_context,
// syscall_ptr_end=entry_point_return_values.syscall_ptr,
// );
// }

%{
print(ids.entry_point_return_values.failure_flag)
for i in range(0, 1):
print(hex(memory[ids.retdata_start + i]))
%}

return (retdata_size=0, retdata=cast(0, felt*));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ from bootloader.contract.execute_entry_point import (
ExecutionContext,
ExecutionInfo,
)
from starkware.starknet.core.os.constants import ENTRY_POINT_TYPE_EXTERNAL

// Loads the programs and executes them.
//
Expand Down Expand Up @@ -62,6 +63,8 @@ func run_contract_bootloader{
);
let builtin_ptrs = &local_builtin_ptrs;

%{ print("builtin_ptrs.selectable.range_check: ", ids.builtin_ptrs.selectable.range_check) %}

local local_builtin_encodings: BuiltinEncodings = BuiltinEncodings(
pedersen='pedersen',
range_check='range_check',
Expand Down Expand Up @@ -93,15 +96,6 @@ func run_contract_bootloader{

local execution_info: ExecutionInfo = ExecutionInfo(selector=0);

from starkware.starknet.core.os.constants import (
DEFAULT_ENTRY_POINT_SELECTOR,
ENTRY_POINT_GAS_COST,
ENTRY_POINT_TYPE_CONSTRUCTOR,
ENTRY_POINT_TYPE_EXTERNAL,
ENTRY_POINT_TYPE_L1_HANDLER,
NOP_ENTRY_POINT_OFFSET,
)

local execution_context: ExecutionContext = ExecutionContext(
entry_point_type=ENTRY_POINT_TYPE_EXTERNAL,
calldata_size=0,
Expand Down
2 changes: 1 addition & 1 deletion compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

log_and_run(
[
f"cairo-compile --cairo_path=. bootloader/contract/simple_bootloader.cairo --output {current_dir}/bootloader.json --proof_mode",
f"cairo-compile --cairo_path=. bootloader/contract/contract_bootloader.cairo --output {current_dir}/bootloader.json --proof_mode",
],
"Compile bootloader program",
cwd="cairo0-bootloader",
Expand Down

0 comments on commit 1509d14

Please sign in to comment.