Skip to content

Commit

Permalink
input structurized
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Apr 22, 2024
1 parent 84379fa commit ee2ea49
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 35 deletions.
2 changes: 1 addition & 1 deletion cairo0-bootloader/bootloader/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def load_task(self, memory=None, args_start=None, args_len=None) -> "CairoPieTas
with tempfile.NamedTemporaryFile() as cairo_pie_file:
cairo_pie_file_path = cairo_pie_file.name

args = [memory[args_start + i + 1] for i in range(args_len)]
args = [memory[args_start.address_ + i] for i in range(args_len)]
formatted_args = f'[{" ".join(map(str, args))}]'

subprocess.run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ func verify_non_negative(num: felt, n_bits: felt) {
return verify_non_negative(num=num_div2, n_bits=n_bits - 1);
}

struct Input {
a: felt,
b: felt,
c: felt,
}

struct Output {
a_2: felt,
b_2: felt,
Expand Down Expand Up @@ -146,20 +152,20 @@ func execute_tasks{builtin_ptrs: BuiltinData*, self_range_check_ptr}(
return ();
}

local args: felt*;
%{ ids.args = segments.add() %}
let args_start = args;
assert [args_start + 1] = 3;
assert [args_start + 2] = 4;
assert [args_start + 3] = 5;
local input_size = Input.SIZE;
local input: Input = Input(
a=3,
b=4,
c=5,
);

%{
from bootloader.objects import Task

# Pass current task to execute_task.
task_id = len(simple_bootloader_input.tasks) - ids.n_tasks
task = simple_bootloader_input.tasks[task_id].load_task(
memory=memory, args_start=ids.args_start, args_len=3
memory=memory, args_start=ids.input, args_len=ids.input_size
)
%}
tempvar use_poseidon = nondet %{ 1 if task.use_poseidon else 0 %};
Expand Down
10 changes: 7 additions & 3 deletions compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
if __name__ == "__main__":
current_dir = os.getcwd()

log_and_run([
f"cairo-compile --cairo_path=. bootloader/recursive_with_poseidon/simple_bootloader.cairo --output {current_dir}/bootloader.json --proof_mode",
], "Compile bootloader program", cwd="cairo0-bootloader")
log_and_run(
[
f"cairo-compile --cairo_path=. bootloader/recursive_with_poseidon/simple_bootloader.cairo --output {current_dir}/bootloader.json --proof_mode",
],
"Compile bootloader program",
cwd="cairo0-bootloader",
)
54 changes: 36 additions & 18 deletions install.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,50 @@
import subprocess
from colorama import Fore, Style


def log_and_run(commands, description, cwd=None):
full_command = " && ".join(commands)
try:
print(f"{Fore.YELLOW}Starting: {description}...{Style.RESET_ALL}")
print(f"{Fore.CYAN}Command: {full_command}{Style.RESET_ALL}")
result = subprocess.run(full_command, shell=True, check=True, cwd=cwd, text=True)
result = subprocess.run(
full_command, shell=True, check=True, cwd=cwd, text=True
)
print(f"{Fore.GREEN}Success: {description} completed!\n{Style.RESET_ALL}")
except subprocess.CalledProcessError as e:
print(f"{Fore.RED}Error running command '{full_command}': {e}\n{Style.RESET_ALL}")
print(
f"{Fore.RED}Error running command '{full_command}': {e}\n{Style.RESET_ALL}"
)


if __name__ == "__main__":
log_and_run([
"pip install cairo-lang==0.13.1",
"pip install aiofiles",
"pip install cairo0-bootloader/"
], "Installing cairo-lang", cwd=".")
log_and_run(
[
"pip install cairo-lang==0.13.1",
"pip install aiofiles",
"pip install cairo0-bootloader/",
],
"Installing cairo-lang",
cwd=".",
)

log_and_run([
"git clone https://github.com/starkware-libs/cairo.git",
"cd cairo",
"git checkout v2.6.3",
"cd ..",
"mv cairo/corelib/ .",
"rm -rf cairo/",
], "Clone corelib", cwd=".")
log_and_run(
[
"git clone https://github.com/starkware-libs/cairo.git",
"cd cairo",
"git checkout v2.6.3",
"cd ..",
"mv cairo/corelib/ .",
"rm -rf cairo/",
],
"Clone corelib",
cwd=".",
)

log_and_run([
"cargo install --path .",
], "Install cairo-vm", cwd="cairo-vm/cairo1-run")
log_and_run(
[
"cargo install --path .",
],
"Install cairo-vm",
cwd="cairo-vm/cairo1-run",
)
13 changes: 7 additions & 6 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from install import log_and_run

if __name__ == "__main__":
log_and_run([
"cairo-run \
log_and_run(
[
"cairo-run \
--program=bootloader.json \
--layout=recursive_with_poseidon \
--program_input=bootloader_input.json \
Expand All @@ -13,7 +14,7 @@
--print_output \
--proof_mode \
--print_info"
], "Running cairo1 pie in cairo0 bootloader", cwd=".")

# cargo run ../../cairo1.cairo --layout recursive_large_output --trace_file cairo1/program.trace --memory_file cairo1/program.memory --air_public_input cairo1/air_public_input.json --air_private_input cairo1/air_private_input.json --proof_mode
# cargo run ../../cairo1.cairo --layout recursive_large_output --print_output
],
"Running cairo1 pie in cairo0 bootloader",
cwd=".",
)

0 comments on commit ee2ea49

Please sign in to comment.