forked from starkware-libs/cairo-lang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bootloader for recusive with poseidon
- Loading branch information
1 parent
45bd7de
commit 3d6476c
Showing
6 changed files
with
393 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/starkware/cairo/bootloaders/simple_bootloader/objects.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import dataclasses | ||
from abc import abstractmethod | ||
from dataclasses import field | ||
from typing import ClassVar, Dict, List, Optional, Type | ||
import marshmallow | ||
import marshmallow.fields as mfields | ||
import marshmallow_dataclass | ||
from marshmallow_oneofschema import OneOfSchema | ||
from starkware.cairo.lang.compiler.program import Program, ProgramBase, StrippedProgram | ||
from starkware.cairo.lang.vm.cairo_pie import CairoPie | ||
from starkware.starkware_utils.marshmallow_dataclass_fields import additional_metadata | ||
from starkware.starkware_utils.validated_dataclass import ValidatedMarshmallowDataclass | ||
|
||
|
||
class Task: | ||
@abstractmethod | ||
def get_program(self) -> ProgramBase: | ||
""" | ||
Returns the task's Cairo program. | ||
""" | ||
|
||
|
||
class TaskSpec: | ||
""" | ||
Contains task's specification. | ||
""" | ||
|
||
@abstractmethod | ||
def load_task(self, memory=None, args_start=None, args_len=None) -> "Task": | ||
""" | ||
Returns the corresponding task. | ||
""" | ||
|
||
|
||
@marshmallow_dataclass.dataclass(frozen=True) | ||
class RunProgramTask(TaskSpec, Task): | ||
TYPE: ClassVar[str] = "RunProgramTask" | ||
program: Program | ||
program_input: dict | ||
use_poseidon: bool | ||
|
||
def get_program(self) -> Program: | ||
return self.program | ||
|
||
def load_task(self, memory=None, args_start=None, args_len=None) -> "Task": | ||
return self | ||
|
||
|
||
@marshmallow_dataclass.dataclass(frozen=True) | ||
class CairoPiePath(TaskSpec): | ||
TYPE: ClassVar[str] = "CairoPiePath" | ||
path: str | ||
use_poseidon: bool | ||
|
||
def load_task(self, memory=None, args_start=None, args_len=None) -> "CairoPieTask": | ||
""" | ||
Loads the PIE to memory. | ||
""" | ||
return CairoPieTask( | ||
cairo_pie=CairoPie.from_file(self.path), use_poseidon=self.use_poseidon | ||
) | ||
|
||
|
||
class TaskSchema(OneOfSchema): | ||
""" | ||
Schema for Task/CairoPiePath/Cairo1ProgramPath/CairoSierra | ||
OneOfSchema adds a "type" field. | ||
""" | ||
|
||
type_schemas: Dict[str, Type[marshmallow.Schema]] = { | ||
RunProgramTask.TYPE: RunProgramTask.Schema, | ||
CairoPiePath.TYPE: CairoPiePath.Schema, | ||
} | ||
|
||
def get_obj_type(self, obj): | ||
return obj.TYPE | ||
|
||
|
||
@dataclasses.dataclass(frozen=True) | ||
class CairoPieTask(Task): | ||
cairo_pie: CairoPie | ||
use_poseidon: bool | ||
|
||
def get_program(self) -> StrippedProgram: | ||
return self.cairo_pie.program | ||
|
||
|
||
@marshmallow_dataclass.dataclass(frozen=True) | ||
class SimpleBootloaderInput(ValidatedMarshmallowDataclass): | ||
tasks: List[TaskSpec] = field( | ||
metadata=additional_metadata( | ||
marshmallow_field=mfields.List(mfields.Nested(TaskSchema)) | ||
) | ||
) | ||
fact_topologies_path: Optional[str] | ||
|
||
# If true, the bootloader will put all the outputs in a single page, ignoring the | ||
# tasks' fact topologies. | ||
single_page: bool |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.