Skip to content

Commit

Permalink
Cairo v0.13.4a0 (pre).
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoni-Starkware committed Jan 26, 2025
1 parent 8e11b8c commit 6caf256
Show file tree
Hide file tree
Showing 156 changed files with 6,969 additions and 6,709 deletions.
16 changes: 11 additions & 5 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
load("vars.bzl", "ADDITIONAL_IMPORTS")

exports_files([
".clang-format",
"package.json",
"yarn_ganache.lock",
] + glob(["*.py"]))
exports_files(
[
".clang-format",
"package.json",
"yarn_ganache.lock",
] + glob(
[
"*.py",
],
),
)

# The 'starkware' library adds 'src' to PYTHONPATH.
# The library on its own does not add any dependencies.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ We recommend starting from [Setting up the environment](https://cairo-lang.org/d
# Installation instructions

You should be able to download the python package zip file directly from
[github](https://github.com/starkware-libs/cairo-lang/releases/tag/v0.13.3)
[github](https://github.com/starkware-libs/cairo-lang/releases/tag/v0.13.4)
and install it using ``pip``.
See [Setting up the environment](https://cairo-lang.org/docs/quickstart.html).

Expand Down Expand Up @@ -54,7 +54,7 @@ Once the docker image is built, you can fetch the python package zip file using:

```bash
> container_id=$(docker create cairo)
> docker cp ${container_id}:/app/cairo-lang-0.13.3.zip .
> docker cp ${container_id}:/app/cairo-lang-0.13.4.zip .
> docker rm -v ${container_id}
```

2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ http_archive(
"//src/starkware/starknet/compiler/v1:BUILD." + CAIRO_COMPILER_ARCHIVE,
),
strip_prefix = "cairo",
url = "https://github.com/starkware-libs/cairo/releases/download/v2.7.0/release-x86_64-unknown-linux-musl.tar.gz",
url = "https://github.com/starkware-libs/cairo/releases/download/v2.10.0-rc.0/release-x86_64-unknown-linux-musl.tar.gz",
)

http_archive(
Expand Down
5 changes: 4 additions & 1 deletion bazel_utils/python/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
load("@rules_python//python:defs.bzl", "py_runtime", "py_runtime_pair")
load(":defs.bzl", "python_version_info")
load(
":defs.bzl",
"python_version_info",
)

python_version_info(
name = "python_version",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
%builtins output pedersen range_check ecdsa bitwise ec_op keccak poseidon range_check96 add_mod mul_mod

from starkware.cairo.bootloaders.bootloader.constants import BOOTLOADER_CONFIG_SIZE
from starkware.cairo.bootloaders.bootloader.run_bootloader import run_bootloader
from starkware.cairo.bootloaders.simple_bootloader.run_simple_bootloader import (
run_simple_bootloader,
verify_non_negative,
)
from starkware.cairo.common.cairo_builtins import HashBuiltin, PoseidonBuiltin
from starkware.cairo.common.hash import hash2
from starkware.cairo.common.memcpy import memcpy
from starkware.cairo.common.registers import get_fp_and_pc

const AGGREGATOR_CONSTANT = 'AGGREGATOR';

// Runs the simple bootloader on the aggregator task, the unpacker bootloader on the other tasks,
// compares the input of the aggregator task with the output of the other tasks, and outputs the
// aggregated output produced by running the aggregator task.
//
// Hint arguments:
// program_input - Contains the tasks to execute (including the aggregator task), and the packed
// outputs. Formatted as an ApplicativeBootloaderInput object.

// Returns (written to output_ptr):
// - The modified aggregator program hash (the aggregator program hash, hashed with the word
// "AGGREGATOR").
// - The bootloader config.
// - The aggregated output.
func main{
output_ptr: felt*,
pedersen_ptr: HashBuiltin*,
Expand Down Expand Up @@ -41,11 +53,11 @@ func main{

# Load the applicative bootloader input and the aggregator task.
applicative_bootloader_input = ApplicativeBootloaderInput.Schema().load(program_input)
aggregator_task = applicative_bootloader_input.aggregator_task.load_task()
aggregator_task = applicative_bootloader_input.aggregator_task

# Create the simple bootloader input.
simple_bootloader_input = SimpleBootloaderInput(
tasks=[aggregator_task], fact_topologies_path=None, single_page=False
tasks=[aggregator_task], fact_topologies_path=None, single_page=True
)

# Change output builtin state to a different segment in preparation for running the
Expand Down Expand Up @@ -120,21 +132,20 @@ func main{

// Output:
// * The aggregator program hash, hashed with the word "AGGREGATOR".
// * The bootloader config: the simple bootloader hash and the hash of the list of the Cairo
// verifiers.
// * The bootloader config.
local output_start: felt* = output_ptr;
let (modified_aggregator_program_hash) = hash2{hash_ptr=pedersen_ptr}(
AGGREGATOR_CONSTANT, aggregator_program_hash
);
local pedersen_ptr: HashBuiltin* = pedersen_ptr;
assert output_ptr[0] = modified_aggregator_program_hash;
let output_ptr = &output_ptr[1];
// Copy the bootloader config.
assert output_ptr[1] = bootloader_output_start[0];
assert output_ptr[2] = bootloader_output_start[1];
let output_ptr = &output_ptr[3];
let output_start = output_ptr;
memcpy(dst=output_ptr, src=bootloader_output_start, len=BOOTLOADER_CONFIG_SIZE);
let output_ptr = &output_ptr[BOOTLOADER_CONFIG_SIZE];

// Assert that the bootloader output agrees with the aggregator input.
let bootloader_tasks_output_ptr = &bootloader_output_start[2];
let bootloader_tasks_output_ptr = &bootloader_output_start[BOOTLOADER_CONFIG_SIZE];
let bootloader_tasks_output_length = bootloader_output_end - bootloader_tasks_output_ptr;
memcpy(
dst=aggregator_input_ptr,
Expand All @@ -149,28 +160,39 @@ func main{
let output_ptr = output_ptr + aggregated_output_length;

%{
from starkware.cairo.bootloaders.fact_topology import FactTopology
from starkware.cairo.bootloaders.fact_topology import GPS_FACT_TOPOLOGY, FactTopology
from starkware.cairo.bootloaders.simple_bootloader.utils import (
configure_fact_topologies,
add_consecutive_output_pages,
write_to_fact_topologies_file,
)

assert len(aggregator_fact_topologies) == 1
# Subtract the bootloader output length from the first page's length. Note that the
# bootloader output is always fully contained in the first page.
original_first_page_length = aggregator_fact_topologies[0].page_sizes[0]
first_page_length = original_first_page_length - ids.bootloader_tasks_output_length
# The header contains the program hash and bootloader config.
header_size = 1 + ids.BOOTLOADER_CONFIG_SIZE
first_page_length = (
original_first_page_length - ids.bootloader_tasks_output_length + header_size
)

# Update the first page's length to account for the bootloader output.
# Update the first page's length to account for the removed bootloader output, and the
# added program hash and bootloader config.
fact_topology = FactTopology(
tree_structure=aggregator_fact_topologies[0].tree_structure,
page_sizes=[first_page_length] + aggregator_fact_topologies[0].page_sizes[1:]
)
output_builtin.add_attribute(
attribute_name=GPS_FACT_TOPOLOGY,
attribute_value=aggregator_fact_topologies[0].tree_structure
)

# Configure the memory pages in the output builtin, based on plain_fact_topologies.
configure_fact_topologies(
fact_topologies=[fact_topology], output_start=ids.output_start,
add_consecutive_output_pages(
page_sizes=fact_topology.page_sizes[1:],
output_builtin=output_builtin,
cur_page_id=1,
output_start=ids.output_start + fact_topology.page_sizes[0],
)

# Dump fact topologies to a json file.
Expand Down
1 change: 1 addition & 0 deletions src/starkware/cairo/bootloaders/bootloader/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("//src/starkware/cairo/lang:cairo_rules.bzl", "cairo_binary", "cairo_librar
cairo_library(
name = "run_bootloader_lib",
srcs = [
"constants.cairo",
"run_bootloader.cairo",
"//src/starkware/cairo/bootloaders/simple_bootloader:execute_task.cairo",
"//src/starkware/cairo/bootloaders/simple_bootloader:run_simple_bootloader.cairo",
Expand Down
5 changes: 2 additions & 3 deletions src/starkware/cairo/bootloaders/bootloader/bootloader.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ from starkware.cairo.bootloaders.bootloader.run_bootloader import run_bootloader
from starkware.cairo.common.cairo_builtins import HashBuiltin, PoseidonBuiltin
from starkware.cairo.common.registers import get_fp_and_pc

// Runs the simple bootloader on tasks and unpacks them to the output.
//
// For documentation of the unpacker bootloader, see the docstring of `run_bootloader`.
// Hint arguments:
// program_input - Contains the inputs for the bootloader.
// program_input - Contains the tasks to execute. Formatted as a BootloaderInput object.
func main{
output_ptr: felt*,
pedersen_ptr: HashBuiltin*,
Expand Down
1 change: 1 addition & 0 deletions src/starkware/cairo/bootloaders/bootloader/constants.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const BOOTLOADER_CONFIG_SIZE = 3;
Loading

0 comments on commit 6caf256

Please sign in to comment.