Skip to content

Commit

Permalink
works WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed May 27, 2024
1 parent 3c15fda commit a1c2551
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 37 deletions.
5 changes: 2 additions & 3 deletions bootloader_input.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
"prime": "0x800000000000011000000000000000000000000000000000000000000000001",
"compiler_version": "2.6.3",
"bytecode": [
"0xa0680017fff8000",
"0x7",
"0x482680017ffa8000",
"0x100000000000000000000000000000000",
"0x400280007ff97fff",
Expand Down Expand Up @@ -81,6 +79,7 @@
"0x482480017ff98000",
"0x1",
"0x208b7fff7fff7ffe",
"0x208b7fff7fff7ffe",
"0x40780017fff7fff",
"0x1",
"0x480680017fff8000",
Expand All @@ -98,7 +97,7 @@
"0x208b7fff7fff7ffe"
],
"bytecode_segment_lengths": [
93
92
],
"hints": [
[
Expand Down
49 changes: 22 additions & 27 deletions cairo0-bootloader/bootloader/contract/execute_entry_point.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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*
) {
Expand Down Expand Up @@ -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,
Expand All @@ -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*));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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() %}
Expand All @@ -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);
}

Expand Down

0 comments on commit a1c2551

Please sign in to comment.