Skip to content

Remove backtraces feature #1967

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

Merged
merged 14 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 9 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: 1 addition & 3 deletions contracts/burner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ overflow-checks = true
default = []
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
cranelift = ["cosmwasm-vm/cranelift"]
# for quicker tests, cargo test --lib
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]


[dependencies]
cosmwasm-schema = { path = "../../packages/schema" }
Expand Down
3 changes: 0 additions & 3 deletions contracts/crypto-verify/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ overflow-checks = true
default = []
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
cranelift = ["cosmwasm-vm/cranelift"]
# for quicker tests, cargo test --lib
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]

[dependencies]
cosmwasm-schema = { path = "../../packages/schema" }
Expand Down
19 changes: 11 additions & 8 deletions contracts/crypto-verify/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,13 @@ mod tests {

let res = query(deps.as_ref(), mock_env(), verify_msg);
assert!(res.is_err());
assert_eq!(
assert!(matches!(
res.unwrap_err(),
StdError::VerificationErr {
source: VerificationError::InvalidPubkeyFormat
source: VerificationError::InvalidPubkeyFormat,
..
}
)
))
}

#[test]
Expand Down Expand Up @@ -605,12 +606,13 @@ mod tests {
};
let res = query(deps.as_ref(), mock_env(), verify_msg);
assert!(res.is_err());
assert_eq!(
assert!(matches!(
res.unwrap_err(),
StdError::VerificationErr {
source: VerificationError::InvalidPubkeyFormat,
..
}
)
))
}

#[test]
Expand Down Expand Up @@ -670,12 +672,13 @@ mod tests {
};
let res = query(deps.as_ref(), mock_env(), verify_msg);
assert!(res.is_err());
assert_eq!(
assert!(matches!(
res.unwrap_err(),
StdError::VerificationErr {
source: VerificationError::InvalidPubkeyFormat
source: VerificationError::InvalidPubkeyFormat,
..
}
)
))
}

#[test]
Expand Down
2 changes: 0 additions & 2 deletions contracts/cyberpunk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ overflow-checks = true
default = []
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
cranelift = ["cosmwasm-vm/cranelift"]
# For quicker tests, cargo test --lib. for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]

[dependencies]
cosmwasm-schema = { path = "../../packages/schema" }
Expand Down
3 changes: 0 additions & 3 deletions contracts/empty/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ overflow-checks = true
default = []
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
cranelift = ["cosmwasm-vm/cranelift"]
# for quicker tests, cargo test --lib
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]

[dependencies]
cosmwasm-schema = { path = "../../packages/schema" }
Expand Down
2 changes: 0 additions & 2 deletions contracts/floaty/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ overflow-checks = true
default = []
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
cranelift = ["cosmwasm-vm/cranelift"]
# For quicker tests, cargo test --lib. for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]

[dependencies]
cosmwasm-schema = { path = "../../packages/schema" }
Expand Down
2 changes: 0 additions & 2 deletions contracts/hackatom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ overflow-checks = true
default = []
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
cranelift = ["cosmwasm-vm/cranelift"]
# For quicker tests, cargo test --lib. for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]

[dependencies]
cosmwasm-schema = { path = "../../packages/schema" }
Expand Down
3 changes: 0 additions & 3 deletions contracts/ibc-reflect-send/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ overflow-checks = true
default = []
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
cranelift = ["cosmwasm-vm/cranelift"]
# for quicker tests, cargo test --lib
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]

[dependencies]
cosmwasm-schema = { path = "../../packages/schema" }
Expand Down
3 changes: 0 additions & 3 deletions contracts/ibc-reflect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ overflow-checks = true
default = []
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
cranelift = ["cosmwasm-vm/cranelift"]
# for quicker tests, cargo test --lib
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]

[dependencies]
cosmwasm-schema = { path = "../../packages/schema" }
Expand Down
4 changes: 1 addition & 3 deletions contracts/queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ overflow-checks = true
default = []
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
cranelift = ["cosmwasm-vm/cranelift"]
# For quicker tests, cargo test --lib. for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]
# this is to demonstrate conditional entry-points for cosmwasm-plus style
library = []

Expand All @@ -40,4 +38,4 @@ schemars = "0.8.3"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }

[dev-dependencies]
cosmwasm-vm = { path = "../../packages/vm", default-features = false, features = ["iterator"] }
cosmwasm-vm = { path = "../../packages/vm", default-features = false, features = ["iterator"] }
3 changes: 0 additions & 3 deletions contracts/reflect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ overflow-checks = true
default = []
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
cranelift = ["cosmwasm-vm/cranelift"]
# for quicker tests, cargo test --lib
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]

[dependencies]
cosmwasm-schema = { path = "../../packages/schema" }
Expand Down
3 changes: 0 additions & 3 deletions contracts/staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ overflow-checks = true
default = []
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
cranelift = ["cosmwasm-vm/cranelift"]
# for quicker tests, cargo test --lib
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]

[dependencies]
cosmwasm-schema = { path = "../../packages/schema" }
Expand Down
3 changes: 0 additions & 3 deletions contracts/virus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ overflow-checks = true
default = []
# Use cranelift backend instead of singlepass. This is required for development on 32 bit or ARM machines.
cranelift = ["cosmwasm-vm/cranelift"]
# for quicker tests, cargo test --lib
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces", "cosmwasm-vm/backtraces"]

[dependencies]
cosmwasm-schema = { path = "../../packages/schema" }
Expand Down
3 changes: 1 addition & 2 deletions docs/USING_COSMWASM_STD.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ in the dependency tree. Otherwise conflicting C exports are created.

## cosmwasm-std features

The libarary comes with the following features:
The library comes with the following features:

| Feature | Enabled by default | Description |
| ------------ | ------------------ | ------------------------------------------------------------------------- |
| iterator | x | Storage iterators |
| abort | x | A panic handler that aborts the contract execution with a helpful message |
| stargate | | Cosmos SDK 0.40+ features and IBC |
| staking | | Access to the staking module |
| backtraces | | Add backtraces to errors (for unit testing) |
| cosmwasm_1_1 | | Features that require CosmWasm 1.1+ on the chain |
| cosmwasm_1_2 | | Features that require CosmWasm 1.2+ on the chain |
| cosmwasm_1_3 | | Features that require CosmWasm 1.3+ on the chain |
Expand Down
4 changes: 0 additions & 4 deletions packages/crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ license = "Apache-2.0"

[features]
default = []
# backtraces provides much better context at runtime errors (in non-wasm code)
# at the cost of a bit of code size and performance.
# This feature requires Rust nightly because it depends on the unstable backtrace feature.
backtraces = []

[lib]
# See https://bheisler.github.io/criterion.rs/book/faq.html#cargo-bench-gives-unrecognized-option-errors-for-valid-command-line-options
Expand Down
26 changes: 26 additions & 0 deletions packages/crypto/src/backtrace.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use core::fmt::{Debug, Display, Formatter, Result};
use std::backtrace::Backtrace;

/// This wraps an actual backtrace to achieve two things:
/// - being able to fill this with a stub implementation in `no_std` environments
/// - being able to use this in conjunction with [`thiserror::Error`]
pub struct BT(Backtrace);

impl BT {
#[track_caller]
pub fn capture() -> Self {
BT(Backtrace::capture())
}
}

impl Debug for BT {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
Debug::fmt(&self.0, f)
}
}

impl Display for BT {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
Display::fmt(&self.0, f)
}
}
53 changes: 13 additions & 40 deletions packages/crypto/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#[cfg(feature = "backtraces")]
use std::backtrace::Backtrace;
use crate::BT;
use std::fmt::Debug;
use thiserror::Error;

Expand All @@ -8,81 +7,55 @@ pub type CryptoResult<T> = core::result::Result<T, CryptoError>;
#[derive(Error, Debug)]
pub enum CryptoError {
#[error("Batch verify error: {msg}")]
BatchErr {
msg: String,
#[cfg(feature = "backtraces")]
backtrace: Backtrace,
},
BatchErr { msg: String, backtrace: BT },
#[error("Crypto error: {msg}")]
GenericErr {
msg: String,
#[cfg(feature = "backtraces")]
backtrace: Backtrace,
},
GenericErr { msg: String, backtrace: BT },
#[error("Invalid hash format")]
InvalidHashFormat {
#[cfg(feature = "backtraces")]
backtrace: Backtrace,
},
InvalidHashFormat { backtrace: BT },
#[error("Invalid public key format")]
InvalidPubkeyFormat {
#[cfg(feature = "backtraces")]
backtrace: Backtrace,
},
InvalidPubkeyFormat { backtrace: BT },
#[error("Invalid signature format")]
InvalidSignatureFormat {
#[cfg(feature = "backtraces")]
backtrace: Backtrace,
},
InvalidSignatureFormat { backtrace: BT },
#[error("Invalid recovery parameter. Supported values: 0 and 1.")]
InvalidRecoveryParam {
#[cfg(feature = "backtraces")]
backtrace: Backtrace,
},
InvalidRecoveryParam { backtrace: BT },
}

impl CryptoError {
pub fn batch_err(msg: impl Into<String>) -> Self {
CryptoError::BatchErr {
msg: msg.into(),
#[cfg(feature = "backtraces")]
backtrace: Backtrace::capture(),
backtrace: BT::capture(),
}
}

pub fn generic_err(msg: impl Into<String>) -> Self {
CryptoError::GenericErr {
msg: msg.into(),
#[cfg(feature = "backtraces")]
backtrace: Backtrace::capture(),
backtrace: BT::capture(),
}
}

pub fn invalid_hash_format() -> Self {
CryptoError::InvalidHashFormat {
#[cfg(feature = "backtraces")]
backtrace: Backtrace::capture(),
backtrace: BT::capture(),
}
}

pub fn invalid_pubkey_format() -> Self {
CryptoError::InvalidPubkeyFormat {
#[cfg(feature = "backtraces")]
backtrace: Backtrace::capture(),
backtrace: BT::capture(),
}
}

pub fn invalid_signature_format() -> Self {
CryptoError::InvalidSignatureFormat {
#[cfg(feature = "backtraces")]
backtrace: Backtrace::capture(),
backtrace: BT::capture(),
}
}

pub fn invalid_recovery_param() -> Self {
CryptoError::InvalidRecoveryParam {
#[cfg(feature = "backtraces")]
backtrace: Backtrace::capture(),
backtrace: BT::capture(),
}
}

Expand Down
5 changes: 2 additions & 3 deletions packages/crypto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
//! Please don't use any of these types directly, as
//! they might change frequently, or be removed in the future.
//! This crate does not adhere to semantic versioning.
#![cfg_attr(feature = "backtraces", feature(error_generic_member_access))]
#![cfg_attr(feature = "backtraces", feature(provide_any))]

mod backtrace;
mod ed25519;
mod errors;
mod identity_digest;
Expand All @@ -20,3 +18,4 @@ pub use crate::errors::{CryptoError, CryptoResult};
pub use crate::secp256k1::{secp256k1_recover_pubkey, secp256k1_verify};
#[doc(hidden)]
pub use crate::secp256k1::{ECDSA_PUBKEY_MAX_LEN, ECDSA_SIGNATURE_LEN, MESSAGE_HASH_MAX_LEN};
pub(crate) use backtrace::BT;
14 changes: 2 additions & 12 deletions packages/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ iterator = []
# CosmosMsg types, and new QueryRequest types. This should only be enabled on contracts
# that require these types, so other contracts can be used on systems with eg. PoA consensus
staking = []
# backtraces provides much better context at runtime errors (in non-wasm code)
# at the cost of a bit of code size and performance.
# This feature requires Rust nightly because it depends on the unstable backtrace feature.
backtraces = []
# stargate enables stargate-dependent messages and queries, like raw protobuf messages
# as well as ibc-related functionality
stargate = []
Expand Down Expand Up @@ -54,10 +50,7 @@ forward_ref = "1"
hex = "0.4"
schemars = "0.8.3"
sha2 = "0.10.3"
serde = { version = "1.0.103", default-features = false, features = [
"derive",
"alloc",
] }
serde = { version = "1.0.103", default-features = false, features = ["derive", "alloc"] }
serde-json-wasm = { version = "1.0.0" }
thiserror = "1.0.26"
bnum = "0.8.0"
Expand All @@ -70,10 +63,7 @@ cosmwasm-crypto = { path = "../crypto", version = "1.5.0" }
[dev-dependencies]
cosmwasm-schema = { path = "../schema" }
# The chrono dependency is only used in an example, which Rust compiles for us. If this causes trouble, remove it.
chrono = { version = "0.4", default-features = false, features = [
"alloc",
"std",
] }
chrono = { version = "0.4", default-features = false, features = ["alloc", "std"] }
crc32fast = "1.3.2"
hex-literal = "0.3.1"
serde_json = "1.0.81"
2 changes: 1 addition & 1 deletion packages/std/src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ mod tests {
("cmFuZ", "Encoded text cannot have a 6-bit remainder."),
] {
match Binary::from_base64(invalid_base64) {
Err(StdError::InvalidBase64 { msg }) => assert_eq!(want, msg),
Err(StdError::InvalidBase64 { msg, .. }) => assert_eq!(want, msg),
result => panic!("Unexpected result: {result:?}"),
}
}
Expand Down
Loading