|
| 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