-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from lambdaclass/progress
Implement more libfuncs
- Loading branch information
Showing
35 changed files
with
2,986 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Retreive cached dependecies | ||
uses: Swatinem/rust-cache@v2 | ||
- name: Deps | ||
run: make deps | ||
- name: Build | ||
run: cargo build --all-features --verbose | ||
- name: Run tests | ||
run: make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,11 @@ Cargo.lock | |
*.pdb | ||
|
||
# End of https://www.toptal.com/developers/gitignore/api/rust | ||
|
||
cairo2/ | ||
|
||
corelib | ||
|
||
*.tar | ||
|
||
*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
.PHONY: usage deps build check needs-cairo2 deps-macos build-cairo-2-compiler-macos decompress-cairo install-scarb clean | ||
|
||
UNAME := $(shell uname) | ||
|
||
CAIRO_2_VERSION=2.7.0 | ||
SCARB_VERSION = 2.7.0 | ||
|
||
needs-cairo2: | ||
ifeq ($(wildcard ./cairo2/.),) | ||
$(error You are missing the Starknet Cairo 1 compiler, please run 'make deps' to install the necessary dependencies.) | ||
endif | ||
./scripts/check-corelib-version.sh $(CAIRO_2_VERSION) | ||
|
||
usage: | ||
@echo "Usage:" | ||
@echo " deps: Installs the necesarry dependencies." | ||
@echo " build: Builds the cairo-native library and binaries." | ||
@echo " check: Checks format and lints." | ||
@echo " test: Runs all tests." | ||
@echo " clean: Cleans the built artifacts." | ||
|
||
build: | ||
cargo build --release --all-features | ||
|
||
check: | ||
cargo fmt --all -- --check | ||
cargo clippy --all-targets --all-features -- -D warnings | ||
|
||
test: needs-cairo2 | ||
cargo test --all-features | ||
|
||
clean: | ||
cargo clean | ||
|
||
deps: | ||
ifeq ($(UNAME), Linux) | ||
deps: build-cairo-2-compiler install-scarb | ||
endif | ||
ifeq ($(UNAME), Darwin) | ||
deps: deps-macos | ||
endif | ||
-rm -rf corelib | ||
-ln -s cairo2/corelib corelib | ||
|
||
deps-macos: build-cairo-2-compiler-macos install-scarb-macos | ||
|
||
cairo-repo-2-dir = cairo2 | ||
cairo-repo-2-dir-macos = cairo2-macos | ||
|
||
build-cairo-2-compiler-macos: | $(cairo-repo-2-dir-macos) | ||
|
||
$(cairo-repo-2-dir-macos): cairo-${CAIRO_2_VERSION}-macos.tar | ||
$(MAKE) decompress-cairo SOURCE=$< TARGET=cairo2/ | ||
|
||
build-cairo-2-compiler: | $(cairo-repo-2-dir) | ||
|
||
$(cairo-repo-2-dir): cairo-${CAIRO_2_VERSION}.tar | ||
$(MAKE) decompress-cairo SOURCE=$< TARGET=cairo2/ | ||
|
||
decompress-cairo: | ||
rm -rf $(TARGET) \ | ||
&& tar -xzvf $(SOURCE) \ | ||
&& mv cairo/ $(TARGET) | ||
|
||
cairo-%-macos.tar: | ||
curl -L -o "$@" "https://github.com/starkware-libs/cairo/releases/download/v$*/release-aarch64-apple-darwin.tar" | ||
|
||
cairo-%.tar: | ||
curl -L -o "$@" "https://github.com/starkware-libs/cairo/releases/download/v$*/release-x86_64-unknown-linux-musl.tar.gz" | ||
|
||
install-scarb: | ||
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh| sh -s -- --no-modify-path --version $(SCARB_VERSION) | ||
|
||
install-scarb-macos: | ||
curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh| sh -s -- --version $(SCARB_VERSION) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
use core::starknet::{ | ||
call_contract_syscall, class_hash_const, contract_address_const, ContractAddress, | ||
deploy_syscall, emit_event_syscall, ExecutionInfo, get_block_hash_syscall, | ||
keccak_syscall, | ||
library_call_syscall, replace_class_syscall, send_message_to_l1_syscall, | ||
storage_address_try_from_felt252, storage_read_syscall, storage_write_syscall, SyscallResult, | ||
testing::cheatcode, | ||
}; | ||
use core::starknet::syscalls::get_execution_info_syscall; | ||
use core::starknet::syscalls::get_execution_info_v2_syscall; | ||
|
||
fn get_block_hash() -> SyscallResult<felt252> { | ||
get_block_hash_syscall(0) | ||
} | ||
|
||
fn get_execution_info() -> SyscallResult<Box<core::starknet::info::ExecutionInfo>> { | ||
get_execution_info_syscall() | ||
} | ||
|
||
fn get_execution_info_v2() -> SyscallResult<Box<core::starknet::info::v2::ExecutionInfo>> { | ||
get_execution_info_v2_syscall() | ||
} | ||
|
||
fn deploy() -> SyscallResult<(ContractAddress, Span<felt252>)> { | ||
deploy_syscall(class_hash_const::<0>(), 0, array![].span(), false) | ||
} | ||
|
||
fn replace_class() -> SyscallResult<()> { | ||
replace_class_syscall(class_hash_const::<0>()) | ||
} | ||
|
||
fn library_call() -> SyscallResult<Span<felt252>> { | ||
library_call_syscall(class_hash_const::<0>(), 0, array![].span()) | ||
} | ||
|
||
fn call_contract() -> SyscallResult<Span<felt252>> { | ||
call_contract_syscall(contract_address_const::<0>(), 0, array![].span()) | ||
} | ||
|
||
fn storage_read() -> felt252 { | ||
storage_read_syscall(0, storage_address_try_from_felt252(0).unwrap()).unwrap() | ||
} | ||
|
||
fn storage_write() { | ||
storage_write_syscall(0, storage_address_try_from_felt252(0).unwrap(), 0).unwrap() | ||
} | ||
|
||
fn emit_event() -> SyscallResult<()> { | ||
emit_event_syscall(array![].span(), array![].span()) | ||
} | ||
|
||
fn send_message_to_l1() -> SyscallResult<()> { | ||
send_message_to_l1_syscall(3, array![2].span()) | ||
} | ||
|
||
fn keccak() -> SyscallResult<u256> { | ||
keccak_syscall(array![].span()) | ||
} | ||
|
||
fn set_sequencer_address(address: felt252) -> Span<felt252> { | ||
return cheatcode::<'set_sequencer_address'>(array![address].span()); | ||
} | ||
|
||
fn set_account_contract_address(address: felt252) -> Span<felt252> { | ||
return cheatcode::<'set_account_contract_address'>(array![address].span()); | ||
} | ||
|
||
fn set_block_number(number: felt252) -> Span<felt252> { | ||
return cheatcode::<'set_block_number'>(array![number].span()); | ||
} | ||
|
||
fn set_block_timestamp(timestamp: felt252) -> Span<felt252> { | ||
return cheatcode::<'set_block_timestamp'>(array![timestamp].span()); | ||
} | ||
|
||
fn set_caller_address(address: felt252) -> Span<felt252> { | ||
return cheatcode::<'set_caller_address'>(array![address].span()); | ||
} | ||
|
||
fn set_chain_id(id: felt252) -> Span<felt252> { | ||
return cheatcode::<'set_chain_id'>(array![id].span()); | ||
} | ||
|
||
fn set_contract_address(address: felt252) -> Span<felt252> { | ||
return cheatcode::<'set_contract_address'>(array![address].span()); | ||
} | ||
|
||
fn set_max_fee(fee: felt252) -> Span<felt252> { | ||
return cheatcode::<'set_max_fee'>(array![fee].span()); | ||
} | ||
|
||
fn set_nonce(nonce: felt252) -> Span<felt252> { | ||
return cheatcode::<'set_nonce'>(array![nonce].span()); | ||
} | ||
|
||
fn set_signature(signature: Array<felt252>) -> Span<felt252> { | ||
return cheatcode::<'set_signature'>(signature.span()); | ||
} | ||
|
||
fn set_transaction_hash(hash: felt252) -> Span<felt252> { | ||
return cheatcode::<'set_transaction_hash'>(array![hash].span()); | ||
} | ||
|
||
fn set_version(version: felt252) -> Span<felt252> { | ||
return cheatcode::<'set_version'>(array![version].span()); | ||
} | ||
|
||
fn pop_log(log: felt252) -> Span<felt252> { | ||
return cheatcode::<'pop_log'>(array![log].span()); | ||
} | ||
|
||
fn pop_l2_to_l1_message(message: felt252) -> Span<felt252> { | ||
return cheatcode::<'pop_l2_to_l1_message'>(array![message].span()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Script to check the corelib version matches. | ||
|
||
_result=$(grep "version = \"$1\"" corelib/Scarb.toml) | ||
|
||
if [ $? -ne 0 ]; then | ||
echo "corelib version mismatch, please re-run 'make deps'" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.