Skip to content

Commit

Permalink
Merge pull request #50 from NethermindEth/ElijahVlasov/different-files
Browse files Browse the repository at this point in the history
Separate starknet-compile and horus-compile outputs
  • Loading branch information
ElijahVlasov authored Jan 24, 2023
2 parents 3cf2a87 + ccdfc09 commit 56ec2cc
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 19 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ pip install git+https://github.com/NethermindEth/horus-compile.git@master
## Usage

```console
horus-compile [-h] [--abi ABI] [--disable_hint_validation]
[--account_contract] [--prime PRIME]
[--cairo_path CAIRO_PATH] [--preprocess]
[--output OUTPUT] [--no_debug_info]
[--cairo_dependencies CAIRO_DEPENDENCIES]
[--no_opt_unused_functions] [-v]
horus-compile [-h] [--abi ABI] [--disable_hint_validation] [--account_contract]
[--spec_output SPEC_OUTPUT] [--prime PRIME] [--cairo_path CAIRO_PATH]
[--preprocess] [--output OUTPUT] [--no_debug_info] [--debug_info_with_source]
[--cairo_dependencies CAIRO_DEPENDENCIES] [--no_opt_unused_functions] [-v]
file [file ...]
```
A tool to compile checked StarkNet contracts.
Expand Down Expand Up @@ -55,6 +53,9 @@ program hints against a whitelist.
Compile as account contract, which means the ABI will
be checked for expected builtin entry points.

`--spec_output SPEC_OUTPUT`
The specification output file name (default: stdout).

`--prime PRIME`

The positive integer size of the finite field. This is
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ skip_gitignore = true

[tool.poetry]
name = "horus-compile"
version = "0.0.6.7"
version = "0.0.6.8"
authors = ["Nethermind <[email protected]>"]
description = "Use formally verified annotations in your Cairo code"
classifiers = [
Expand Down
2 changes: 1 addition & 1 deletion src/horus/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.6.7"
__version__ = "0.0.6.8"
3 changes: 1 addition & 2 deletions src/horus/compiler/contract_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from starkware.cairo.lang.compiler.ast.cairo_types import CairoType
from starkware.cairo.lang.compiler.fields import CairoTypeAsStr
from starkware.cairo.lang.compiler.scoped_name import ScopedName, ScopedNameAsStr
from starkware.starknet.services.api.contract_class import ContractClass

import horus
from horus.compiler.var_names import *
Expand Down Expand Up @@ -100,7 +99,7 @@ class FunctionAnnotations:


@marshmallow_dataclass.dataclass(frozen=True)
class HorusDefinition(ContractClass):
class HorusDefinition:
horus_version: Optional[str] = field(
metadata=dict(marshmallow_field=mfields.String()), default=horus.__version__
)
Expand Down
34 changes: 26 additions & 8 deletions src/horus/compiler/horus_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from starkware.starknet.compiler.starknet_pass_manager import starknet_pass_manager
from starkware.starknet.compiler.storage_var import STORAGE_VAR_DECORATOR
from starkware.starknet.compiler.validation_utils import has_decorator
from starkware.starknet.services.api.contract_class import ContractClass

import horus.compiler.parser
from horus.compiler.code_elements import AnnotatedCodeElement
Expand All @@ -55,17 +56,19 @@

def assemble_horus_contract(
preprocessed_program: HorusProgram, *args, **kwargs
) -> HorusDefinition:
) -> Tuple[ContractClass, HorusDefinition]:
contract_definition = assemble_starknet_contract(
preprocessed_program, *args, **kwargs
)

return HorusDefinition(
**contract_definition.__dict__,
horus_version=horus.__version__,
specifications=preprocessed_program.specifications,
invariants=preprocessed_program.invariants,
storage_vars=preprocessed_program.storage_vars,
return (
contract_definition,
HorusDefinition(
horus_version=horus.__version__,
specifications=preprocessed_program.specifications,
invariants=preprocessed_program.invariants,
storage_vars=preprocessed_program.storage_vars,
),
)


Expand Down Expand Up @@ -210,6 +213,7 @@ def horus_compile_common(
try:
codes = get_codes(args.files)
out = args.output if args.output is not None else sys.stdout
specs_out = args.spec_output if args.spec_output is not None else sys.stdout

cairo_path: List[str] = list(
filter(
Expand Down Expand Up @@ -241,7 +245,7 @@ def horus_compile_common(
for source_file in module_reader.source_files | set(args.files):
file_contents_for_debug_info[source_file] = open(source_file).read()

assembled_program = assemble_func(
assembled_program, specs = assemble_func(
preprocessed,
main_scope=MAIN_SCOPE,
add_debug_info=debug_info,
Expand All @@ -257,6 +261,15 @@ def horus_compile_common(
# Print a new line at the end.
print(file=out)

json.dump(
specs.Schema().dump(specs),
specs_out,
indent=4,
sort_keys=True,
)
# Print a new line at the end.
print(file=specs_out)

return preprocessed
finally:
if args.cairo_dependencies:
Expand Down Expand Up @@ -351,6 +364,11 @@ def main(args):
action="store_true",
help="Compile as account contract, which means the ABI will be checked for expected builtin entry points.",
)
parser.add_argument(
"--spec_output",
type=argparse.FileType("w"),
help="The specification output file name (default: stdout).",
)

def pass_manager_factory(
args: argparse.Namespace, module_reader: ModuleReader
Expand Down
2 changes: 1 addition & 1 deletion tests/test_compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def test_golden(capsys):
def run_horus_compile(file):
main([file, "--cairo_path", "./tests/golden"])
main([file, "--cairo_path", "./tests/golden", "--output", "/dev/null"])
out = capsys.readouterr().out
program_json = json.loads(out)
with StringIO() as checks_out:
Expand Down

0 comments on commit 56ec2cc

Please sign in to comment.