Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: script to keep track of missing hints #1015

Merged
merged 1 commit into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ coverage:
ignore:
- src/vm/errors
- src/types/errors
- hint_accountant
- ./deps
28 changes: 28 additions & 0 deletions .github/workflows/hint_accountant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Update missing hints tracking issue

on:
push:
branches: [ main ]

env:
CARGO_TERM_COLOR: always

jobs:
run:
runs-on: ubuntu-22.04
steps:
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@1.66.1
- name: Set up Cargo cache
uses: Swatinem/rust-cache@v2
- name: Checkout
uses: actions/checkout@v3
- name: Run the hint accounting script
run: cargo r -p hint_accountant | tee comment.md
- name: Update comment in tracking issue
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: 1031
comment-id: 1518234161
body-path: comment.md
edit-mode: replace
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
**/.DS_Store
**/*.svg
**/*.json
!hint_accountant/whitelists/*.json
!cairo_programs/manually_compiled/*.json
**/*.trace
**/*.memory
Expand Down
9 changes: 9 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = [".", "felt", "cairo-vm-cli", "./deps/parse-hyperlinks"]
members = [".", "cairo-vm-cli", "felt", "hint_accountant", "./deps/parse-hyperlinks"]

[package]
name = "cairo-vm"
Expand Down
11 changes: 11 additions & 0 deletions hint_accountant/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "hint_accountant"
version = "0.3.0-rc1"
edition = "2021"
license = "Apache-2.0"
description = "A script to check which whitelisted hints we're missing"

[dependencies]
cairo-vm = { path = "..", version = "0.3.0-rc1" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
90 changes: 90 additions & 0 deletions hint_accountant/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#![deny(warnings)]
#![forbid(unsafe_code)]
use cairo_vm::{
hint_processor::{
builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor,
hint_processor_definition::HintProcessor,
},
serde::deserialize_program::ApTracking,
types::exec_scope::ExecutionScopes,
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine},
with_std::collections::{HashMap, HashSet},
};
use serde::Deserialize;
use serde_json;
use serde_json::Value;

const WHITELISTS: [&'static 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"))]
_allowed_expressions: Option<Value>,
hint_lines: Vec<Box<str>>,
}

#[derive(Deserialize)]
struct Whitelist {
#[serde(rename(deserialize = "allowed_reference_expressions_for_hint"))]
allowed_hint_expressions: Vec<AllowedHintExpression>,
}

fn run() {
let mut vm = VirtualMachine::new(false);
let mut hint_executor = BuiltinHintProcessor::new_empty();
let (ap_tracking_data, reference_ids, references, mut exec_scopes, constants) = (
ApTracking::default(),
HashMap::new(),
HashMap::new(),
ExecutionScopes::new(),
HashMap::new(),
);
let missing_hints: HashSet<_> = WHITELISTS
.iter()
.flat_map(|wl| {
serde_json::from_str::<Whitelist>(wl)
.unwrap()
.allowed_hint_expressions
})
.map(|ahe| ahe.hint_lines.join("\n"))
.filter(|h| {
let hint_data = hint_executor
.compile_hint(&h, &ap_tracking_data, &reference_ids, &references)
.expect("this implementation is infallible");
matches!(
hint_executor.execute_hint(&mut vm, &mut exec_scopes, &hint_data, &constants),
Err(HintError::UnknownHint(_)),
)
})
.collect();

println!("{} missing hints:", missing_hints.len());
for hint in missing_hints.iter() {
println!("");
println!("```");
println!("%{{");
println!("{hint}");
println!("%}}");
println!("```");
}
}

fn main() {
run()
}
Loading