From a3f9a8dcd5744d141002222f62884b81109cabbf Mon Sep 17 00:00:00 2001 From: Serge Radinovich <47865535+sergerad@users.noreply.github.com> Date: Mon, 4 Nov 2024 15:31:31 +1300 Subject: [PATCH] Replace regex in trie diff main (#758) * Replace trie diff regex * RM previous regex crate --- Cargo.lock | 25 ++++++++++++++++++++++++- zero/Cargo.toml | 2 +- zero/src/bin/trie_diff.rs | 11 ++++++----- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc83b02b7..d64c3c1b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2861,6 +2861,29 @@ dependencies = [ "waker-fn", ] +[[package]] +name = "lazy-regex" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d8e41c97e6bc7ecb552016274b99fbb5d035e8de288c582d9b933af6677bfda" +dependencies = [ + "lazy-regex-proc_macros", + "once_cell", + "regex", +] + +[[package]] +name = "lazy-regex-proc_macros" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76e1d8b05d672c53cb9c7b920bbba8783845ae4f0b076e02a3db1d02c81b4163" +dependencies = [ + "proc-macro2", + "quote", + "regex", + "syn 2.0.77", +] + [[package]] name = "lazy_static" version = "1.5.0" @@ -5893,6 +5916,7 @@ dependencies = [ "itertools 0.13.0", "jemallocator", "keccak-hash 0.10.0", + "lazy-regex", "lru", "mockall", "mpt_trie", @@ -5902,7 +5926,6 @@ dependencies = [ "plonky2", "plonky2_maybe_rayon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "primitive-types 0.12.2", - "regex", "rlp", "ruint", "serde", diff --git a/zero/Cargo.toml b/zero/Cargo.toml index 88c8c580b..96d3bdeba 100644 --- a/zero/Cargo.toml +++ b/zero/Cargo.toml @@ -26,6 +26,7 @@ hashbrown.workspace = true hex.workspace = true itertools.workspace = true keccak-hash.workspace = true +lazy-regex = "3.3.0" lru.workspace = true mpt_trie.workspace = true num-traits.workspace = true @@ -33,7 +34,6 @@ once_cell.workspace = true paladin-core.workspace = true plonky2.workspace = true plonky2_maybe_rayon.workspace = true -regex = "1.5.4" rlp.workspace = true ruint = { workspace = true, features = ["num-traits", "primitive-types"] } serde.workspace = true diff --git a/zero/src/bin/trie_diff.rs b/zero/src/bin/trie_diff.rs index e580684d2..480441486 100644 --- a/zero/src/bin/trie_diff.rs +++ b/zero/src/bin/trie_diff.rs @@ -20,9 +20,9 @@ use anyhow::Result; use clap::{Parser, ValueHint}; use evm_arithmetization::generation::DebugOutputTries; use futures::{future, TryStreamExt}; +use lazy_regex::regex_captures; use paladin::directive::{Directive, IndexedStream}; use paladin::runtime::Runtime; -use regex::Regex; use trace_decoder::observer::TriesObserver; use tracing::{error, info}; use zero::ops::register; @@ -132,10 +132,11 @@ async fn main() -> Result<()> { { // Try to parse block and batch index from error message. let error_message = e2.to_string(); - let re = Regex::new(r"block:(\d+) batch:(\d+)")?; - if let Some(cap) = re.captures(&error_message) { - let block_number: u64 = cap[1].parse()?; - let batch_index: usize = cap[2].parse()?; + if let Some((_, block_number, block_index)) = + regex_captures!(r"block:(\d+) batch:(\d+)", error_message.as_str()) + { + let block_number: u64 = block_number.parse()?; + let batch_index: usize = block_index.parse()?; let prover_tries = zero::debug_utils::load_tries_from_disk(block_number, batch_index)?;