Skip to content

Commit

Permalink
feat: memory (#34)
Browse files Browse the repository at this point in the history
* feat: MemoryTrait + store()

* feat: memory store_n

* feat: memory load / load_n

* feat: memory expand/ensure_length

* docs: memory docs

* fix: cairo_project script kakarot path

* refactor: u128-based memory rather instead of felt252

* tests: helper functions test

* chore: address PR review 1

* refactor: optimize pow256_rev

* chore: address PR review 2 - optimize mask, rename testfiles

* fix: store_u256 bug, address pr

* chore: clean remaining todos

* chore: update CI
  • Loading branch information
enitrat authored May 11, 2023
1 parent 4afa1e9 commit 22f2f23
Show file tree
Hide file tree
Showing 20 changed files with 1,209 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on: [push, pull_request]
env:
CAIRO_COMPILER_VERSION: 1.0.0-rc0
# Temporary use artifacts from custom CI build
ARTIFACT_RELEASE_ARCHIVE_LINK: https://api.github.com/repos/starkware-libs/cairo/actions/artifacts/679726320/zip
ARTIFACT_RELEASE_ARCHIVE_LINK: https://api.github.com/repos/starkware-libs/cairo/actions/artifacts/689746858/zip
ARTIFACT_RELEASE_ARCHIVE_NAME: cairo.zip
RELEASE_ARCHIVE_NAME: x86_64-unknown-linux-musl.tar.gz

Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ target/
# Environment files
.env

build
build

# Cairo project config file.
# Auto-generated by scripts/generate_cairo_project.sh
cairo_project.toml
15 changes: 12 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,16 @@ all: build run test

# Targets

# There is no integration between Scarb and the default `cairo-test` runner.
# Therefore, we need to generate the cairo_project.toml file, required
# by the `cairo-test` runner, manually. This is done by the generate_cairo_project script.
cairo-project:
@echo "Generating cairo project..."
sh scripts/generate_cairo_project.sh
# Test the project

# Compile the project
build: FORCE
build: cairo-project FORCE
$(MAKE) clean format
@echo "Building..."
cairo-compile . > $(BUILD_DIR)/$(PROJECT_NAME).sierra
Expand All @@ -25,8 +33,9 @@ run:
@echo "Running..."
#cairo-run -p $(ENTRYPOINT)

# Test the project
test:


test: cairo-project
@echo "Testing..."
cairo-test $(TEST_ENTRYPOINT)

Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ It is a work in progress, and it is not ready for production.

- [Cairo](https://github.com/starkware-libs/cairo)
- [Rust](https://www.rust-lang.org/tools/install)
- [Scarb](https://docs.swmansion.com/scarb/download)
- [jq](https://stedolan.github.io/jq/download/)

### Installation

> **[TODO]**
## Usage


### Build

```bash
Expand All @@ -81,6 +82,11 @@ make run

### Test

We use the `cairo-test` runner to run the unit tests on Kakarot.
However, it is not directly compatible with Scarb. Hence, we use a script
to generate the `cairo_project.toml` file from Scarb's metadata.
Running this script requires `jq` to be installed.

```bash
make test
```
Expand Down Expand Up @@ -141,7 +147,6 @@ See [LICENSE](LICENSE) for more information.

## Acknowledgements


## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
Expand Down Expand Up @@ -176,4 +181,4 @@ This project follows the [all-contributors](https://github.com/all-contributors/

<p align="center">
<img src="docs/img/kakarot_github_banner_footer.png" height="200">
</p>
</p>
3 changes: 0 additions & 3 deletions Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[package]
name = "kakarot"
version = "0.1.0"

[dependencies]
quaireaux = { git = "https://github.com/keep-starknet-strange/quaireaux.git" }
2 changes: 0 additions & 2 deletions cairo_project.toml

This file was deleted.

25 changes: 25 additions & 0 deletions scripts/generate_cairo_project.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

# This script is used to generate the `cairo_project.toml` file
# from the Scarb project's metadata.
# It is required to run the `cairo-test` runner.

# Run the scarb metadata command and store the JSON output in a variable
json_output=$(scarb metadata --format-version 1| sed -n '/^{/,$p')

# Create a temporary file to store the JSON output
temp_file=$(mktemp)
echo "$json_output" > "$temp_file"

# Initialize cairo_project.toml file
echo "[crate_roots]" > cairo_project.toml

# Process the JSON output and create the cairo_project.toml file using jq
jq -r '.packages[] | select(.name != "core" and .name != "kakarot") | .name + " = \"" + .root + "/src\""' "$temp_file" >> cairo_project.toml

# Add kakarot and tests to the cairo_project.toml
echo 'kakarot = "src"' >> cairo_project.toml
echo 'tests = "tests"' >> cairo_project.toml

# Remove the temporary file
rm "$temp_file"
3 changes: 0 additions & 3 deletions src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,3 @@ mod context;

// Utils module
mod utils;

// Test modules
mod tests;
Loading

0 comments on commit 22f2f23

Please sign in to comment.