Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(preimage): Traces #13

Merged
merged 2 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/mipsevm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ preimage-oracle = { path = "../preimage" }

# misc
anyhow = "1.0.75"
tracing = "0.1.37"
tracing = { version = "0.1.37", optional = true }

[dev-dependencies]
rand = "0.8.5"
criterion = { version = "0.5.1", features = ["html_reports"] }

[features]
tracing = []
tracing = ["dep:tracing"]

[[bench]]
name = "memory"
Expand Down
16 changes: 3 additions & 13 deletions crates/mipsevm/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ impl MipsEVM<CacheDB<EmptyDB>> {
/// execution.
pub fn step(&mut self, witness: StepWitness) -> Result<B256> {
if witness.has_preimage() {
#[cfg(feature = "tracing")]
tracing::info!(
crate::debug!(
target: "mipsevm::evm",
"Reading preimage key {:x} at offset {}",
witness.preimage_key,
Expand All @@ -129,11 +128,7 @@ impl MipsEVM<CacheDB<EmptyDB>> {
})?;
}

#[cfg(feature = "tracing")]
tracing::debug!(
target: "mipsevm::evm",
"Performing EVM step",
);
crate::debug!(target: "mipsevm::evm", "Performing EVM step");

let step_input = witness.encode_step_input();
self.fill_tx_env(TransactTo::Call(MIPS_ADDR.into()), step_input.0);
Expand All @@ -151,12 +146,7 @@ impl MipsEVM<CacheDB<EmptyDB>> {
{
let output = B256::from_slice(&output);

#[cfg(feature = "tracing")]
tracing::debug!(
target: "mipsevm::evm",
"EVM step successful with resulting post-state hash: {:x}",
output,
);
crate::debug!(target: "mipsevm::evm", "EVM step successful with resulting post-state hash: {:x}", output);

if logs.len() != 1 {
anyhow::bail!("Expected 1 log, got {}", logs.len());
Expand Down
2 changes: 2 additions & 0 deletions crates/mipsevm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#![feature(generic_const_exprs)]
#![allow(incomplete_features, dead_code)]

pub(crate) mod traces;

mod memory;
pub use self::memory::Memory;

Expand Down
49 changes: 49 additions & 0 deletions crates/mipsevm/src/traces.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/// Performs a tracing debug if the `tracing` feature is enabled.
#[macro_export]
macro_rules! debug {
($($arg:tt)*) => {
#[cfg(feature = "tracing")]
tracing::debug!($($arg)*);
};
}
pub use debug;

/// Performs a tracing info if the `tracing` feature is enabled.
#[macro_export]
macro_rules! info {
($($arg:tt)*) => {
#[cfg(feature = "tracing")]
tracing::info!($($arg)*);
};
}
pub use info;

/// Performs a tracing error if the `tracing` feature is enabled.
#[macro_export]
macro_rules! error {
($($arg:tt)*) => {
#[cfg(feature = "tracing")]
tracing::error!($($arg)*);
};
}
pub use error;

/// Performs a tracing warn if the `tracing` feature is enabled.
#[macro_export]
macro_rules! warn {
($($arg:tt)*) => {
#[cfg(feature = "tracing")]
tracing::warn!($($arg)*);
};
}
pub use crate::warn;

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_debug() {
debug!("test");
}
}
13 changes: 3 additions & 10 deletions crates/mipsevm/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,18 @@ impl StepWitness {
/// - `None` if the [StepWitness] does not have a preimage request.
pub fn encode_preimage_oracle_input(&self) -> Option<Bytes> {
if self.preimage_key == B256::ZERO {
#[cfg(feature = "tracing")]
tracing::warn!("Cannot encode preimage oracle input without preimage");
crate::error!(target: "mipsevm::step_witness", "Cannot encode preimage oracle input without preimage key");
return None;
}

match KeyType::from(self.preimage_key[0]) {
KeyType::_Illegal => {
#[cfg(feature = "tracing")]
tracing::error!("Illegal key type");
crate::error!(target: "mipsevm::step_witness", "Illegal key type");
None
}
KeyType::Local => {
if self.preimage_value.len() > 32 + 8 {
#[cfg(feature = "tracing")]
tracing::error!(
target: "mipsevm::step_witness",
"Local preimage value exceeds maximum size of 32 bytes with key 0x{:x}",
self.preimage_key
);
crate::error!(target: "mipsevm::step_witness", "Local preimage value exceeds maximum size of 32 bytes with key 0x{:x}", self.preimage_key);
return None;
}

Expand Down
4 changes: 2 additions & 2 deletions crates/preimage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ tokio = { version = "1.32.0", features = ["full"] }

# misc
anyhow = "1.0.75"
tracing = "0.1.37"
tracing = { version = "0.1.37", optional = true }

[dev-dependencies]
rand = "0.8.5"

[features]
tracing = []
tracing = ["dep:tracing"]
3 changes: 3 additions & 0 deletions crates/preimage/src/hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ impl Hinter for HintWriter {
hint_bytes[0..4].copy_from_slice((hint.len() as u32).to_be_bytes().as_ref());
hint_bytes[4..].copy_from_slice(hint);

crate::debug!("Sending hint: {:?}", hint_bytes);
self.tx.send(hint_bytes)?;

let n = self.rx.recv()?;
if n.len() != 1 {
crate::error!("Failed to read hint ack, received response: {:?}", n);
anyhow::bail!(
"Failed to read invalid pre-image hint ack, received response: {:?}",
n
Expand Down Expand Up @@ -74,6 +76,7 @@ impl HintReader {
if let Err(e) = router(&payload) {
// Write back on error to unblock the hint writer.
self.tx.send(vec![0])?;
crate::error!("Failed to handle hint: {:?}", e);
anyhow::bail!("Failed to handle hint: {:?}", e);
}

Expand Down
2 changes: 2 additions & 0 deletions crates/preimage/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![doc = include_str!("../README.md")]
#![allow(dead_code, unused_variables)]

pub(crate) mod traces;

mod oracle;
pub use oracle::{OracleClient, OracleServer};

Expand Down
49 changes: 49 additions & 0 deletions crates/preimage/src/traces.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/// Performs a tracing debug if the `tracing` feature is enabled.
#[macro_export]
macro_rules! debug {
($($arg:tt)*) => {
#[cfg(feature = "tracing")]
tracing::debug!($($arg)*);
};
}
pub use debug;

/// Performs a tracing info if the `tracing` feature is enabled.
#[macro_export]
macro_rules! info {
($($arg:tt)*) => {
#[cfg(feature = "tracing")]
tracing::info!($($arg)*);
};
}
pub use info;

/// Performs a tracing error if the `tracing` feature is enabled.
#[macro_export]
macro_rules! error {
($($arg:tt)*) => {
#[cfg(feature = "tracing")]
tracing::error!($($arg)*);
};
}
pub use error;

/// Performs a tracing warn if the `tracing` feature is enabled.
#[macro_export]
macro_rules! warn {
($($arg:tt)*) => {
#[cfg(feature = "tracing")]
tracing::warn!($($arg)*);
};
}
pub use crate::warn;

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_debug() {
debug!("test");
}
}
Loading