├── ICO ├── src │ ├── lib.cairo │ └── IERC20.cairo ├── .DS_Store ├── target │ └── CACHEDIR.TAG └── Scarb.toml ├── cairo1.0 ├── clippy.toml ├── .gitignore ├── corelib │ ├── cairo_project.toml │ ├── internal.cairo │ ├── box.cairo │ ├── debug.cairo │ ├── nullable.cairo │ └── gas.cairo ├── crates │ ├── cairo-lang-parser │ │ ├── test_data │ │ │ ├── cairo_files │ │ │ │ ├── .cairofmtignore │ │ │ │ ├── short.cairo │ │ │ │ ├── colored.cairo │ │ │ │ ├── test2.cairo │ │ │ │ └── test1.cairo │ │ │ ├── test_items │ │ │ └── expected_results │ │ │ │ ├── colored │ │ │ │ └── colored_verbose │ │ ├── src │ │ │ ├── lib.rs │ │ │ └── parser_test_data │ │ │ │ ├── question_mark │ │ │ │ ├── fn │ │ │ │ ├── exprs │ │ │ │ ├── pattern │ │ │ │ ├── not_isnt_a_binary_operator │ │ │ │ ├── literal │ │ │ │ ├── semicolon │ │ │ │ ├── if │ │ │ │ └── module_diagnostics │ │ └── Cargo.toml │ ├── cairo-lang-formatter │ │ ├── test_data │ │ │ ├── cairo_files │ │ │ │ ├── .cairofmtignore │ │ │ │ ├── test1.cairo │ │ │ │ └── linebreaking.cairo │ │ │ └── expected_results │ │ │ │ └── test1.cairo │ │ └── Cargo.toml │ ├── cairo-lang-starknet │ │ ├── cairo_level_tests │ │ │ └── cairo_project.toml │ │ ├── test_data │ │ │ ├── hello_starknet.cairo │ │ │ └── test_contract.cairo │ │ └── src │ │ │ ├── lib.rs │ │ │ ├── test_utils.rs │ │ │ ├── felt_serde_test.rs │ │ │ ├── casm_contract_class_test.rs │ │ │ ├── db.rs │ │ │ └── cli.rs │ ├── cairo-lang-semantic │ │ └── src │ │ │ ├── items │ │ │ ├── constant_test.rs │ │ │ ├── tests │ │ │ │ ├── struct │ │ │ │ ├── enum │ │ │ │ ├── extern_func │ │ │ │ ├── free_function │ │ │ │ ├── panicable │ │ │ │ └── module │ │ │ ├── mod.rs │ │ │ ├── test.rs │ │ │ ├── extern_type_test.rs │ │ │ ├── extern_function_test.rs │ │ │ └── generics.rs │ │ │ ├── expr │ │ │ ├── mod.rs │ │ │ ├── fmt.rs │ │ │ └── test_data │ │ │ │ ├── literal │ │ │ │ ├── if │ │ │ │ ├── return │ │ │ │ └── assignment │ │ │ ├── lib.rs │ │ │ ├── literals.rs │ │ │ └── diagnostic_test_data │ │ │ └── not_found │ ├── cairo-lang-sierra │ │ ├── src │ │ │ ├── build.rs │ │ │ ├── extensions │ │ │ │ ├── modules │ │ │ │ │ ├── range_check.rs │ │ │ │ │ ├── starknet │ │ │ │ │ │ └── syscalls.rs │ │ │ │ │ ├── branch_align.rs │ │ │ │ │ ├── ap_tracking.rs │ │ │ │ │ ├── unconditional_jump.rs │ │ │ │ │ ├── uninitialized.rs │ │ │ │ │ └── dict_manager.rs │ │ │ │ ├── type_specialization_context.rs │ │ │ │ └── mod.rs │ │ │ ├── simulation │ │ │ │ └── value.rs │ │ │ ├── edit_state_test.rs │ │ │ └── lib.rs │ │ ├── Cargo.toml │ │ └── examples │ │ │ └── fib_no_gas.sierra │ ├── cairo-lang-syntax │ │ ├── src │ │ │ ├── lib.rs │ │ │ └── node │ │ │ │ ├── test_utils.rs │ │ │ │ ├── db.rs │ │ │ │ ├── ids.rs │ │ │ │ ├── element_list.rs │ │ │ │ ├── green.rs │ │ │ │ └── utils.rs │ │ └── Cargo.toml │ ├── cairo-lang-filesystem │ │ ├── src │ │ │ ├── lib.rs │ │ │ ├── test_utils.rs │ │ │ ├── db_test.rs │ │ │ └── detect.rs │ │ └── Cargo.toml │ ├── cairo-lang-debug │ │ ├── src │ │ │ └── lib.rs │ │ └── Cargo.toml │ ├── cairo-lang-syntax-codegen │ │ ├── src │ │ │ ├── lib.rs │ │ │ ├── generate_syntax.rs │ │ │ └── golden_test.rs │ │ └── Cargo.toml │ ├── cairo-lang-utils │ │ ├── src │ │ │ ├── casts.rs │ │ │ ├── collection_arithmetics_test.rs │ │ │ └── logging.rs │ │ └── Cargo.toml │ ├── cairo-lang-casm │ │ ├── src │ │ │ ├── lib.rs │ │ │ ├── operand_test.rs │ │ │ └── ap_change_test.rs │ │ └── Cargo.toml │ ├── cairo-lang-defs │ │ ├── src │ │ │ ├── lib.rs │ │ │ └── test_data │ │ │ │ └── generic_item_id │ │ └── Cargo.toml │ ├── cairo-lang-plugins │ │ └── src │ │ │ ├── test_data │ │ │ └── config │ │ │ └── lib.rs │ ├── cairo-lang-sierra-generator │ │ └── src │ │ │ ├── function_generator_test.rs │ │ │ ├── id_allocator.rs │ │ │ ├── lib.rs │ │ │ ├── block_generator_test_data │ │ │ ├── early_return │ │ │ └── literals │ │ │ ├── local_variables_test_data │ │ │ ├── construct_enum │ │ │ └── block │ │ │ ├── function_generator_test_data │ │ │ ├── simple │ │ │ └── match │ │ │ └── lifetime_test_data │ │ │ ├── block │ │ │ └── simple │ ├── cairo-lang-test-utils │ │ ├── test_data │ │ │ └── test_example │ │ ├── Cargo.toml │ │ └── src │ │ │ ├── lib.rs │ │ │ └── parse_test_file_test.rs │ ├── cairo-lang-diagnostics │ │ ├── src │ │ │ └── lib.rs │ │ └── Cargo.toml │ ├── cairo-lang-lowering │ │ └── src │ │ │ ├── lib.rs │ │ │ └── test_data │ │ │ ├── constant │ │ │ ├── rebindings │ │ │ ├── enums │ │ │ └── tuple │ ├── cairo-lang-sierra-to-casm │ │ ├── src │ │ │ ├── lib.rs │ │ │ ├── environment │ │ │ │ └── ap_tracking.rs │ │ │ ├── invocations │ │ │ │ ├── pedersen_test.rs │ │ │ │ └── bitwise_test.rs │ │ │ └── cli.rs │ │ └── Cargo.toml │ ├── cairo-lang-proc-macros │ │ └── Cargo.toml │ ├── cairo-lang-project │ │ ├── src │ │ │ └── test.rs │ │ └── Cargo.toml │ ├── cairo-lang-runner │ │ └── src │ │ │ └── short_string.rs │ ├── cairo-lang-sierra-ap-change │ │ ├── src │ │ │ └── ap_change_info.rs │ │ └── Cargo.toml │ ├── cairo-lang-compiler │ │ └── src │ │ │ └── diagnostics_test.rs │ ├── cairo-lang-eq-solver │ │ ├── Cargo.toml │ │ └── src │ │ │ └── expr_test.rs │ ├── cairo-lang-test-runner │ │ └── README.md │ ├── cairo-lang-sierra-gas │ │ ├── src │ │ │ ├── test_data │ │ │ │ └── fib_jumps │ │ │ └── cost_expr.rs │ │ └── Cargo.toml │ └── cairo-lang-language-server │ │ └── src │ │ ├── vfs.rs │ │ ├── bin │ │ └── language_server.rs │ │ └── semantic_highlighting │ │ └── encoder.rs ├── vscode-cairo │ ├── .vscodeignore │ ├── .gitignore │ ├── language-configuration.json │ ├── tsconfig.json │ └── README.md ├── scripts │ ├── rust_fmt.sh │ ├── cairo_fmt.sh │ ├── cairo_test.sh │ ├── docs.sh │ ├── starknet_test.sh │ ├── clippy.sh │ └── release_tar.sh ├── package-lock.json ├── .github │ ├── ISSUE_TEMPLATE │ │ ├── config.yml │ │ ├── 03_CODEBASE_IMPROVEMENT.md │ │ ├── 01_BUG_REPORT.md │ │ └── 02_FEATURE_REQUEST.md │ └── workflows │ │ └── artifacts.yml ├── src │ └── hello.cairo ├── examples │ ├── traits_impl │ │ └── traits_impl.cairo │ └── ens │ │ └── ens.cairo └── rustfmt.toml ├── ERC20 ├── src │ └── lib.cairo ├── .DS_Store ├── target │ └── CACHEDIR.TAG └── Scarb.toml ├── ERC20_0.x ├── lib │ ├── cairo_contracts │ │ ├── MANIFEST.in │ │ ├── .gitattributes │ │ ├── netlify.toml │ │ ├── .DS_Store │ │ ├── src │ │ │ ├── .DS_Store │ │ │ └── openzeppelin │ │ │ │ ├── introspection │ │ │ │ └── erc165 │ │ │ │ │ └── IERC165.cairo │ │ │ │ ├── __init__.py │ │ │ │ ├── token │ │ │ │ ├── erc721 │ │ │ │ │ ├── IERC721Receiver.cairo │ │ │ │ │ ├── IERC721Metadata.cairo │ │ │ │ │ ├── enumerable │ │ │ │ │ │ ├── IERC721Enumerable.cairo │ │ │ │ │ │ └── presets │ │ │ │ │ │ │ └── utils │ │ │ │ │ │ │ └── ERC721Holder.cairo │ │ │ │ │ └── IERC721.cairo │ │ │ │ └── erc20 │ │ │ │ │ └── IERC20.cairo │ │ │ │ ├── access │ │ │ │ └── accesscontrol │ │ │ │ │ └── IAccessControl.cairo │ │ │ │ ├── utils │ │ │ │ └── constants │ │ │ │ │ └── library.cairo │ │ │ │ ├── account │ │ │ │ ├── presets │ │ │ │ │ └── AddressRegistry.cairo │ │ │ │ └── IAccount.cairo │ │ │ │ └── security │ │ │ │ ├── reentrancyguard │ │ │ │ └── library.cairo │ │ │ │ └── initializable │ │ │ │ └── library.cairo │ │ ├── docs │ │ │ ├── antora.yml │ │ │ ├── package.json │ │ │ └── modules │ │ │ │ └── ROOT │ │ │ │ ├── nav.adoc │ │ │ │ └── pages │ │ │ │ └── wizard.adoc │ │ ├── tests │ │ │ ├── conftest.py │ │ │ ├── mocks │ │ │ │ ├── Initializable.cairo │ │ │ │ ├── ReentrancyAttackerMock.cairo │ │ │ │ ├── ERC165.cairo │ │ │ │ ├── Ownable.cairo │ │ │ │ ├── AccountReentrancy.cairo │ │ │ │ └── SafeMathMock.cairo │ │ │ └── security │ │ │ │ └── test_initializable.py │ │ ├── SECURITY.md │ │ ├── pyproject.toml │ │ ├── .github │ │ │ └── ISSUE_TEMPLATE │ │ │ │ ├── feature_request.md │ │ │ │ └── bug_report.md │ │ ├── .markdownlintrc │ │ ├── setup.py │ │ ├── PULL_REQUEST_TEMPLATE.md │ │ ├── scripts │ │ │ └── update_version.py │ │ ├── setup.cfg │ │ ├── LICENSE │ │ └── RELEASING.md │ └── .DS_Store ├── .DS_Store ├── protostar.toml └── tests │ └── test_main.cairo ├── ERC721_0.x ├── lib │ ├── cairo_contracts │ │ ├── MANIFEST.in │ │ ├── .gitattributes │ │ ├── netlify.toml │ │ ├── .DS_Store │ │ ├── src │ │ │ ├── .DS_Store │ │ │ └── openzeppelin │ │ │ │ ├── introspection │ │ │ │ └── erc165 │ │ │ │ │ └── IERC165.cairo │ │ │ │ ├── __init__.py │ │ │ │ ├── token │ │ │ │ ├── erc721 │ │ │ │ │ ├── IERC721Receiver.cairo │ │ │ │ │ ├── IERC721Metadata.cairo │ │ │ │ │ ├── enumerable │ │ │ │ │ │ ├── IERC721Enumerable.cairo │ │ │ │ │ │ └── presets │ │ │ │ │ │ │ └── utils │ │ │ │ │ │ │ └── ERC721Holder.cairo │ │ │ │ │ └── IERC721.cairo │ │ │ │ └── erc20 │ │ │ │ │ └── IERC20.cairo │ │ │ │ ├── access │ │ │ │ └── accesscontrol │ │ │ │ │ └── IAccessControl.cairo │ │ │ │ ├── utils │ │ │ │ └── constants │ │ │ │ │ └── library.cairo │ │ │ │ ├── account │ │ │ │ ├── presets │ │ │ │ │ └── AddressRegistry.cairo │ │ │ │ └── IAccount.cairo │ │ │ │ └── security │ │ │ │ ├── reentrancyguard │ │ │ │ └── library.cairo │ │ │ │ └── initializable │ │ │ │ └── library.cairo │ │ ├── docs │ │ │ ├── antora.yml │ │ │ ├── package.json │ │ │ └── modules │ │ │ │ └── ROOT │ │ │ │ ├── nav.adoc │ │ │ │ └── pages │ │ │ │ └── wizard.adoc │ │ ├── tests │ │ │ ├── conftest.py │ │ │ ├── mocks │ │ │ │ ├── Initializable.cairo │ │ │ │ ├── ReentrancyAttackerMock.cairo │ │ │ │ ├── ERC165.cairo │ │ │ │ ├── Ownable.cairo │ │ │ │ └── AccountReentrancy.cairo │ │ │ └── security │ │ │ │ └── test_initializable.py │ │ ├── SECURITY.md │ │ ├── pyproject.toml │ │ ├── .github │ │ │ └── ISSUE_TEMPLATE │ │ │ │ ├── feature_request.md │ │ │ │ └── bug_report.md │ │ ├── .markdownlintrc │ │ ├── setup.py │ │ ├── PULL_REQUEST_TEMPLATE.md │ │ ├── scripts │ │ │ └── update_version.py │ │ ├── setup.cfg │ │ ├── LICENSE │ │ └── RELEASING.md │ └── .DS_Store ├── .DS_Store ├── protostar.toml └── tests │ └── test_main.cairo ├── .DS_Store ├── ICO_0.x ├── protostar.toml ├── src │ └── IERC20.cairo ├── tests │ └── test_main.cairo └── build │ └── ico_abi.json └── Readme.md /ICO/src/lib.cairo: -------------------------------------------------------------------------------- 1 | mod ERC20; 2 | mod IERC20; 3 | mod ICO; -------------------------------------------------------------------------------- /cairo1.0/clippy.toml: -------------------------------------------------------------------------------- 1 | enum-variant-name-threshold = 1 2 | -------------------------------------------------------------------------------- /ERC20/src/lib.cairo: -------------------------------------------------------------------------------- 1 | mod ERC20; 2 | use ERC20::ERC20Contract; -------------------------------------------------------------------------------- /cairo1.0/.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .vscode/ 3 | .idea/ 4 | .spr.yml 5 | -------------------------------------------------------------------------------- /cairo1.0/corelib/cairo_project.toml: -------------------------------------------------------------------------------- 1 | [crate_roots] 2 | core = "." 3 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-parser/test_data/cairo_files/.cairofmtignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /cairo1.0/vscode-cairo/.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/MANIFEST.in: -------------------------------------------------------------------------------- 1 | recursive-include src/ *.cairo 2 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/MANIFEST.in: -------------------------------------------------------------------------------- 1 | recursive-include src/ *.cairo 2 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-formatter/test_data/cairo_files/.cairofmtignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/argentlabs/starknet-build/HEAD/.DS_Store -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/.gitattributes: -------------------------------------------------------------------------------- 1 | *.cairo linguist-language=python 2 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/.gitattributes: -------------------------------------------------------------------------------- 1 | *.cairo linguist-language=python 2 | -------------------------------------------------------------------------------- /ICO/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/argentlabs/starknet-build/HEAD/ICO/.DS_Store -------------------------------------------------------------------------------- /cairo1.0/corelib/internal.cairo: -------------------------------------------------------------------------------- 1 | extern fn revoke_ap_tracking() implicits() nopanic; 2 | -------------------------------------------------------------------------------- /ERC20/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/argentlabs/starknet-build/HEAD/ERC20/.DS_Store -------------------------------------------------------------------------------- /cairo1.0/scripts/rust_fmt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cargo +nightly-2022-11-03 fmt --all -- "$@" 4 | -------------------------------------------------------------------------------- /cairo1.0/vscode-cairo/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /out 3 | /package-lock.json 4 | /*.vsix 5 | -------------------------------------------------------------------------------- /ERC20_0.x/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/argentlabs/starknet-build/HEAD/ERC20_0.x/.DS_Store -------------------------------------------------------------------------------- /ERC721_0.x/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/argentlabs/starknet-build/HEAD/ERC721_0.x/.DS_Store -------------------------------------------------------------------------------- /ERC20_0.x/lib/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/argentlabs/starknet-build/HEAD/ERC20_0.x/lib/.DS_Store -------------------------------------------------------------------------------- /ERC721_0.x/lib/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/argentlabs/starknet-build/HEAD/ERC721_0.x/lib/.DS_Store -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-starknet/cairo_level_tests/cairo_project.toml: -------------------------------------------------------------------------------- 1 | [crate_roots] 2 | cairo_level_tests = "." 3 | -------------------------------------------------------------------------------- /cairo1.0/scripts/cairo_fmt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cargo +nightly-2022-11-03 run --bin cairo-format -- --recursive "$@" 4 | -------------------------------------------------------------------------------- /cairo1.0/scripts/cairo_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cargo +nightly-2022-11-03 run --bin cairo-test -- --path corelib/ 4 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-semantic/src/items/constant_test.rs: -------------------------------------------------------------------------------- 1 | // TODO(lior): Add semantic tests for constant definitions. 2 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | base = "docs/" 3 | command = "npm run docs" 4 | publish = "build/site" 5 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | base = "docs/" 3 | command = "npm run docs" 4 | publish = "build/site" 5 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-sierra/src/build.rs: -------------------------------------------------------------------------------- 1 | use lalrpop::process_root; 2 | 3 | fn main() { 4 | process_root().unwrap(); 5 | } 6 | -------------------------------------------------------------------------------- /cairo1.0/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cairo1.0", 3 | "lockfileVersion": 2, 4 | "requires": true, 5 | "packages": {} 6 | } 7 | -------------------------------------------------------------------------------- /cairo1.0/scripts/docs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | RUSTDOCFLAGS="-Dwarnings" cargo doc --document-private-items --no-deps --all-features 4 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/argentlabs/starknet-build/HEAD/ERC20_0.x/lib/cairo_contracts/.DS_Store -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/argentlabs/starknet-build/HEAD/ERC721_0.x/lib/cairo_contracts/.DS_Store -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/argentlabs/starknet-build/HEAD/ERC20_0.x/lib/cairo_contracts/src/.DS_Store -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-parser/test_data/cairo_files/short.cairo: -------------------------------------------------------------------------------- 1 | use std::format; 2 | 3 | fn foo(a: int) -> felt { 4 | return a; 5 | } 6 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-syntax/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Cairo syntax representation using green-red tree and AST abstraction. 2 | 3 | pub mod node; 4 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/argentlabs/starknet-build/HEAD/ERC721_0.x/lib/cairo_contracts/src/.DS_Store -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/docs/antora.yml: -------------------------------------------------------------------------------- 1 | name: contracts-cairo 2 | title: Contracts for Cairo 3 | version: 0.4.0 4 | nav: 5 | - modules/ROOT/nav.adoc 6 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/docs/antora.yml: -------------------------------------------------------------------------------- 1 | name: contracts-cairo 2 | title: Contracts for Cairo 3 | version: 0.4.0 4 | nav: 5 | - modules/ROOT/nav.adoc 6 | -------------------------------------------------------------------------------- /ICO_0.x/protostar.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | protostar-version = "0.9.1" 3 | lib-path = "lib" 4 | cairo-path = ["lib"] 5 | 6 | [contracts] 7 | ico = ["src/ICO.cairo"] 8 | 9 | -------------------------------------------------------------------------------- /ERC20_0.x/protostar.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | protostar-version = "0.9.1" 3 | lib-path = "lib" 4 | cairo-path = ["lib"] 5 | 6 | [contracts] 7 | ERC20 = ["src/ERC20.cairo"] 8 | 9 | -------------------------------------------------------------------------------- /ERC721_0.x/protostar.toml: -------------------------------------------------------------------------------- 1 | [project] 2 | protostar-version = "0.9.1" 3 | lib-path = "lib" 4 | cairo-path = ["lib"] 5 | 6 | [contracts] 7 | ERC721 = ["src/ERC721.cairo"] 8 | 9 | -------------------------------------------------------------------------------- /cairo1.0/scripts/starknet_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cargo +nightly-2022-11-03 run --bin cairo-test -- \ 4 | --path crates/cairo-lang-starknet/cairo_level_tests/ --starknet 5 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/tests/conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import asyncio 3 | 4 | @pytest.fixture(scope='module') 5 | def event_loop(): 6 | return asyncio.new_event_loop() 7 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/tests/conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import asyncio 3 | 4 | @pytest.fixture(scope='module') 5 | def event_loop(): 6 | return asyncio.new_event_loop() 7 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-filesystem/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Files and modules abstraction. 2 | 3 | pub mod db; 4 | pub mod detect; 5 | pub mod ids; 6 | pub mod span; 7 | pub mod test_utils; 8 | -------------------------------------------------------------------------------- /cairo1.0/scripts/clippy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cargo clippy "$@" --all-targets --all-features -- -D warnings -D future-incompatible \ 4 | -D nonstandard-style -D rust-2018-idioms -D unused 5 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-debug/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Debug utilities for types that need a salsa database for debug formatting. 2 | 3 | pub mod debug; 4 | pub use crate::debug::{helper, DebugWithDb}; 5 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-parser/test_data/cairo_files/colored.cairo: -------------------------------------------------------------------------------- 1 | ; 2 | #[attr] 3 | fn foo(var1: int var2: felt) -> int { 4 | let bla = 7 + true + 'abc'; // comment 5 | return bar(bla); 6 | } 7 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-syntax-codegen/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Code generation for the `syntax` crate. 2 | 3 | pub mod cairo_spec; 4 | pub mod generator; 5 | #[cfg(test)] 6 | mod golden_test; 7 | pub mod spec; 8 | -------------------------------------------------------------------------------- /ICO/target/CACHEDIR.TAG: -------------------------------------------------------------------------------- 1 | Signature: 8a477f597d28d172789f06886806bc55 2 | # This file is a cache directory tag created by scarb. 3 | # For information about cache directory tags see https://bford.info/cachedir/ 4 | -------------------------------------------------------------------------------- /ERC20/target/CACHEDIR.TAG: -------------------------------------------------------------------------------- 1 | Signature: 8a477f597d28d172789f06886806bc55 2 | # This file is a cache directory tag created by scarb. 3 | # For information about cache directory tags see https://bford.info/cachedir/ 4 | -------------------------------------------------------------------------------- /ICO/Scarb.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "src" 3 | version = "0.1.0" 4 | 5 | # See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest 6 | 7 | [dependencies] 8 | # foo = { path = "vendor/foo" } 9 | -------------------------------------------------------------------------------- /cairo1.0/.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | --- 2 | blank_issues_enabled: false 3 | contact_links: 4 | - name: Cairo Community Support 5 | url: https://github.com/starkware-libs-cairo/discussions 6 | about: Please ask and answer questions here. 7 | -------------------------------------------------------------------------------- /cairo1.0/corelib/box.cairo: -------------------------------------------------------------------------------- 1 | extern type Box; 2 | impl BoxFeltCopy of Copy::>; 3 | impl BoxFeltDrop of Drop::>; 4 | 5 | extern fn into_box(value: T) -> Box:: nopanic; 6 | extern fn unbox(box: Box::) -> T nopanic; 7 | -------------------------------------------------------------------------------- /cairo1.0/corelib/debug.cairo: -------------------------------------------------------------------------------- 1 | use array::ArrayTrait; 2 | 3 | extern fn print(message: Array::) nopanic; 4 | 5 | fn print_felt(message: felt) { 6 | let mut arr = ArrayTrait::new(); 7 | arr.append(message); 8 | print(arr); 9 | } 10 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-utils/src/casts.rs: -------------------------------------------------------------------------------- 1 | /// Casts a usize to an i16 if there is no overflow. 2 | /// Panics on overflow. 3 | pub fn usize_as_i16(n: usize) -> i16 { 4 | i16::try_from(n).unwrap_or_else(|_| panic!("Cast from usize to i16 failed: {n}")) 5 | } 6 | -------------------------------------------------------------------------------- /cairo1.0/.github/ISSUE_TEMPLATE/03_CODEBASE_IMPROVEMENT.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Codebase improvement 3 | about: Provide your feedback for the existing codebase. Suggest a better solution for algorithms, development tools, etc. 4 | title: "dev: " 5 | labels: "enhancement" 6 | assignees: "" 7 | --- 8 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-semantic/src/expr/mod.rs: -------------------------------------------------------------------------------- 1 | //! This module is responsible for inner code elements, such as expressions and statements. 2 | #[cfg(test)] 3 | mod test; 4 | 5 | pub mod compute; 6 | pub mod fmt; 7 | pub mod inference; 8 | pub mod objects; 9 | pub mod pattern; 10 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/SECURITY.md: -------------------------------------------------------------------------------- 1 | > ⚠️ Warning! ⚠️ 2 | > This project is still in a very early and experimental phase. It has never been audited nor thoroughly reviewed for security vulnerabilities. Do not use in production. 3 | 4 | Please report any security issues you find to security@openzeppelin.com. -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/SECURITY.md: -------------------------------------------------------------------------------- 1 | > ⚠️ Warning! ⚠️ 2 | > This project is still in a very early and experimental phase. It has never been audited nor thoroughly reviewed for security vulnerabilities. Do not use in production. 3 | 4 | Please report any security issues you find to security@openzeppelin.com. -------------------------------------------------------------------------------- /ERC20/Scarb.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ERC20_CAIRO1" 3 | version = "0.1.0" 4 | 5 | # See more keys and their definitions at https://github.com/software-mansion/scarb/blob/main/scarb/src/core/manifest/toml_manifest.rs 6 | 7 | [dependencies] 8 | # foo = { path = "vendor/foo" } 9 | 10 | [[target.starknet-contract]] -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Argent Starknet-buidl 2 | In here, you will find all codes associated with our series of articles teaching you how to build on Starknet with Argent X. 3 | 4 | Simply clone the repo `git clone git@github.com:argentlabs/starknet-build.git`, and `cd` into the directory associated with the article you are studying. -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-casm/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Cairo assembly representation, formatting and construction utilities. 2 | 3 | pub mod ap_change; 4 | pub mod assembler; 5 | pub mod builder; 6 | pub mod cell_expression; 7 | pub mod encoder; 8 | pub mod hints; 9 | pub mod inline; 10 | pub mod instructions; 11 | pub mod operand; 12 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-defs/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Representation and queries for definitions of module-level Cairo language elements. 2 | //! For example, resolving identifiers in the module level is done here. 3 | 4 | pub mod db; 5 | pub mod diagnostic_utils; 6 | pub mod ids; 7 | pub mod plugin; 8 | #[cfg(test)] 9 | mod test; 10 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-plugins/src/test_data/config: -------------------------------------------------------------------------------- 1 | //! > Test ignoring of test config in the test config. 2 | 3 | //! > test_function_name 4 | test_expand_plugin 5 | 6 | //! > cairo_code 7 | #[cfg(test)] 8 | mod Ignored { 9 | } 10 | 11 | mod NotIgnored { 12 | } 13 | 14 | //! > generated_cairo_code 15 | 16 | //! > expected_diagnostics 17 | -------------------------------------------------------------------------------- /cairo1.0/src/hello.cairo: -------------------------------------------------------------------------------- 1 | #[contract] 2 | mod HelloStarknet { 3 | struct Storage { 4 | balance: felt, 5 | } 6 | 7 | #[external] 8 | fn increase_balance(amount: felt) { 9 | balance::write(balance::read() + amount); 10 | } 11 | 12 | #[view] 13 | fn get_balance() -> felt { 14 | balance::read() 15 | } 16 | } -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/src/openzeppelin/introspection/erc165/IERC165.cairo: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts for Cairo v0.4.0 (introspection/erc165/IERC165.cairo) 3 | 4 | %lang starknet 5 | 6 | @contract_interface 7 | namespace IERC165 { 8 | func supportsInterface(interfaceId: felt) -> (success: felt) { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/src/openzeppelin/introspection/erc165/IERC165.cairo: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts for Cairo v0.4.0 (introspection/erc165/IERC165.cairo) 3 | 4 | %lang starknet 5 | 6 | @contract_interface 7 | namespace IERC165 { 8 | func supportsInterface(interfaceId: felt) -> (success: felt) { 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /cairo1.0/corelib/nullable.cairo: -------------------------------------------------------------------------------- 1 | extern type Nullable; 2 | 3 | enum FromNullableResult { 4 | Null: (), 5 | NotNull: Box::, 6 | } 7 | 8 | extern fn null() -> Nullable:: nopanic; 9 | extern fn into_nullable(value: Box::) -> Nullable:: nopanic; 10 | extern fn from_nullable(value: Nullable::) -> FromNullableResult:: nopanic; 11 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | # AVOID CHANGING REQUIRES: IT WILL BE UPDATED BY PYSCAFFOLD! 3 | requires = ["setuptools>=46.1.0", "setuptools_scm[toml]>=5", "wheel"] 4 | build-backend = "setuptools.build_meta" 5 | 6 | [tool.setuptools_scm] 7 | # See configuration details in https://github.com/pypa/setuptools_scm 8 | version_scheme = "no-guess-dev" 9 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | # AVOID CHANGING REQUIRES: IT WILL BE UPDATED BY PYSCAFFOLD! 3 | requires = ["setuptools>=46.1.0", "setuptools_scm[toml]>=5", "wheel"] 4 | build-backend = "setuptools.build_meta" 5 | 6 | [tool.setuptools_scm] 7 | # See configuration details in https://github.com/pypa/setuptools_scm 8 | version_scheme = "no-guess-dev" 9 | -------------------------------------------------------------------------------- /cairo1.0/corelib/gas.cairo: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Drop)] 2 | extern type BuiltinCosts; 3 | extern type GasBuiltin; 4 | 5 | extern fn get_gas() -> Option::<()> implicits(RangeCheck, GasBuiltin) nopanic; 6 | extern fn get_gas_all( 7 | costs: BuiltinCosts 8 | ) -> Option::<()> implicits(RangeCheck, GasBuiltin) nopanic; 9 | extern fn get_builtin_costs() -> BuiltinCosts nopanic; 10 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-semantic/src/items/tests/struct: -------------------------------------------------------------------------------- 1 | //! > Test struct generics. 2 | 3 | //! > test_function_name 4 | test_function_diagnostics 5 | 6 | //! > function 7 | fn foo(a: A::) -> felt { 8 | a.a 9 | } 10 | 11 | //! > function_name 12 | foo 13 | 14 | //! > module_code 15 | struct A { 16 | a: T 17 | } 18 | 19 | //! > expected_diagnostics 20 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-sierra-generator/src/function_generator_test.rs: -------------------------------------------------------------------------------- 1 | use crate::function_generator_test_utils::test_function_generator; 2 | 3 | cairo_lang_test_utils::test_file_test!( 4 | function_generator, 5 | "src/function_generator_test_data", 6 | { 7 | match_: "match", 8 | simple: "simple", 9 | }, 10 | test_function_generator 11 | ); 12 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-test-utils/test_data/test_example: -------------------------------------------------------------------------------- 1 | //! > Test Example 2 | 3 | //! > Expression 4 | foo 5 | 6 | //! > Expected 7 | bar 8 | 9 | //! > ========================================================================== 10 | 11 | //! > Another Test Example 12 | 13 | //! > Empty 14 | 15 | //! > Expression 16 | foo 17 | //! bar 18 | 19 | //! > Expected 20 | baz 21 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "docs", 3 | "version": "0.0.1", 4 | "scripts": { 5 | "docs": "oz-docs -c .", 6 | "docs:watch": "npm run docs watch", 7 | "prepare-docs": "" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "devDependencies": { 13 | "@openzeppelin/docs-utils": "^0.1.2" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "docs", 3 | "version": "0.0.1", 4 | "scripts": { 5 | "docs": "oz-docs -c .", 6 | "docs:watch": "npm run docs watch", 7 | "prepare-docs": "" 8 | }, 9 | "keywords": [], 10 | "author": "", 11 | "license": "ISC", 12 | "devDependencies": { 13 | "@openzeppelin/docs-utils": "^0.1.2" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-parser/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Cairo parser. 2 | //! 3 | //! This crate is responsible for parsing Cairo code. 4 | pub mod colored_printer; 5 | pub mod db; 6 | pub mod diagnostic; 7 | pub mod lexer; 8 | pub mod operators; 9 | pub mod parser; 10 | pub mod printer; 11 | pub mod recovery; 12 | pub mod test_utils; 13 | pub mod utils; 14 | 15 | pub use diagnostic::ParserDiagnostic; 16 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/src/openzeppelin/__init__.py: -------------------------------------------------------------------------------- 1 | """StarkNet/Cairo development toolbelt.""" 2 | 3 | try: 4 | from importlib import metadata as importlib_metadata 5 | except ImportError: 6 | import importlib_metadata 7 | 8 | try: 9 | __version__ = importlib_metadata.version("openzeppelin-cairo-contracts") 10 | except importlib_metadata.PackageNotFoundError: 11 | __version__ = None 12 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/src/openzeppelin/__init__.py: -------------------------------------------------------------------------------- 1 | """StarkNet/Cairo development toolbelt.""" 2 | 3 | try: 4 | from importlib import metadata as importlib_metadata 5 | except ImportError: 6 | import importlib_metadata 7 | 8 | try: 9 | __version__ = importlib_metadata.version("openzeppelin-cairo-contracts") 10 | except importlib_metadata.PackageNotFoundError: 11 | __version__ = None 12 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-semantic/src/items/tests/enum: -------------------------------------------------------------------------------- 1 | //! > Test enum generics. 2 | 3 | //! > test_function_name 4 | test_function_diagnostics 5 | 6 | //! > function 7 | fn foo(a: A::) -> felt { 8 | match a { 9 | A::Variant0(t) => {t} 10 | } 11 | } 12 | 13 | //! > function_name 14 | foo 15 | 16 | //! > module_code 17 | enum A { 18 | Variant0: T 19 | } 20 | 21 | //! > expected_diagnostics 22 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-sierra-generator/src/id_allocator.rs: -------------------------------------------------------------------------------- 1 | /// Allocates unique sequential identifiers. 2 | pub struct IdAllocator { 3 | next_id: usize, 4 | } 5 | impl IdAllocator { 6 | pub fn default() -> Self { 7 | Self { next_id: 0 } 8 | } 9 | 10 | pub fn allocate(&mut self) -> usize { 11 | let cur_id = self.next_id; 12 | self.next_id += 1; 13 | cur_id 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-diagnostics/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Diagnostics hold error information from around the compiler, associated with a location to the 2 | //! source files. 3 | 4 | mod diagnostics; 5 | mod location_marks; 6 | 7 | pub use self::diagnostics::{ 8 | format_diagnostics, skip_diagnostic, DiagnosticAdded, DiagnosticEntry, DiagnosticLocation, 9 | Diagnostics, DiagnosticsBuilder, Maybe, ToMaybe, ToOption, 10 | }; 11 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **🧐 Motivation** 11 | 12 | 13 | **📝 Details** 14 | 15 | 16 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **🧐 Motivation** 11 | 12 | 13 | **📝 Details** 14 | 15 | 16 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-semantic/src/items/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod attribute; 2 | pub mod constant; 3 | pub mod enm; 4 | pub mod extern_function; 5 | pub mod extern_type; 6 | pub mod free_function; 7 | pub mod function_with_body; 8 | pub mod functions; 9 | pub mod generics; 10 | pub mod imp; 11 | pub mod modifiers; 12 | pub mod module; 13 | pub mod structure; 14 | pub mod trt; 15 | pub mod type_alias; 16 | pub mod us; 17 | 18 | #[cfg(test)] 19 | mod test; 20 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/.markdownlintrc: -------------------------------------------------------------------------------- 1 | { 2 | // Disable line length check to enable paragraphs without internal line breaks. 3 | // See https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md#md013---line-length 4 | "MD013": false, 5 | // Disable inline HTML check to enable duplicate headers with separate ids. 6 | // See https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md#md033---inline-html 7 | "MD033": false 8 | } 9 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/.markdownlintrc: -------------------------------------------------------------------------------- 1 | { 2 | // Disable line length check to enable paragraphs without internal line breaks. 3 | // See https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md#md013---line-length 4 | "MD013": false, 5 | // Disable inline HTML check to enable duplicate headers with separate ids. 6 | // See https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md#md033---inline-html 7 | "MD033": false 8 | } 9 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-lowering/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Cairo lowering. 2 | //! 3 | //! This crate is responsible for handling the lowering phase. 4 | pub mod borrow_check; 5 | pub mod concretize; 6 | pub mod db; 7 | pub mod diagnostic; 8 | pub mod fmt; 9 | pub mod inline; 10 | pub mod lower; 11 | pub mod objects; 12 | pub mod panic; 13 | 14 | #[cfg(test)] 15 | mod test; 16 | 17 | pub use self::objects::*; 18 | 19 | #[cfg(any(feature = "testing", test))] 20 | pub mod test_utils; 21 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-parser/test_data/test_items: -------------------------------------------------------------------------------- 1 | fn foo (x:T) -> S 2 | { 3 | let x = -5 + 3; 4 | let y : T = x*2 + 3*5; // Comment. 5 | let z = ; 6 | 5 + Struct{a: 5, b: Struct2{_gg: ()}}; 7 | return df == 6; 8 | x + y 9 | } 10 | 11 | mod my_mod{ 12 | fn bar (x:T0, s: S) -> X { 13 | x.a *+-. s.s * foo(1,3) 14 | } 15 | struct A{ 16 | x: a, // Comment. 17 | y: int 18 | } 19 | 20 | } 21 | 22 | skipped tokens 23 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-parser/src/parser_test_data/question_mark: -------------------------------------------------------------------------------- 1 | //! > Handling question mark. 2 | 3 | //! > test_function_name 4 | get_diagnostics 5 | 6 | //! > cairo_code 7 | fn f() { 8 | let x = calc()?; 9 | let y = calc1(calc2()?)?; 10 | let z = w?; 11 | let block_eval = { other_expr }?; 12 | let block_eval = 7 + { other_expr }; 13 | let multi = error_of_errors????; 14 | let super_expr = (a? + b?)?; 15 | } 16 | 17 | //! > expected_diagnostics 18 | -------------------------------------------------------------------------------- /cairo1.0/vscode-cairo/language-configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "comments": { 3 | // Symbol used for single line comment. 4 | "lineComment": "//", 5 | }, 6 | // Symbols used as brackets. 7 | "brackets": [ 8 | [ 9 | "[", 10 | "]" 11 | ] 12 | ], 13 | // Symbols that are auto closed when typing. 14 | "autoClosingPairs": [ 15 | [ 16 | "[", 17 | "]" 18 | ], 19 | ], 20 | } 21 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-parser/test_data/cairo_files/test2.cairo: -------------------------------------------------------------------------------- 1 | fn foo (x:T) -> S 2 | { 3 | let x = -5 + 3; 4 | let y : T = x*2 + 3*5; // Comment. 5 | let z = ; 6 | 5 + Struct{a: 5, b: Struct2{_gg: ()}}; 7 | return df == 6; 8 | x + y 9 | } 10 | 11 | mod my_mod{ 12 | fn bar (x:T0, s: S) -> X { 13 | x.a *+-. s.s * foo(1,3) 14 | } 15 | struct A{ 16 | x: a, // Comment. 17 | y: int 18 | } 19 | 20 | } 21 | 22 | skipped tokens 23 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-syntax-codegen/src/generate_syntax.rs: -------------------------------------------------------------------------------- 1 | use cairo_lang_syntax_codegen::generator::{ensure_file_content, get_codes, project_root}; 2 | use cairo_lang_utils::logging::init_logging; 3 | 4 | fn main() { 5 | init_logging(log::LevelFilter::Info); 6 | log::info!("Starting syntax generation."); 7 | 8 | for (suffix, code) in get_codes() { 9 | let filename = project_root().join(suffix); 10 | ensure_file_content(filename, code); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-syntax-codegen/src/golden_test.rs: -------------------------------------------------------------------------------- 1 | use std::fs; 2 | 3 | use test_log::test; 4 | 5 | use crate::generator::{get_codes, project_root}; 6 | 7 | #[test] 8 | fn sourcegen_ast() { 9 | for (suffix, code) in get_codes() { 10 | let filename = project_root().join(suffix); 11 | if fs::read_to_string(filename).unwrap() != code { 12 | panic!("Some files are not up to date. Please run `cargo run --bin generate-syntax`"); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-debug/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cairo-lang-debug" 3 | version.workspace = true 4 | edition.workspace = true 5 | repository.workspace = true 6 | license-file.workspace = true 7 | description = "Debug utilities for query objects." 8 | 9 | [dev-dependencies] 10 | cairo-lang-utils = { path = "../cairo-lang-utils" } 11 | cairo-lang-proc-macros = { path = "../cairo-lang-proc-macros" } 12 | env_logger.workspace = true 13 | salsa.workspace = true 14 | test-log.workspace = true 15 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/src/openzeppelin/token/erc721/IERC721Receiver.cairo: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts for Cairo v0.4.0 (token/erc721/IERC721Receiver.cairo) 3 | 4 | %lang starknet 5 | 6 | from starkware.cairo.common.uint256 import Uint256 7 | 8 | @contract_interface 9 | namespace IERC721Receiver { 10 | func onERC721Received( 11 | operator: felt, from_: felt, tokenId: Uint256, data_len: felt, data: felt* 12 | ) -> (selector: felt) { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/src/openzeppelin/token/erc721/IERC721Receiver.cairo: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts for Cairo v0.4.0 (token/erc721/IERC721Receiver.cairo) 3 | 4 | %lang starknet 5 | 6 | from starkware.cairo.common.uint256 import Uint256 7 | 8 | @contract_interface 9 | namespace IERC721Receiver { 10 | func onERC721Received( 11 | operator: felt, from_: felt, tokenId: Uint256, data_len: felt, data: felt* 12 | ) -> (selector: felt) { 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-sierra-to-casm/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! CASM backend. Compiles from Sierra down to CASM. See [cairo_lang_sierra] and [cairo_lang_casm] 2 | 3 | pub mod annotations; 4 | // TODO(ilya): Reduce the size of CompilationError. 5 | #[allow(clippy::result_large_err)] 6 | pub mod compiler; 7 | pub mod environment; 8 | pub mod invocations; 9 | pub mod metadata; 10 | pub mod references; 11 | pub mod relocations; 12 | #[cfg(any(feature = "testing", test))] 13 | pub mod test_utils; 14 | pub mod type_sizes; 15 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-starknet/test_data/hello_starknet.cairo: -------------------------------------------------------------------------------- 1 | #[contract] 2 | mod HelloStarknet { 3 | struct Storage { 4 | balance: felt, 5 | } 6 | 7 | // Increases the balance by the given amount. 8 | #[external] 9 | fn increase_balance(amount: felt) { 10 | balance::write(balance::read() + amount); 11 | } 12 | 13 | // Returns the current balance. 14 | #[view] 15 | fn get_balance() -> felt { 16 | balance::read() 17 | 0 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | if __name__ == "__main__": 4 | try: 5 | setup(use_scm_version={"version_scheme": "no-guess-dev"}) 6 | except: # noqa 7 | print( 8 | "\n\nAn error occurred while building the project, " 9 | "please ensure you have the most updated version of setuptools, " 10 | "setuptools_scm and wheel with:\n" 11 | " pip install -U setuptools setuptools_scm wheel\n\n" 12 | ) 13 | raise 14 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/src/openzeppelin/token/erc721/IERC721Metadata.cairo: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts for Cairo v0.4.0 (token/erc721/IERC721Metadata.cairo) 3 | 4 | %lang starknet 5 | 6 | from starkware.cairo.common.uint256 import Uint256 7 | 8 | @contract_interface 9 | namespace IERC721Metadata { 10 | func name() -> (name: felt) { 11 | } 12 | 13 | func symbol() -> (symbol: felt) { 14 | } 15 | 16 | func tokenURI(tokenId: Uint256) -> (tokenURI: felt) { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-parser/src/parser_test_data/fn: -------------------------------------------------------------------------------- 1 | //! > Test missing param identifier 2 | 3 | //! > test_function_name 4 | get_diagnostics 5 | 6 | //! > cairo_code 7 | #[extern] 8 | #[abc] 9 | fn missing_id (ref: Ref::) { } 10 | 11 | //! > expected_diagnostics 12 | error: 'extern' is a reserved identifier. 13 | --> dummy_file.cairo:1:3 14 | #[extern] 15 | ^****^ 16 | 17 | error: Missing token TerminalIdentifier. 18 | --> dummy_file.cairo:3:22 19 | fn missing_id (ref: Ref::) { } 20 | ^ 21 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup 2 | 3 | if __name__ == "__main__": 4 | try: 5 | setup(use_scm_version={"version_scheme": "no-guess-dev"}) 6 | except: # noqa 7 | print( 8 | "\n\nAn error occurred while building the project, " 9 | "please ensure you have the most updated version of setuptools, " 10 | "setuptools_scm and wheel with:\n" 11 | " pip install -U setuptools setuptools_scm wheel\n\n" 12 | ) 13 | raise 14 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/src/openzeppelin/token/erc721/IERC721Metadata.cairo: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts for Cairo v0.4.0 (token/erc721/IERC721Metadata.cairo) 3 | 4 | %lang starknet 5 | 6 | from starkware.cairo.common.uint256 import Uint256 7 | 8 | @contract_interface 9 | namespace IERC721Metadata { 10 | func name() -> (name: felt) { 11 | } 12 | 13 | func symbol() -> (symbol: felt) { 14 | } 15 | 16 | func tokenURI(tokenId: Uint256) -> (tokenURI: felt) { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-sierra/src/extensions/modules/range_check.rs: -------------------------------------------------------------------------------- 1 | use crate::extensions::NoGenericArgsGenericType; 2 | use crate::ids::GenericTypeId; 3 | 4 | /// Type for Range Check builtin. 5 | #[derive(Default)] 6 | pub struct RangeCheckType {} 7 | impl NoGenericArgsGenericType for RangeCheckType { 8 | const ID: GenericTypeId = GenericTypeId::new_inline("RangeCheck"); 9 | const STORABLE: bool = true; 10 | const DUPLICATABLE: bool = false; 11 | const DROPPABLE: bool = false; 12 | const SIZE: i16 = 1; 13 | } 14 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-semantic/src/items/test.rs: -------------------------------------------------------------------------------- 1 | use crate::test_utils::test_function_diagnostics; 2 | 3 | cairo_lang_test_utils::test_file_test!( 4 | diagnostics, 5 | "src/items/tests", 6 | { 7 | enum_: "enum", 8 | extern_func: "extern_func", 9 | free_function: "free_function", 10 | panicable: "panicable", 11 | struct_: "struct", 12 | trait_: "trait", 13 | type_alias: "type_alias", 14 | module: "module", 15 | }, 16 | test_function_diagnostics 17 | ); 18 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/docs/modules/ROOT/nav.adoc: -------------------------------------------------------------------------------- 1 | * xref:index.adoc[Overview] 2 | * xref:wizard.adoc[Wizard] 3 | * xref:extensibility.adoc[Extensibility] 4 | * xref:proxies.adoc[Proxies and Upgrades] 5 | 6 | * xref:accounts.adoc[Accounts] 7 | * xref:access.adoc[Access Control] 8 | 9 | * Tokens 10 | ** xref:erc20.adoc[ERC20] 11 | ** xref:erc721.adoc[ERC721] 12 | 13 | * xref:security.adoc[Security] 14 | * xref:introspection.adoc[Introspection] 15 | * xref:utilities.adoc[Utilities] 16 | 17 | * xref:contracts::index.adoc[Contracts for Solidity] -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/docs/modules/ROOT/nav.adoc: -------------------------------------------------------------------------------- 1 | * xref:index.adoc[Overview] 2 | * xref:wizard.adoc[Wizard] 3 | * xref:extensibility.adoc[Extensibility] 4 | * xref:proxies.adoc[Proxies and Upgrades] 5 | 6 | * xref:accounts.adoc[Accounts] 7 | * xref:access.adoc[Access Control] 8 | 9 | * Tokens 10 | ** xref:erc20.adoc[ERC20] 11 | ** xref:erc721.adoc[ERC721] 12 | 13 | * xref:security.adoc[Security] 14 | * xref:introspection.adoc[Introspection] 15 | * xref:utilities.adoc[Utilities] 16 | 17 | * xref:contracts::index.adoc[Contracts for Solidity] -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-test-utils/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cairo-lang-test-utils" 3 | version.workspace = true 4 | edition.workspace = true 5 | repository.workspace = true 6 | license-file.workspace = true 7 | description = "Utilities for writing tests in the Cairo compiler project." 8 | 9 | [dependencies] 10 | cairo-lang-utils = { path = "../cairo-lang-utils", version = "1.0.0-alpha.2" } 11 | log.workspace = true 12 | env_logger.workspace = true 13 | pretty_assertions.workspace = true 14 | 15 | [dev-dependencies] 16 | test-log.workspace = true 17 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-sierra/src/extensions/modules/starknet/syscalls.rs: -------------------------------------------------------------------------------- 1 | use crate::extensions::NoGenericArgsGenericType; 2 | use crate::ids::GenericTypeId; 3 | 4 | /// Type for StarkNet system object. 5 | /// Used to make system calls. 6 | #[derive(Default)] 7 | pub struct SystemType {} 8 | impl NoGenericArgsGenericType for SystemType { 9 | const ID: GenericTypeId = GenericTypeId::new_inline("System"); 10 | const STORABLE: bool = true; 11 | const DUPLICATABLE: bool = false; 12 | const DROPPABLE: bool = false; 13 | const SIZE: i16 = 1; 14 | } 15 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-syntax/src/node/test_utils.rs: -------------------------------------------------------------------------------- 1 | use cairo_lang_filesystem::db::{FilesDatabase, FilesGroup}; 2 | use cairo_lang_utils::Upcast; 3 | 4 | use super::db::SyntaxDatabase; 5 | 6 | #[salsa::database(SyntaxDatabase, FilesDatabase)] 7 | #[derive(Default)] 8 | pub struct DatabaseForTesting { 9 | storage: salsa::Storage, 10 | } 11 | impl salsa::Database for DatabaseForTesting {} 12 | impl Upcast for DatabaseForTesting { 13 | fn upcast(&self) -> &(dyn FilesGroup + 'static) { 14 | self 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-proc-macros/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cairo-lang-proc-macros" 3 | version.workspace = true 4 | edition.workspace = true 5 | repository.workspace = true 6 | license-file.workspace = true 7 | description = "Procedural macros." 8 | 9 | [lib] 10 | proc-macro = true 11 | 12 | [package.metadata.cargo-udeps.ignore] 13 | normal = ["cairo-lang-debug"] 14 | 15 | [dependencies] 16 | # This is used only for docs. 17 | cairo-lang-debug = { path = "../cairo-lang-debug", version = "1.0.0-alpha.2" } 18 | quote.workspace = true 19 | syn.workspace = true 20 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-project/src/test.rs: -------------------------------------------------------------------------------- 1 | use indoc::indoc; 2 | 3 | use crate::ProjectConfigContent; 4 | 5 | #[test] 6 | fn test_serde() { 7 | let config = ProjectConfigContent { 8 | crate_roots: [("crate".into(), "dir".into())].into_iter().collect(), 9 | }; 10 | let serialized = toml::to_string(&config).unwrap(); 11 | assert_eq!( 12 | serialized, 13 | indoc! { r#" 14 | [crate_roots] 15 | crate = "dir" 16 | "# } 17 | ); 18 | assert_eq!(config, toml::from_str(&serialized).unwrap()); 19 | } 20 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-utils/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cairo-lang-utils" 3 | version.workspace = true 4 | edition.workspace = true 5 | repository.workspace = true 6 | license-file.workspace = true 7 | description = "General utilities for the Cairo compiler project." 8 | 9 | [features] 10 | testing = [] 11 | 12 | [dependencies] 13 | chrono.workspace = true 14 | env_logger.workspace = true 15 | indexmap.workspace = true 16 | itertools.workspace = true 17 | log.workspace = true 18 | 19 | [dev-dependencies] 20 | test-case.workspace = true 21 | test-log.workspace = true 22 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-starknet/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Starknet capabilities and utilities on top of Cairo. 2 | //! 3 | //! StarkNet is a smart contract platform that enables developers to build and deploy smart 4 | //! contracts on a permissionless Layer 2 network, secured by Ethereum using validity proofs. 5 | //! 6 | //! Learn more at [starkware.io](http://starknet.io/). 7 | pub mod abi; 8 | pub mod casm_contract_class; 9 | pub mod contract; 10 | pub mod contract_class; 11 | pub mod db; 12 | mod felt_serde; 13 | pub mod plugin; 14 | mod sierra_version; 15 | 16 | #[cfg(test)] 17 | mod test_utils; 18 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-runner/src/short_string.rs: -------------------------------------------------------------------------------- 1 | use cairo_felt::Felt; 2 | 3 | /// Converts a bigint representing a felt to a Cairo short-string. 4 | pub fn as_cairo_short_string(value: &Felt) -> Option { 5 | let mut as_string = String::default(); 6 | let mut is_end = false; 7 | for byte in value.to_bytes_be() { 8 | if byte == 0 { 9 | is_end = true; 10 | } else if is_end || !byte.is_ascii() { 11 | return None; 12 | } else { 13 | as_string.push(byte as char); 14 | } 15 | } 16 | Some(as_string) 17 | } 18 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-syntax/src/node/db.rs: -------------------------------------------------------------------------------- 1 | use cairo_lang_filesystem::db::FilesGroup; 2 | use cairo_lang_utils::Upcast; 3 | 4 | use super::green::GreenNode; 5 | use super::ids::{GreenId, SyntaxStablePtrId}; 6 | use super::stable_ptr::SyntaxStablePtr; 7 | 8 | // Salsa database interface. 9 | #[salsa::query_group(SyntaxDatabase)] 10 | pub trait SyntaxGroup: FilesGroup + Upcast { 11 | #[salsa::interned] 12 | fn intern_green(&self, field: GreenNode) -> GreenId; 13 | #[salsa::interned] 14 | fn intern_stable_ptr(&self, field: SyntaxStablePtr) -> SyntaxStablePtrId; 15 | } 16 | -------------------------------------------------------------------------------- /cairo1.0/scripts/release_tar.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | NAMES="cairo-compile cairo-format cairo-language-server cairo-run cairo-test sierra-compile starknet-compile starknet-sierra-compile" 4 | TARGET=$1 5 | rustup target add $TARGET 6 | cargo build --release --target $TARGET 7 | rm -rf target/$TARGET/cairo 8 | rm -rf target/$TARGET.tar.gz 9 | mkdir -p target/$TARGET/cairo 10 | ( 11 | cd target/$TARGET 12 | mkdir cairo/bin 13 | for NAME in $NAMES 14 | do 15 | cp release/$NAME cairo/bin/ 16 | done 17 | cp -R ../../corelib cairo/ 18 | tar czvf ../$TARGET.tar.gz cairo 19 | ) 20 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/tests/mocks/Initializable.cairo: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | %lang starknet 4 | 5 | from starkware.cairo.common.cairo_builtins import HashBuiltin 6 | 7 | from openzeppelin.security.initializable.library import Initializable 8 | 9 | @view 10 | func initialized{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (initialized: felt) { 11 | return Initializable.initialized(); 12 | } 13 | 14 | @external 15 | func initialize{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { 16 | Initializable.initialize(); 17 | return (); 18 | } 19 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/tests/mocks/ReentrancyAttackerMock.cairo: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | %lang starknet 4 | 5 | from starkware.cairo.common.cairo_builtins import HashBuiltin 6 | from starkware.starknet.common.syscalls import get_caller_address 7 | 8 | @contract_interface 9 | namespace IReentrancyGuard { 10 | func callback() { 11 | } 12 | } 13 | 14 | @external 15 | func call_sender{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { 16 | let (caller) = get_caller_address(); 17 | IReentrancyGuard.callback(contract_address=caller); 18 | return (); 19 | } 20 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/tests/mocks/Initializable.cairo: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | %lang starknet 4 | 5 | from starkware.cairo.common.cairo_builtins import HashBuiltin 6 | 7 | from openzeppelin.security.initializable.library import Initializable 8 | 9 | @view 10 | func initialized{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() -> (initialized: felt) { 11 | return Initializable.initialized(); 12 | } 13 | 14 | @external 15 | func initialize{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { 16 | Initializable.initialize(); 17 | return (); 18 | } 19 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/tests/mocks/ReentrancyAttackerMock.cairo: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | %lang starknet 4 | 5 | from starkware.cairo.common.cairo_builtins import HashBuiltin 6 | from starkware.starknet.common.syscalls import get_caller_address 7 | 8 | @contract_interface 9 | namespace IReentrancyGuard { 10 | func callback() { 11 | } 12 | } 13 | 14 | @external 15 | func call_sender{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}() { 16 | let (caller) = get_caller_address(); 17 | IReentrancyGuard.callback(contract_address=caller); 18 | return (); 19 | } 20 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-sierra-ap-change/src/ap_change_info.rs: -------------------------------------------------------------------------------- 1 | use cairo_lang_sierra::ids::FunctionId; 2 | use cairo_lang_sierra::program::StatementIdx; 3 | use cairo_lang_utils::ordered_hash_map::OrderedHashMap; 4 | 5 | /// Ap change information for a Sierra program. 6 | #[derive(Debug, Eq, PartialEq)] 7 | pub struct ApChangeInfo { 8 | /// The values of variables at matching libfuncs at given statements indices. 9 | pub variable_values: OrderedHashMap, 10 | /// The ap_change of calling the given function. 11 | pub function_ap_change: OrderedHashMap, 12 | } 13 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-sierra-to-casm/src/environment/ap_tracking.rs: -------------------------------------------------------------------------------- 1 | use cairo_lang_casm::ap_change::{ApChange, ApChangeError}; 2 | 3 | /// Updates the function level ap_tracking based on ap_change. 4 | pub fn update_ap_tracking( 5 | ap_tracking: ApChange, 6 | ap_change: ApChange, 7 | ) -> Result { 8 | Ok(match (ap_tracking, ap_change) { 9 | (ApChange::Known(current), ApChange::Known(change)) => { 10 | ApChange::Known(current.checked_add(change).ok_or(ApChangeError::OffsetOverflow)?) 11 | } 12 | _ => ApChange::Unknown, 13 | }) 14 | } 15 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/docs/modules/ROOT/pages/wizard.adoc: -------------------------------------------------------------------------------- 1 | = Cairo Contracts Wizard 2 | :page-notoc: 3 | 4 | Not sure where to start? Use the interactive generator below to bootstrap your 5 | contract and learn about the components offered in OpenZeppelin Cairo Contracts. 6 | 7 | 8 | NOTE: We strongly recommend checking the xref:extensibility.adoc[Extensibility Pattern] to understand how to extend from our library. 9 | 10 | ++++ 11 | 12 | 13 | 14 | ++++ 15 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/src/openzeppelin/token/erc721/enumerable/IERC721Enumerable.cairo: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts for Cairo v0.4.0 (token/erc721/enumerable/IERC721Enumerable.cairo) 3 | 4 | %lang starknet 5 | 6 | from starkware.cairo.common.uint256 import Uint256 7 | 8 | @contract_interface 9 | namespace IERC721Enumerable { 10 | func totalSupply() -> (totalSupply: Uint256) { 11 | } 12 | 13 | func tokenByIndex(index: Uint256) -> (tokenId: Uint256) { 14 | } 15 | 16 | func tokenOfOwnerByIndex(owner: felt, index: Uint256) -> (tokenId: Uint256) { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/docs/modules/ROOT/pages/wizard.adoc: -------------------------------------------------------------------------------- 1 | = Cairo Contracts Wizard 2 | :page-notoc: 3 | 4 | Not sure where to start? Use the interactive generator below to bootstrap your 5 | contract and learn about the components offered in OpenZeppelin Cairo Contracts. 6 | 7 | 8 | NOTE: We strongly recommend checking the xref:extensibility.adoc[Extensibility Pattern] to understand how to extend from our library. 9 | 10 | ++++ 11 | 12 | 13 | 14 | ++++ 15 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/src/openzeppelin/token/erc721/enumerable/IERC721Enumerable.cairo: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts for Cairo v0.4.0 (token/erc721/enumerable/IERC721Enumerable.cairo) 3 | 4 | %lang starknet 5 | 6 | from starkware.cairo.common.uint256 import Uint256 7 | 8 | @contract_interface 9 | namespace IERC721Enumerable { 10 | func totalSupply() -> (totalSupply: Uint256) { 11 | } 12 | 13 | func tokenByIndex(index: Uint256) -> (tokenId: Uint256) { 14 | } 15 | 16 | func tokenOfOwnerByIndex(owner: felt, index: Uint256) -> (tokenId: Uint256) { 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-compiler/src/diagnostics_test.rs: -------------------------------------------------------------------------------- 1 | use cairo_lang_filesystem::db::{FilesGroup, FilesGroupEx}; 2 | use cairo_lang_filesystem::ids::{CrateLongId, Directory}; 3 | 4 | use crate::db::RootDatabase; 5 | use crate::diagnostics::get_diagnostics_as_string; 6 | 7 | #[test] 8 | fn test_diagnostics() { 9 | let mut db = RootDatabase::default(); 10 | 11 | let crate_id = db.intern_crate(CrateLongId("bad_create".into())); 12 | db.set_crate_root(crate_id, Some(Directory("no/such/path".into()))); 13 | 14 | assert_eq!(get_diagnostics_as_string(&mut db), "no/such/path/lib.cairo not found\n"); 15 | } 16 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-eq-solver/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cairo-lang-eq-solver" 3 | version.workspace = true 4 | edition.workspace = true 5 | repository.workspace = true 6 | license-file.workspace = true 7 | description = "Equation solving for Sierra generation." 8 | 9 | [dependencies] 10 | cairo-lang-utils = { path = "../cairo-lang-utils", version = "1.0.0-alpha.2" } 11 | good_lp.workspace = true 12 | itertools.workspace = true 13 | indexmap.workspace = true 14 | 15 | [dev-dependencies] 16 | env_logger.workspace = true 17 | indoc.workspace = true 18 | test-case.workspace = true 19 | test-log.workspace = true 20 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-project/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cairo-lang-project" 3 | version.workspace = true 4 | edition.workspace = true 5 | repository.workspace = true 6 | license-file.workspace = true 7 | description = "Cairo project specification. For example, crates and flags used for compilation." 8 | 9 | [dependencies] 10 | serde.workspace = true 11 | smol_str.workspace = true 12 | thiserror.workspace = true 13 | toml.workspace = true 14 | cairo-lang-filesystem = { path = "../cairo-lang-filesystem", version = "1.0.0-alpha.2" } 15 | 16 | [dev-dependencies] 17 | indoc.workspace = true 18 | test-log.workspace = true 19 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-semantic/src/items/tests/extern_func: -------------------------------------------------------------------------------- 1 | //! > Test extern fn diagnostics. 2 | 3 | //! > test_function_name 4 | test_function_diagnostics 5 | 6 | //! > function 7 | fn foo() { 8 | bar() 9 | } 10 | 11 | //! > function_name 12 | foo 13 | 14 | //! > module_code 15 | extern fn bar() -> bad_type; 16 | 17 | //! > expected_diagnostics 18 | error: Type not found. 19 | --> lib.cairo:1:20 20 | extern fn bar() -> bad_type; 21 | ^******^ 22 | 23 | error: An extern function must be marked as nopanic. 24 | --> lib.cairo:1:1 25 | extern fn bar() -> bad_type; 26 | ^**************************^ 27 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-filesystem/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cairo-lang-filesystem" 3 | version.workspace = true 4 | edition.workspace = true 5 | repository.workspace = true 6 | license-file.workspace = true 7 | description = "Virtual filesystem for the compiler." 8 | 9 | [dependencies] 10 | cairo-lang-utils = { path = "../cairo-lang-utils", version = "1.0.0-alpha.2" } 11 | cairo-lang-debug = { path = "../cairo-lang-debug", version = "1.0.0-alpha.2" } 12 | path-clean.workspace = true 13 | salsa.workspace = true 14 | smol_str.workspace = true 15 | 16 | [dev-dependencies] 17 | env_logger.workspace = true 18 | test-log.workspace = true 19 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-parser/test_data/expected_results/colored: -------------------------------------------------------------------------------- 1 | ; 2 | #[attr] 3 | fn foo(var1: int var2: felt) -> int { 4 | let bla = 7 + true + 'abc'; // comment 5 | return bar(bla); 6 | } 7 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-semantic/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Semantic model representation and queries for Cairo. 2 | //! The semantic model represents the Cairo program after type resolution and some syntax 3 | //! desugaring. 4 | 5 | pub mod corelib; 6 | pub mod db; 7 | pub mod diagnostic; 8 | pub mod expr; 9 | pub mod items; 10 | pub mod literals; 11 | pub mod patcher; 12 | pub mod plugin; 13 | pub mod resolve_path; 14 | pub mod types; 15 | 16 | mod semantic; 17 | 18 | pub use diagnostic::SemanticDiagnostic; 19 | 20 | pub use self::semantic::*; 21 | 22 | #[cfg(any(feature = "testing", test))] 23 | pub mod test_utils; 24 | 25 | #[cfg(test)] 26 | mod test; 27 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/src/openzeppelin/access/accesscontrol/IAccessControl.cairo: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts for Cairo v0.4.0 (access/accesscontrol/IAccessControl.cairo) 3 | 4 | %lang starknet 5 | 6 | @contract_interface 7 | namespace IAccessControl { 8 | func hasRole(role: felt, account: felt) -> (hasRole: felt) { 9 | } 10 | 11 | func getRoleAdmin(role: felt) -> (admin: felt) { 12 | } 13 | 14 | func grantRole(role: felt, account: felt) { 15 | } 16 | 17 | func revokeRole(role: felt, account: felt) { 18 | } 19 | 20 | func renounceRole(role: felt, account: felt) { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/src/openzeppelin/access/accesscontrol/IAccessControl.cairo: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts for Cairo v0.4.0 (access/accesscontrol/IAccessControl.cairo) 3 | 4 | %lang starknet 5 | 6 | @contract_interface 7 | namespace IAccessControl { 8 | func hasRole(role: felt, account: felt) -> (hasRole: felt) { 9 | } 10 | 11 | func getRoleAdmin(role: felt) -> (admin: felt) { 12 | } 13 | 14 | func grantRole(role: felt, account: felt) { 15 | } 16 | 17 | func revokeRole(role: felt, account: felt) { 18 | } 19 | 20 | func renounceRole(role: felt, account: felt) { 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-test-runner/README.md: -------------------------------------------------------------------------------- 1 | # Testing cairo files 2 | 3 | ``` 4 | cargo run --bin cairo-test -- -p /path/to/file.cairo 5 | ``` 6 | 7 | We can use this command to run Cairo level tests. 8 | 9 | # Example 10 | 11 | ``` 12 | #[test] 13 | fn test_assert_true() { 14 | // Asserts that true 15 | assert(true, 'assert(true)'); 16 | } 17 | 18 | #[test] 19 | #[should_panic] 20 | fn test_assert_false() { 21 | assert(false, 'assert(false)'); 22 | } 23 | ``` 24 | 25 | # Longer Example 26 | 27 | Longer example can be found at [Core Library Test](../../corelib/test.cairo). 28 | 29 | ``` 30 | cargo run --bin cairo-test -- -p corelib/ 31 | ``` 32 | -------------------------------------------------------------------------------- /cairo1.0/vscode-cairo/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "outDir": "out", 6 | "lib": [ 7 | "es6" 8 | ], 9 | "sourceMap": true, 10 | "rootDir": "src", 11 | // Enable all strict type-checking options. 12 | "strict": true, 13 | // Additional checks. 14 | "noUnusedLocals": true, 15 | "noImplicitReturns": true, 16 | "noFallthroughCasesInSwitch": true, 17 | "noUnusedParameters": true 18 | }, 19 | "exclude": [ 20 | "node_modules", 21 | ".vscode-test" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-casm/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cairo-lang-casm" 3 | version.workspace = true 4 | edition.workspace = true 5 | repository.workspace = true 6 | license-file.workspace = true 7 | description = "Cairo assembly encoding." 8 | 9 | [dependencies] 10 | thiserror.workspace = true 11 | num-bigint.workspace = true 12 | num-traits.workspace = true 13 | cairo-lang-utils = { path = "../cairo-lang-utils", version = "1.0.0-alpha.2" } 14 | indoc.workspace = true 15 | 16 | [dev-dependencies] 17 | env_logger.workspace = true 18 | itertools.workspace = true 19 | pretty_assertions.workspace = true 20 | test-case.workspace = true 21 | test-log.workspace = true 22 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-parser/test_data/expected_results/colored_verbose: -------------------------------------------------------------------------------- 1 | ; 2 | #[attr] 3 | fn foo(var1: int var2: felt) -> int { 4 | let bla = 7 + true + 'abc'; // comment 5 | return bar(bla); 6 | } 7 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-sierra/src/extensions/type_specialization_context.rs: -------------------------------------------------------------------------------- 1 | use super::types::TypeInfo; 2 | use super::SpecializationError; 3 | use crate::ids::ConcreteTypeId; 4 | 5 | /// Trait for the specialization of types. 6 | pub trait TypeSpecializationContext { 7 | /// Returns the type information for the type with the given id. 8 | fn try_get_type_info(&self, id: ConcreteTypeId) -> Option; 9 | 10 | /// Wraps [Self::try_get_type_info] with a result object. 11 | fn get_type_info(&self, id: ConcreteTypeId) -> Result { 12 | self.try_get_type_info(id.clone()).ok_or(SpecializationError::MissingTypeInfo(id)) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/tests/mocks/ERC165.cairo: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | %lang starknet 4 | 5 | from starkware.cairo.common.cairo_builtins import HashBuiltin, SignatureBuiltin 6 | 7 | from openzeppelin.introspection.erc165.library import ERC165 8 | 9 | @view 10 | func supportsInterface{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( 11 | interfaceId: felt 12 | ) -> (success: felt) { 13 | return ERC165.supports_interface(interfaceId); 14 | } 15 | 16 | @external 17 | func registerInterface{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( 18 | interfaceId: felt 19 | ) { 20 | ERC165.register_interface(interfaceId); 21 | return (); 22 | } 23 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/tests/mocks/ERC165.cairo: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | 3 | %lang starknet 4 | 5 | from starkware.cairo.common.cairo_builtins import HashBuiltin, SignatureBuiltin 6 | 7 | from openzeppelin.introspection.erc165.library import ERC165 8 | 9 | @view 10 | func supportsInterface{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( 11 | interfaceId: felt 12 | ) -> (success: felt) { 13 | return ERC165.supports_interface(interfaceId); 14 | } 15 | 16 | @external 17 | func registerInterface{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}( 18 | interfaceId: felt 19 | ) { 20 | ERC165.register_interface(interfaceId); 21 | return (); 22 | } 23 | -------------------------------------------------------------------------------- /cairo1.0/.github/workflows/artifacts.yml: -------------------------------------------------------------------------------- 1 | name: Crate Artifacts 2 | on: workflow_dispatch 3 | jobs: 4 | create_artifacts: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v2 8 | - uses: actions-rs/toolchain@v1 9 | with: 10 | toolchain: stable 11 | - name: Install musl tools. 12 | run: sudo apt-get install -y musl-tools 13 | - name: Build in unknown linux 14 | run: ./scripts/release_tar.sh x86_64-unknown-linux-musl 15 | - name: Archive artifacts 16 | uses: actions/upload-artifact@v3 17 | with: 18 | name: release-x86_64-unknown-linux-musl 19 | path: target/x86_64-unknown-linux-musl.tar.gz 20 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-syntax-codegen/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cairo-lang-syntax-codegen" 3 | version.workspace = true 4 | edition.workspace = true 5 | repository.workspace = true 6 | license-file.workspace = true 7 | description = "Cairo syntax code generation." 8 | 9 | [package.metadata.cargo-udeps.ignore] 10 | normal = ["cairo-lang-syntax"] 11 | 12 | [dependencies] 13 | genco.workspace = true 14 | log.workspace = true 15 | xshell.workspace = true 16 | cairo-lang-utils = { path = "../cairo-lang-utils", version = "1.0.0-alpha.2" } 17 | 18 | [dev-dependencies] 19 | env_logger.workspace = true 20 | test-log.workspace = true 21 | 22 | [[bin]] 23 | name = "generate-syntax" 24 | path = "src/generate_syntax.rs" 25 | -------------------------------------------------------------------------------- /cairo1.0/examples/traits_impl/traits_impl.cairo: -------------------------------------------------------------------------------- 1 | #[contract] 2 | 3 | mod Simple { 4 | struct Storage{ 5 | number_pair: LegacyMap::, 6 | } 7 | 8 | trait IContract{ 9 | fn set_something(num: felt, pair: felt); 10 | 11 | fn get_something(num: felt) -> felt; 12 | } 13 | 14 | impl Contract of IContract { 15 | fn set_something(num: felt, pair: felt) { 16 | number_pair::write(num, pair) 17 | } 18 | 19 | fn get_something(num: felt) -> felt { 20 | number_pair::read(num) 21 | } 22 | } 23 | 24 | #[external] 25 | fn setter(num: felt, pair: felt) { 26 | IContract::set_something(num, pair) 27 | } 28 | } -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-syntax/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cairo-lang-syntax" 3 | version.workspace = true 4 | edition.workspace = true 5 | repository.workspace = true 6 | license-file.workspace = true 7 | description = "Cairo syntax representation." 8 | 9 | [dependencies] 10 | cairo-lang-debug = { path = "../cairo-lang-debug", version = "1.0.0-alpha.2" } 11 | cairo-lang-filesystem = { path = "../cairo-lang-filesystem", version = "1.0.0-alpha.2" } 12 | salsa.workspace = true 13 | smol_str.workspace = true 14 | cairo-lang-utils = { path = "../cairo-lang-utils", version = "1.0.0-alpha.2" } 15 | 16 | [dev-dependencies] 17 | env_logger.workspace = true 18 | pretty_assertions.workspace = true 19 | test-log.workspace = true 20 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-parser/src/parser_test_data/exprs: -------------------------------------------------------------------------------- 1 | //! > Test missing token 2 | 3 | //! > test_function_name 4 | get_diagnostics 5 | 6 | //! > cairo_code 7 | fn f() { 8 | {4} - 1 + * 2 + {5} 9 | } 10 | 11 | //! > expected_diagnostics 12 | error: Missing tokens. Expected an expression. 13 | --> dummy_file.cairo:2:14 14 | {4} - 1 + * 2 + {5} 15 | ^ 16 | 17 | //! > ========================================================================== 18 | 19 | //! > Test complex expression 20 | 21 | //! > test_function_name 22 | get_diagnostics 23 | 24 | //! > cairo_code 25 | fn f() { 26 | {5} + match x { E::V1(_) => 4, E::V2(_) => 2 } - if cond { 32 } else { 1 } 27 | } 28 | 29 | //! > expected_diagnostics 30 | -------------------------------------------------------------------------------- /ICO/src/IERC20.cairo: -------------------------------------------------------------------------------- 1 | use starknet::ContractAddress; 2 | 3 | #[abi] 4 | trait IERC20 { 5 | #[view] 6 | fn get_name() -> felt252; 7 | 8 | #[view] 9 | fn get_symbol() -> felt252; 10 | 11 | #[view] 12 | fn get_total_supply() -> felt252; 13 | 14 | #[view] 15 | fn balance_of(account: ContractAddress) -> u256; 16 | 17 | #[view] 18 | fn allowance(owner: ContractAddress, spender: ContractAddress) -> u256; 19 | 20 | #[external] 21 | fn transfer(recipient: ContractAddress, amount: u256); 22 | 23 | #[external] 24 | fn transfer_from(sender: ContractAddress, recipient: ContractAddress, amount: u256); 25 | 26 | #[external] 27 | fn approve(spender: ContractAddress, amount: u256); 28 | } -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-plugins/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Cairo core plugin implementations. 2 | use std::collections::HashSet; 3 | use std::sync::Arc; 4 | 5 | use cairo_lang_semantic::plugin::SemanticPlugin; 6 | 7 | use crate::config::ConfigPlugin; 8 | use crate::derive::DerivePlugin; 9 | use crate::panicable::PanicablePlugin; 10 | 11 | pub mod config; 12 | pub mod derive; 13 | pub mod panicable; 14 | 15 | #[cfg(test)] 16 | mod test; 17 | 18 | /// Gets the list of default plugins to load into the Cairo compiler. 19 | pub fn get_default_plugins() -> Vec> { 20 | vec![ 21 | Arc::new(DerivePlugin {}), 22 | Arc::new(PanicablePlugin {}), 23 | Arc::new(ConfigPlugin { configs: HashSet::default() }), 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-utils/src/collection_arithmetics_test.rs: -------------------------------------------------------------------------------- 1 | use test_log::test; 2 | 3 | use crate::collection_arithmetics::{add_maps, sub_maps}; 4 | use crate::ordered_hash_map::OrderedHashMap; 5 | 6 | #[test] 7 | fn test_add_map_and_sub_map() { 8 | let x = OrderedHashMap::::from_iter([(10, 3), (20, 7), (30, 3), (40, 3)]); 9 | let y = OrderedHashMap::::from_iter([(0, 2), (10, 5), (30, -3), (40, 3)]); 10 | 11 | assert_eq!( 12 | add_maps(x.clone(), y.clone()), 13 | OrderedHashMap::::from_iter([(10, 8), (20, 7), (0, 2), (40, 6)]) 14 | ); 15 | assert_eq!( 16 | sub_maps(x, y), 17 | OrderedHashMap::::from_iter([(10, -2), (20, 7), (30, 6), (0, -2)]) 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-diagnostics/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cairo-lang-diagnostics" 3 | version.workspace = true 4 | edition.workspace = true 5 | repository.workspace = true 6 | license-file.workspace = true 7 | description = "Diagnostic utilities." 8 | 9 | [dependencies] 10 | cairo-lang-utils = { path = "../cairo-lang-utils", version = "1.0.0-alpha.2" } 11 | cairo-lang-filesystem = { path = "../cairo-lang-filesystem", version = "1.0.0-alpha.2" } 12 | itertools.workspace = true 13 | salsa.workspace = true 14 | 15 | [dev-dependencies] 16 | cairo-lang-proc-macros = { path = "../cairo-lang-proc-macros", version = "1.0.0-alpha.2" } 17 | env_logger.workspace = true 18 | indoc.workspace = true 19 | pretty_assertions.workspace = true 20 | test-log.workspace = true 21 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-sierra-ap-change/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cairo-lang-sierra-ap-change" 3 | version.workspace = true 4 | edition.workspace = true 5 | repository.workspace = true 6 | license-file.workspace = true 7 | description = "Sierra AP change computation." 8 | 9 | [dependencies] 10 | itertools.workspace = true 11 | cairo-lang-sierra = { path = "../cairo-lang-sierra", version = "1.0.0-alpha.2" } 12 | cairo-lang-eq-solver = { path = "../cairo-lang-eq-solver", version = "1.0.0-alpha.2" } 13 | thiserror.workspace = true 14 | cairo-lang-utils = { path = "../cairo-lang-utils", version = "1.0.0-alpha.2" } 15 | 16 | [dev-dependencies] 17 | env_logger.workspace = true 18 | indoc.workspace = true 19 | test-case.workspace = true 20 | test-log.workspace = true 21 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-sierra-generator/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Lowering from the semantic model down to Sierra. See [cairo_lang_semantic] and 2 | //! [cairo_lang_sierra]. 3 | 4 | mod ap_change; 5 | mod block_generator; 6 | pub mod canonical_id_replacer; 7 | pub mod db; 8 | mod expr_generator_context; 9 | mod function_generator; 10 | #[cfg(any(feature = "testing", test))] 11 | pub mod function_generator_test_utils; 12 | mod id_allocator; 13 | mod lifetime; 14 | mod local_variables; 15 | mod next_statement_index_fetch; 16 | pub mod pre_sierra; 17 | mod program_generator; 18 | pub mod replace_ids; 19 | mod resolve_labels; 20 | mod specialization_context; 21 | mod store_variables; 22 | #[cfg(any(feature = "testing", test))] 23 | pub mod test_utils; 24 | mod types; 25 | mod utils; 26 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-sierra-gas/src/test_data/fib_jumps: -------------------------------------------------------------------------------- 1 | //! > Test fib_jumps. 2 | 3 | //! > test_file_name 4 | fib_jumps 5 | 6 | //! > test_function_name 7 | test_solve_gas 8 | 9 | //! > gas_solution 10 | #31: pedersen(0) 11 | #41: pedersen(0) 12 | #21: pedersen(0) 13 | #28: pedersen(0) 14 | #2: pedersen(0) 15 | #9: pedersen(0) 16 | #31: bitwise(0) 17 | #41: bitwise(0) 18 | #21: bitwise(0) 19 | #28: bitwise(0) 20 | #2: bitwise(0) 21 | #9: bitwise(0) 22 | #31: ec_op(0) 23 | #41: ec_op(0) 24 | #21: ec_op(0) 25 | #28: ec_op(0) 26 | #2: ec_op(0) 27 | #9: ec_op(0) 28 | #30: const(970) 29 | #31: const(0) 30 | #41: const(0) 31 | #46: const(0) 32 | #21: const(470) 33 | #24: const(0) 34 | #28: const(0) 35 | #2: const(1270) 36 | #4: const(0) 37 | #9: const(0) 38 | 39 | Fibonacci: 40 | const(1670) 41 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-parser/src/parser_test_data/pattern: -------------------------------------------------------------------------------- 1 | //! > Test modifier followed by path. 2 | 3 | //! > test_function_name 4 | get_diagnostics 5 | 6 | //! > cairo_code 7 | fn f() { 8 | let ref abc::def = 5; 9 | } 10 | 11 | //! > expected_diagnostics 12 | error: Missing token TerminalEq. 13 | --> dummy_file.cairo:2:16 14 | let ref abc::def = 5; 15 | ^ 16 | 17 | error: Missing tokens. Expected an expression. 18 | --> dummy_file.cairo:2:16 19 | let ref abc::def = 5; 20 | ^ 21 | 22 | error: Missing token TerminalSemicolon. 23 | --> dummy_file.cairo:2:16 24 | let ref abc::def = 5; 25 | ^ 26 | 27 | error: Skipped tokens. Expected: statement. 28 | --> dummy_file.cairo:2:16 29 | let ref abc::def = 5; 30 | ^^ 31 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/src/openzeppelin/utils/constants/library.cairo: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts for Cairo v0.4.0 (utils/constants/library.cairo) 3 | 4 | %lang starknet 5 | 6 | // 7 | // Numbers 8 | // 9 | 10 | const UINT8_MAX = 255; 11 | 12 | // 13 | // Interface Ids 14 | // 15 | 16 | // ERC165 17 | const IERC165_ID = 0x01ffc9a7; 18 | const INVALID_ID = 0xffffffff; 19 | 20 | // Account 21 | const IACCOUNT_ID = 0xa66bd575; 22 | 23 | // ERC721 24 | const IERC721_ID = 0x80ac58cd; 25 | const IERC721_RECEIVER_ID = 0x150b7a02; 26 | const IERC721_METADATA_ID = 0x5b5e139f; 27 | const IERC721_ENUMERABLE_ID = 0x780e9d63; 28 | 29 | // AccessControl 30 | const IACCESSCONTROL_ID = 0x7965db0b; 31 | 32 | // 33 | // Roles 34 | // 35 | 36 | const DEFAULT_ADMIN_ROLE = 0; 37 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/src/openzeppelin/utils/constants/library.cairo: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | // OpenZeppelin Contracts for Cairo v0.4.0 (utils/constants/library.cairo) 3 | 4 | %lang starknet 5 | 6 | // 7 | // Numbers 8 | // 9 | 10 | const UINT8_MAX = 255; 11 | 12 | // 13 | // Interface Ids 14 | // 15 | 16 | // ERC165 17 | const IERC165_ID = 0x01ffc9a7; 18 | const INVALID_ID = 0xffffffff; 19 | 20 | // Account 21 | const IACCOUNT_ID = 0xa66bd575; 22 | 23 | // ERC721 24 | const IERC721_ID = 0x80ac58cd; 25 | const IERC721_RECEIVER_ID = 0x150b7a02; 26 | const IERC721_METADATA_ID = 0x5b5e139f; 27 | const IERC721_ENUMERABLE_ID = 0x780e9d63; 28 | 29 | // AccessControl 30 | const IACCESSCONTROL_ID = 0x7965db0b; 31 | 32 | // 33 | // Roles 34 | // 35 | 36 | const DEFAULT_ADMIN_ROLE = 0; 37 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-sierra-generator/src/block_generator_test_data/early_return: -------------------------------------------------------------------------------- 1 | //! > Early return using if. 2 | 3 | //! > test_function_name 4 | block_generator_test 5 | 6 | //! > function 7 | fn foo(x: felt) -> felt { 8 | if x == 0 { 9 | return 1; 10 | } 11 | 2 12 | } 13 | 14 | //! > function_name 15 | foo 16 | 17 | //! > module_code 18 | 19 | //! > semantic_diagnostics 20 | 21 | //! > lowering_diagnostics 22 | 23 | //! > sierra_gen_diagnostics 24 | 25 | //! > sierra_code 26 | felt_is_zero([0]) { fallthrough() label0([1]) } 27 | branch_align() -> () 28 | felt_const<1>() -> ([2]) 29 | PushValues([2]: felt) -> ([3]) 30 | return([3]) 31 | label0: 32 | branch_align() -> () 33 | drop>([1]) -> () 34 | PushValues() -> () 35 | label1: 36 | felt_const<2>() -> ([4]) 37 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-language-server/src/vfs.rs: -------------------------------------------------------------------------------- 1 | use lsp::notification::Notification; 2 | use lsp::Url; 3 | use serde::{Deserialize, Serialize}; 4 | 5 | #[derive(Debug)] 6 | pub enum UpdateVirtualFile {} 7 | 8 | impl Notification for UpdateVirtualFile { 9 | type Params = UpdateVirtualFileParams; 10 | const METHOD: &'static str = "vfs/update"; 11 | } 12 | 13 | #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 14 | pub struct UpdateVirtualFileParams { 15 | pub uri: Url, 16 | } 17 | 18 | #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 19 | pub struct ProvideVirtualFileRequest { 20 | pub uri: Url, 21 | } 22 | 23 | #[derive(Debug, Eq, PartialEq, Clone, Deserialize, Serialize)] 24 | pub struct ProvideVirtualFileResponse { 25 | pub content: Option, 26 | } 27 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-semantic/src/expr/fmt.rs: -------------------------------------------------------------------------------- 1 | use cairo_lang_defs::db::DefsGroup; 2 | use cairo_lang_defs::ids::FunctionWithBodyId; 3 | use cairo_lang_utils::Upcast; 4 | 5 | use crate::db::SemanticGroup; 6 | 7 | /// Holds all the information needed for formatting expressions. 8 | /// Acts like a "db" for DebugWithDb. 9 | pub struct ExprFormatter<'a> { 10 | pub db: &'a (dyn SemanticGroup + 'static), 11 | pub function_id: FunctionWithBodyId, 12 | } 13 | 14 | impl<'a> Upcast for ExprFormatter<'a> { 15 | fn upcast(&self) -> &(dyn SemanticGroup + 'static) { 16 | self.db 17 | } 18 | } 19 | impl<'a> Upcast for ExprFormatter<'a> { 20 | fn upcast(&self) -> &(dyn DefsGroup + 'static) { 21 | self.db.upcast() 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-sierra/src/simulation/value.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | 3 | use num_bigint::BigInt; 4 | 5 | /// The logical value of a variable for Sierra simulation. 6 | #[derive(Clone, Debug, Eq, PartialEq)] 7 | pub enum CoreValue { 8 | EcPoint(BigInt, BigInt), 9 | // TODO(orizi): Use actual felt object. 10 | Felt(BigInt), 11 | GasBuiltin(i64), 12 | RangeCheck, 13 | Uint8(u8), 14 | Uint64(u64), 15 | Uint128(u128), 16 | NonZero(Box), 17 | Ref(Box), 18 | Array(Vec), 19 | Dict(HashMap), 20 | Enum { 21 | value: Box, 22 | /// The index of the relevant variant. 23 | index: usize, 24 | }, 25 | Struct(Vec), 26 | Uninitialized, 27 | } 28 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-sierra-generator/src/local_variables_test_data/construct_enum: -------------------------------------------------------------------------------- 1 | //! > Block 2 | 3 | //! > test_function_name 4 | check_find_local_variables 5 | 6 | //! > function_name 7 | foo 8 | 9 | //! > function_code 10 | fn foo() -> bool { 11 | let x = true; 12 | revoke_ap(); 13 | x 14 | } 15 | 16 | //! > module_code 17 | // Revokes ap since this function is recursive. 18 | fn revoke_ap() -> felt { 19 | revoke_ap() 20 | } 21 | 22 | struct MyStruct { 23 | a: felt, 24 | b: felt, 25 | } 26 | 27 | //! > lowering_format 28 | blk0 (root): 29 | Inputs: 30 | Statements: 31 | (v0: ()) <- struct_construct() 32 | (v1: core::bool) <- bool::True(v0) 33 | (v2: core::felt) <- test::revoke_ap() 34 | End: 35 | Return(v1) 36 | 37 | //! > local_variables 38 | v1 39 | 40 | //! > block_infos 41 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-starknet/src/test_utils.rs: -------------------------------------------------------------------------------- 1 | use std::path::PathBuf; 2 | 3 | use cairo_lang_compiler::CompilerConfig; 4 | 5 | use crate::contract_class::compile_path; 6 | 7 | /// Returns a path to example contract that matches `name`. 8 | pub fn get_example_file_path(file_name: &str) -> PathBuf { 9 | let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); 10 | path.extend(["test_data", file_name].into_iter()); 11 | path 12 | } 13 | 14 | /// Returns the compiled test contract, with replaced ids. 15 | pub fn get_test_contract(example_file_name: &str) -> crate::contract_class::ContractClass { 16 | let path = get_example_file_path(example_file_name); 17 | compile_path(&path, CompilerConfig { replace_ids: true, ..CompilerConfig::default() }) 18 | .expect("compile_path failed") 19 | } 20 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-lowering/src/test_data/constant: -------------------------------------------------------------------------------- 1 | //! > Constants 2 | 3 | //! > test_function_name 4 | test_function_lowering 5 | 6 | //! > function 7 | fn foo(x: felt) -> felt { 8 | MY_CONST + x 9 | } 10 | 11 | //! > function_name 12 | foo 13 | 14 | //! > module_code 15 | const MY_CONST: felt = 0x1234; 16 | 17 | //! > semantic_diagnostics 18 | 19 | //! > lowering_diagnostics 20 | 21 | //! > lowering_structured 22 | blk0 (root): 23 | Inputs: v0: core::felt 24 | Initial refs: 25 | Statements: 26 | (v1: core::felt) <- 4660u 27 | (v2: core::felt) <- core::FeltAdd::add(v1, v0) 28 | End: 29 | Return(v2) 30 | 31 | //! > lowering_flat 32 | blk0 (root): 33 | Inputs: v0: core::felt 34 | Statements: 35 | (v1: core::felt) <- 4660u 36 | (v2: core::felt) <- core::felt_add(v1, v0) 37 | End: 38 | Return(v2) 39 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-syntax/src/node/ids.rs: -------------------------------------------------------------------------------- 1 | use cairo_lang_filesystem::span::TextWidth; 2 | use cairo_lang_utils::define_short_id; 3 | 4 | use super::db::SyntaxGroup; 5 | use super::green::GreenNode; 6 | use crate::node::stable_ptr::SyntaxStablePtr; 7 | 8 | define_short_id!(GreenId, GreenNode, SyntaxGroup, lookup_intern_green); 9 | impl GreenId { 10 | /// Returns the width of the node of this green id. 11 | pub fn width(&self, db: &dyn SyntaxGroup) -> TextWidth { 12 | match db.lookup_intern_green(*self).details { 13 | super::green::GreenNodeDetails::Token(text) => TextWidth::from_str(&text), 14 | super::green::GreenNodeDetails::Node { width, .. } => width, 15 | } 16 | } 17 | } 18 | 19 | define_short_id!(SyntaxStablePtrId, SyntaxStablePtr, SyntaxGroup, lookup_intern_stable_ptr); 20 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-starknet/src/felt_serde_test.rs: -------------------------------------------------------------------------------- 1 | use std::fs::read_to_string; 2 | 3 | use cairo_lang_sierra::ProgramParser; 4 | use test_case::test_case; 5 | 6 | use super::{sierra_from_felts, sierra_to_felts}; 7 | use crate::test_utils::get_example_file_path; 8 | 9 | #[test_case("test_contract")] 10 | #[test_case("hello_starknet")] 11 | fn test_felt_serde(example_file_name: &str) { 12 | let sierra = ProgramParser::new() 13 | .parse( 14 | &read_to_string(get_example_file_path(format!("{example_file_name}.sierra").as_str())) 15 | .unwrap(), 16 | ) 17 | .unwrap(); 18 | pretty_assertions::assert_eq!( 19 | sierra_from_felts(&sierra_to_felts(&sierra).expect("Serialization failed.")) 20 | .expect("Deserialization failed."), 21 | sierra 22 | ); 23 | } 24 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Fixes #???? 7 | 8 | 9 | 10 | 11 | 12 | #### PR Checklist 13 | 14 | 15 | 16 | 17 | 18 | - [ ] Tests 19 | - [ ] Tried the feature on a public network 20 | - [ ] Documentation 21 | -------------------------------------------------------------------------------- /ICO_0.x/src/IERC20.cairo: -------------------------------------------------------------------------------- 1 | %lang starknet 2 | 3 | from starkware.cairo.common.uint256 import Uint256 4 | 5 | @contract_interface 6 | namespace IERC20 { 7 | func name() -> (name: felt) { 8 | } 9 | 10 | func symbol() -> (symbol: felt) { 11 | } 12 | 13 | func decimals() -> (decimals: felt) { 14 | } 15 | 16 | func totalSupply() -> (totalSupply: Uint256) { 17 | } 18 | 19 | func balanceOf(account: felt) -> (balance: Uint256) { 20 | } 21 | 22 | func allowance(owner: felt, spender: felt) -> (remaining: Uint256) { 23 | } 24 | 25 | func transfer(recipient: felt, amount: Uint256) -> (success: felt) { 26 | } 27 | 28 | func transferFrom(sender: felt, recipient: felt, amount: Uint256) -> (success: felt) { 29 | } 30 | 31 | func approve(spender: felt, amount: Uint256) -> (success: felt) { 32 | } 33 | } -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Fixes #???? 7 | 8 | 9 | 10 | 11 | 12 | #### PR Checklist 13 | 14 | 15 | 16 | 17 | 18 | - [ ] Tests 19 | - [ ] Tried the feature on a public network 20 | - [ ] Documentation 21 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-sierra-generator/src/block_generator_test_data/literals: -------------------------------------------------------------------------------- 1 | //! > Test literals code. 2 | 3 | //! > test_function_name 4 | block_generator_test 5 | 6 | //! > function 7 | fn foo() -> () { 8 | let x = 5; 9 | let y = 6; 10 | let x = 0x1a; 11 | let y = 12_u128; 12 | let x = 0x12_u128; 13 | } 14 | 15 | //! > function_name 16 | foo 17 | 18 | //! > module_code 19 | 20 | //! > semantic_diagnostics 21 | 22 | //! > lowering_diagnostics 23 | 24 | //! > sierra_gen_diagnostics 25 | 26 | //! > sierra_code 27 | felt_const<5>() -> ([0]) 28 | drop([0]) -> () 29 | felt_const<6>() -> ([1]) 30 | drop([1]) -> () 31 | felt_const<26>() -> ([2]) 32 | drop([2]) -> () 33 | u128_const<12>() -> ([3]) 34 | drop([3]) -> () 35 | u128_const<18>() -> ([4]) 36 | drop([4]) -> () 37 | struct_construct() -> ([5]) 38 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/tests/security/test_initializable.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from utils import TRUE, FALSE, assert_revert, get_contract_class, State 3 | 4 | 5 | @pytest.mark.asyncio 6 | async def test_initializer(): 7 | starknet = await State.init() 8 | initializable = await starknet.deploy( 9 | contract_class=get_contract_class("Initializable") 10 | ) 11 | expected = await initializable.initialized().call() 12 | assert expected.result == (FALSE,) 13 | 14 | await initializable.initialize().execute() 15 | 16 | expected = await initializable.initialized().call() 17 | assert expected.result == (TRUE,) 18 | 19 | # second initialize invocation should revert 20 | await assert_revert( 21 | initializable.initialize().execute(), 22 | reverted_with="Initializable: contract already initialized" 23 | ) 24 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/tests/security/test_initializable.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from utils import TRUE, FALSE, assert_revert, get_contract_class, State 3 | 4 | 5 | @pytest.mark.asyncio 6 | async def test_initializer(): 7 | starknet = await State.init() 8 | initializable = await starknet.deploy( 9 | contract_class=get_contract_class("Initializable") 10 | ) 11 | expected = await initializable.initialized().call() 12 | assert expected.result == (FALSE,) 13 | 14 | await initializable.initialize().execute() 15 | 16 | expected = await initializable.initialized().call() 17 | assert expected.result == (TRUE,) 18 | 19 | # second initialize invocation should revert 20 | await assert_revert( 21 | initializable.initialize().execute(), 22 | reverted_with="Initializable: contract already initialized" 23 | ) 24 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-starknet/src/casm_contract_class_test.rs: -------------------------------------------------------------------------------- 1 | use cairo_lang_test_utils::compare_contents_or_fix_with_path; 2 | use test_case::test_case; 3 | 4 | use crate::casm_contract_class::CasmContractClass; 5 | use crate::test_utils::{get_example_file_path, get_test_contract}; 6 | 7 | #[test_case("test_contract")] 8 | #[test_case("hello_starknet")] 9 | #[test_case("erc20")] 10 | fn test_casm_contract_from_contract_class(example_file_name: &str) { 11 | let contract_class = get_test_contract(format!("{example_file_name}.cairo").as_str()); 12 | let casm_contract = CasmContractClass::from_contract_class(contract_class).unwrap(); 13 | 14 | compare_contents_or_fix_with_path( 15 | &get_example_file_path(format!("{example_file_name}.casm").as_str()), 16 | serde_json::to_string_pretty(&casm_contract).unwrap() + "\n", 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /ERC20_0.x/lib/cairo_contracts/.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | 12 | 13 | 14 | **📝 Details** 15 | 16 | 17 | 18 | **🔢 Code to reproduce bug** 19 | 20 | 21 | -------------------------------------------------------------------------------- /ERC721_0.x/lib/cairo_contracts/.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | 12 | 13 | 14 | **📝 Details** 15 | 16 | 17 | 18 | **🔢 Code to reproduce bug** 19 | 20 | 21 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-sierra-gas/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cairo-lang-sierra-gas" 3 | version.workspace = true 4 | edition.workspace = true 5 | repository.workspace = true 6 | license-file.workspace = true 7 | description = "Sierra gas computation." 8 | 9 | [dependencies] 10 | itertools.workspace = true 11 | cairo-lang-sierra = { path = "../cairo-lang-sierra", version = "1.0.0-alpha.2" } 12 | cairo-lang-eq-solver = { path = "../cairo-lang-eq-solver", version = "1.0.0-alpha.2" } 13 | thiserror.workspace = true 14 | cairo-lang-utils = { path = "../cairo-lang-utils", version = "1.0.0-alpha.2" } 15 | 16 | [dev-dependencies] 17 | env_logger.workspace = true 18 | indoc.workspace = true 19 | test-case.workspace = true 20 | test-log.workspace = true 21 | pretty_assertions.workspace = true 22 | cairo-lang-test-utils = { path = "../cairo-lang-test-utils", version = "1.0.0-alpha.2" } 23 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-starknet/test_data/test_contract.cairo: -------------------------------------------------------------------------------- 1 | #[abi] 2 | trait IAnotherContract { 3 | fn foo(a: u128) -> u128; 4 | } 5 | 6 | 7 | #[contract] 8 | mod TestContract { 9 | struct Storage { 10 | my_storage_var: felt 11 | } 12 | 13 | fn internal_func() -> felt { 14 | 1 15 | } 16 | 17 | #[external] 18 | fn test(ref arg: felt, arg1: felt, arg2: felt) -> felt { 19 | let x = my_storage_var::read(); 20 | my_storage_var::write(x + 1); 21 | x + internal_func() 22 | } 23 | 24 | #[external] 25 | fn empty() {} 26 | 27 | #[external] 28 | fn call_foo(a: u128) -> u128 { 29 | // TODO(ilya): pass the address of foo as an argument. 30 | let foo_address = starknet::contract_address_const::<17>(); 31 | super::IAnotherContractDispatcher::foo(foo_address, a) 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-sierra/src/extensions/modules/branch_align.rs: -------------------------------------------------------------------------------- 1 | use crate::extensions::lib_func::{ 2 | LibfuncSignature, SierraApChange, SignatureSpecializationContext, 3 | }; 4 | use crate::extensions::{NoGenericArgsGenericLibfunc, SpecializationError}; 5 | 6 | /// Libfunc for aligning branches. 7 | /// Used to equalize environment changes across merging paths. 8 | /// This may include gas usages and ap changes. 9 | #[derive(Default)] 10 | pub struct BranchAlignLibfunc {} 11 | impl NoGenericArgsGenericLibfunc for BranchAlignLibfunc { 12 | const STR_ID: &'static str = "branch_align"; 13 | 14 | fn specialize_signature( 15 | &self, 16 | _context: &dyn SignatureSpecializationContext, 17 | ) -> Result { 18 | Ok(LibfuncSignature::new_non_branch(vec![], vec![], SierraApChange::BranchAlign)) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /cairo1.0/crates/cairo-lang-utils/src/logging.rs: -------------------------------------------------------------------------------- 1 | use std::io::Write; 2 | 3 | use log::LevelFilter; 4 | 5 | /// Initializes env_logger. 6 | /// The format is: 7 | /// ` /path/to/file: