Skip to content

Commit

Permalink
Merge branch 'main' into fresh-run-ci
Browse files Browse the repository at this point in the history
  • Loading branch information
fmoletta authored Aug 31, 2023
2 parents b498fb1 + 91eeff5 commit 8d6fe97
Show file tree
Hide file tree
Showing 32 changed files with 147 additions and 5,128 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/hint_accountant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
uses: actions/checkout@v3
- name: Check Build
run: cargo build -p hint_accountant
- name: Clone cairo-lang repo
run: git clone --depth=1 https://github.com/starkware-libs/cairo-lang
- name: Run the hint accounting script
run: cargo r -p hint_accountant | tee comment.md
- name: Update comment in tracking issue
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ cairo-vm-env/*
cairo-vm-pypy-env/*
/cairo1/
/cairo2/
/cairo-lang/
*.tar

ensure-no_std/Cargo.lock
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ STARKNET_SIERRA_COMPILE_CAIRO_2:=cairo2/bin/starknet-sierra-compile
compare_trace_memory_proof compare_all_proof compare_trace_proof compare_memory_proof compare_air_public_input \
cairo_bench_programs cairo_proof_programs cairo_test_programs cairo_1_test_contracts cairo_2_test_contracts \
cairo_trace cairo-vm_trace cairo_proof_trace cairo-vm_proof_trace \
fuzzer-deps fuzzer-run-cairo-compiled fuzzer-run-hint-diff \
fuzzer-deps fuzzer-run-cairo-compiled fuzzer-run-hint-diff build-cairo-lang hint-accountant \
$(RELBIN) $(DBGBIN)

# Proof mode consumes too much memory with cairo-lang to execute
Expand Down Expand Up @@ -309,6 +309,7 @@ clean:
rm -rf cairo
rm -rf cairo1
rm -rf cairo2
rm -rf cairo-lang

fuzzer-deps: build
cargo +nightly install cargo-fuzz
Expand All @@ -325,3 +326,14 @@ fuzzer-run-hint-diff:
. cairo-vm-env/bin/activate ; \
cd fuzzer/diff_fuzzer/; \
../../cairo-vm-env/bin/python random_hint_fuzzer.py -len_control=0

CAIRO_LANG_REPO_DIR=cairo-lang

$(CAIRO_LANG_REPO_DIR):
git clone --depth=1 https://github.com/starkware-libs/cairo-lang

build-cairo-lang: | $(CAIRO_LANG_REPO_DIR)

hint-accountant: build-cairo-lang
cargo r -p hint_accountant

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ A faster and safer implementation of the Cairo VM in Rust

[pr-welcome]: https://img.shields.io/static/v1?color=orange&label=PRs&style=flat&message=welcome
[tg-badge]: https://img.shields.io/static/v1?color=green&logo=telegram&label=chat&style=flat&message=join
[tg-url]: https://t.me/starknet_rs
[tg-url]: https://t.me/LambdaStarkNet

</div>

Expand Down Expand Up @@ -72,7 +72,7 @@ It's Turing-complete and it was created by [Starkware](https://starkware.co/) as

These are needed in order to compile and use the project.

- [Rust 1.69.0 or newer](https://www.rust-lang.org/tools/install)
- [Rust 1.70.0 or newer](https://www.rust-lang.org/tools/install)
- Cargo

#### Optional
Expand Down
5 changes: 4 additions & 1 deletion hint_accountant/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ publish = false
[dependencies]
cairo-vm.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_json = { version = "1.0", features = [
"arbitrary_precision",
"alloc",
]}
49 changes: 24 additions & 25 deletions hint_accountant/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#![deny(warnings)]
#![forbid(unsafe_code)]
use std::fs::{self, File};
use std::io::BufReader;

use cairo_vm::stdlib::collections::{HashMap, HashSet};
use cairo_vm::{
hint_processor::{
Expand All @@ -14,24 +17,6 @@ use cairo_vm::{
use serde::Deserialize;
use serde_json::Value;

const WHITELISTS: [&str; 15] = [
include_str!("../whitelists/0.10.3.json"),
include_str!("../whitelists/0.6.0.json"),
include_str!("../whitelists/0.8.2.json"),
include_str!("../whitelists/384_bit_prime_field.json"),
include_str!("../whitelists/cairo_blake2s.json"),
include_str!("../whitelists/cairo_keccak.json"),
include_str!("../whitelists/cairo_secp.json"),
include_str!("../whitelists/cairo_sha256.json"),
include_str!("../whitelists/cairo_sha256_arbitrary_input_length.json"),
include_str!("../whitelists/ec_bigint.json"),
include_str!("../whitelists/ec_recover.json"),
include_str!("../whitelists/encode_packed.json"),
include_str!("../whitelists/latest.json"),
include_str!("../whitelists/uint256_improvements.json"),
include_str!("../whitelists/vrf.json"),
];

#[derive(Deserialize)]
struct AllowedHintExpression {
#[serde(rename(deserialize = "allowed_expressions"))]
Expand All @@ -45,7 +30,25 @@ struct Whitelist {
allowed_hint_expressions: Vec<AllowedHintExpression>,
}

const CAIRO_LANG_PATH: &str = "cairo-lang/src/starkware/starknet/security/whitelists";

fn run() {
// We use the files in the cairo-lang repo, cloned from the latest version
let whitelist_paths = fs::read_dir(CAIRO_LANG_PATH).expect(
"Failed to read whitelist directory from cairo-lang, did you forget to clone it?\n",
);
let mut whitelists = Vec::new();
for path in whitelist_paths {
let path = path.expect("Failed to get path").path();
if path.to_str().unwrap_or_default().ends_with(".json") {
let file = File::open(path).expect("Failed to open whitelist file");
let mut reader = BufReader::new(file);

let whitelist_file: Whitelist =
serde_json::from_reader(&mut reader).expect("Failed to parse whitelist");
whitelists.push(whitelist_file.allowed_hint_expressions);
}
}
let mut vm = VirtualMachine::new(false);
let mut hint_executor = BuiltinHintProcessor::new_empty();
let (ap_tracking_data, reference_ids, references, mut exec_scopes, constants) = (
Expand All @@ -55,13 +58,9 @@ fn run() {
ExecutionScopes::new(),
HashMap::new(),
);
let missing_hints: HashSet<_> = WHITELISTS
.iter()
.flat_map(|wl| {
serde_json::from_str::<Whitelist>(wl)
.unwrap()
.allowed_hint_expressions
})
let missing_hints: HashSet<_> = whitelists
.into_iter()
.flatten()
.map(|ahe| ahe.hint_lines.join("\n"))
.filter(|h| {
let hint_data = hint_executor
Expand Down
Loading

0 comments on commit 8d6fe97

Please sign in to comment.