-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: script to keep track of missing hints (#1015)
- Loading branch information
Showing
22 changed files
with
4,910 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -7,4 +7,5 @@ coverage: | |
ignore: | ||
- src/vm/errors | ||
- src/types/errors | ||
- hint_accountant | ||
- ./deps |
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,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 |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,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" |
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,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() | ||
} |
Oops, something went wrong.