Skip to content

Commit 0155288

Browse files
authored
ci: script to keep track of missing hints (#1015)
1 parent e78190a commit 0155288

22 files changed

+4910
-1
lines changed

.github/codecov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ coverage:
77
ignore:
88
- src/vm/errors
99
- src/types/errors
10+
- hint_accountant
1011
- ./deps
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Update missing hints tracking issue
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
env:
8+
CARGO_TERM_COLOR: always
9+
10+
jobs:
11+
run:
12+
runs-on: ubuntu-22.04
13+
steps:
14+
- name: Install Rust toolchain
15+
uses: dtolnay/[email protected]
16+
- name: Set up Cargo cache
17+
uses: Swatinem/rust-cache@v2
18+
- name: Checkout
19+
uses: actions/checkout@v3
20+
- name: Run the hint accounting script
21+
run: cargo r -p hint_accountant | tee comment.md
22+
- name: Update comment in tracking issue
23+
uses: peter-evans/create-or-update-comment@v3
24+
with:
25+
issue-number: 1031
26+
comment-id: 1518234161
27+
body-path: comment.md
28+
edit-mode: replace

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
**/.DS_Store
33
**/*.svg
44
**/*.json
5+
!hint_accountant/whitelists/*.json
56
!cairo_programs/manually_compiled/*.json
67
**/*.trace
78
**/*.memory

Cargo.lock

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = [".", "felt", "cairo-vm-cli", "./deps/parse-hyperlinks"]
2+
members = [".", "cairo-vm-cli", "felt", "hint_accountant", "./deps/parse-hyperlinks"]
33

44
[package]
55
name = "cairo-vm"

hint_accountant/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "hint_accountant"
3+
version = "0.3.0-rc1"
4+
edition = "2021"
5+
license = "Apache-2.0"
6+
description = "A script to check which whitelisted hints we're missing"
7+
8+
[dependencies]
9+
cairo-vm = { path = "..", version = "0.3.0-rc1" }
10+
serde = { version = "1.0", features = ["derive"] }
11+
serde_json = "1.0"

hint_accountant/src/main.rs

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#![deny(warnings)]
2+
#![forbid(unsafe_code)]
3+
use cairo_vm::{
4+
hint_processor::{
5+
builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor,
6+
hint_processor_definition::HintProcessor,
7+
},
8+
serde::deserialize_program::ApTracking,
9+
types::exec_scope::ExecutionScopes,
10+
vm::{errors::hint_errors::HintError, vm_core::VirtualMachine},
11+
with_std::collections::{HashMap, HashSet},
12+
};
13+
use serde::Deserialize;
14+
use serde_json;
15+
use serde_json::Value;
16+
17+
const WHITELISTS: [&'static str; 15] = [
18+
include_str!("../whitelists/0.10.3.json"),
19+
include_str!("../whitelists/0.6.0.json"),
20+
include_str!("../whitelists/0.8.2.json"),
21+
include_str!("../whitelists/384_bit_prime_field.json"),
22+
include_str!("../whitelists/cairo_blake2s.json"),
23+
include_str!("../whitelists/cairo_keccak.json"),
24+
include_str!("../whitelists/cairo_secp.json"),
25+
include_str!("../whitelists/cairo_sha256.json"),
26+
include_str!("../whitelists/cairo_sha256_arbitrary_input_length.json"),
27+
include_str!("../whitelists/ec_bigint.json"),
28+
include_str!("../whitelists/ec_recover.json"),
29+
include_str!("../whitelists/encode_packed.json"),
30+
include_str!("../whitelists/latest.json"),
31+
include_str!("../whitelists/uint256_improvements.json"),
32+
include_str!("../whitelists/vrf.json"),
33+
];
34+
35+
#[derive(Deserialize)]
36+
struct AllowedHintExpression {
37+
#[serde(rename(deserialize = "allowed_expressions"))]
38+
_allowed_expressions: Option<Value>,
39+
hint_lines: Vec<Box<str>>,
40+
}
41+
42+
#[derive(Deserialize)]
43+
struct Whitelist {
44+
#[serde(rename(deserialize = "allowed_reference_expressions_for_hint"))]
45+
allowed_hint_expressions: Vec<AllowedHintExpression>,
46+
}
47+
48+
fn run() {
49+
let mut vm = VirtualMachine::new(false);
50+
let mut hint_executor = BuiltinHintProcessor::new_empty();
51+
let (ap_tracking_data, reference_ids, references, mut exec_scopes, constants) = (
52+
ApTracking::default(),
53+
HashMap::new(),
54+
HashMap::new(),
55+
ExecutionScopes::new(),
56+
HashMap::new(),
57+
);
58+
let missing_hints: HashSet<_> = WHITELISTS
59+
.iter()
60+
.flat_map(|wl| {
61+
serde_json::from_str::<Whitelist>(wl)
62+
.unwrap()
63+
.allowed_hint_expressions
64+
})
65+
.map(|ahe| ahe.hint_lines.join("\n"))
66+
.filter(|h| {
67+
let hint_data = hint_executor
68+
.compile_hint(&h, &ap_tracking_data, &reference_ids, &references)
69+
.expect("this implementation is infallible");
70+
matches!(
71+
hint_executor.execute_hint(&mut vm, &mut exec_scopes, &hint_data, &constants),
72+
Err(HintError::UnknownHint(_)),
73+
)
74+
})
75+
.collect();
76+
77+
println!("{} missing hints:", missing_hints.len());
78+
for hint in missing_hints.iter() {
79+
println!("");
80+
println!("```");
81+
println!("%{{");
82+
println!("{hint}");
83+
println!("%}}");
84+
println!("```");
85+
}
86+
}
87+
88+
fn main() {
89+
run()
90+
}

0 commit comments

Comments
 (0)