Skip to content

Commit

Permalink
more selectors, fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
maciejka committed Dec 18, 2023
1 parent b32145b commit e2fdc1f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 31 deletions.
44 changes: 25 additions & 19 deletions src/bin/hints.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::collections::HashSet;
use std::collections::{HashMap, HashSet};
use std::fs::{read_dir, File};
use std::io::{BufReader, Read};
use std::io::BufReader;

use serde::Deserialize;
use serde_json::Value;
Expand All @@ -21,8 +21,19 @@ struct Whitelist {
allowed_hint_expressions: Vec<AllowedHintExpression>,
}

#[derive(Deserialize)]
struct Hint {
code: Box<str>,
}

#[derive(Deserialize)]
struct Os {
hints: HashMap<String, Vec<Hint>>,
}

fn main() -> std::io::Result<()> {
let subset = std::env::args().nth(1).expect("choose what you need: all, implemented, unimplemented");
let subset =
std::env::args().nth(1).expect("choose what you need: all, implemented, unimplemented, whitelisted, snos");

// whitelisted hints implemented by the vm
let whitelist_paths = read_dir(WHITELISTS_PATH).expect("Failed to read whitelist directory");
Expand All @@ -40,27 +51,22 @@ fn main() -> std::io::Result<()> {

let whitelisted_hints =
whitelists.into_iter().flatten().map(|ahe| ahe.hint_lines.join("\n")).collect::<HashSet<_>>();

let snos_hints = sn_hint_processor().extra_hints.keys().cloned().collect::<HashSet<_>>();

let implemented_hints = whitelisted_hints.union(&snos_hints).collect::<HashSet<_>>();

let mut result = HashSet::new();

let mut file = File::open("build/os_latest.json")?;
let mut data = String::new();
let _ = file.read_to_string(&mut data);
let json: Value = serde_json::from_str(&data)?;
let hints = json.get("hints").unwrap().as_object();
for (_, hint_value) in hints.unwrap() {
for hint in hint_value.as_array().unwrap() {
let code = hint.get("code").unwrap().as_str().unwrap().to_string();
if subset == "all"
|| subset == "implemented" && implemented_hints.contains(&code)
|| subset == "unimplemented" && !implemented_hints.contains(&code)
{
result.insert(code);
}
let os: Os = serde_json::from_reader(BufReader::new(File::open("build/os_latest.json")?))
.expect("Failed to parse os_latest.json");
let hints = os.hints.into_values().flatten().map(|h| h.code.to_string()).collect::<HashSet<_>>();
for code in hints {
if subset == "all"
|| subset == "implemented" && implemented_hints.contains(&code)
|| subset == "unimplemented" && !implemented_hints.contains(&code)
|| subset == "whitelisted" && whitelisted_hints.contains(&code)
|| subset == "snos" && snos_hints.contains(&code)
{
result.insert(code);
}
}

Expand Down
21 changes: 9 additions & 12 deletions src/hints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,16 @@ use crate::io::InternalTransaction;
use crate::state::storage::TrieStorage;
use crate::state::trie::PedersenHash;

type HintImpl = fn(
&mut VirtualMachine,
&mut ExecutionScopes,
&HashMap<String, HintReference>,
&ApTracking,
&HashMap<String, Felt252>,
) -> Result<(), HintError>;

pub fn sn_hint_processor() -> BuiltinHintProcessor {
let hints: Box<
[(
&str,
fn(
&mut VirtualMachine,
&mut ExecutionScopes,
&HashMap<String, HintReference>,
&ApTracking,
&HashMap<String, Felt252>,
) -> Result<(), HintError>,
)],
> = Box::new([
let hints: Box<[(&str, HintImpl)]> = Box::new([
(ASSERT_TRANSACTION_HASH, assert_transaction_hash),
(CHAIN_ID, chain_id),
(CHECK_DEPRECATED_CLASS_HASH, check_deprecated_class_hash),
Expand Down

0 comments on commit e2fdc1f

Please sign in to comment.