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 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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ and this project adheres to
`AnalysisReport::required_capabilities` a `BTreeSet`. ([#1949])
- cosmwasm-std: Add `Checksum` type and change type of
`CodeInfoResponse::checksum` to that. ([#1944])
- cosmwasm-std: Removed `backtraces` feature, use the `RUST_BACKTRACE=1` env
variable instead. Error variants that previously only contained a `backtrace`
field with the feature enabled now always contain it. ([#1967])
- cosmwasm-vm: Removed `backtraces` feature, use the `RUST_BACKTRACE=1` env
variable instead. All `VmError` variants now have a `backtrace` field.
([#1967])

[#1874]: https://github.com/CosmWasm/cosmwasm/pull/1874
[#1876]: https://github.com/CosmWasm/cosmwasm/pull/1876
Expand All @@ -73,6 +79,7 @@ and this project adheres to
[#1941]: https://github.com/CosmWasm/cosmwasm/pull/1941
[#1944]: https://github.com/CosmWasm/cosmwasm/pull/1944
[#1949]: https://github.com/CosmWasm/cosmwasm/pull/1949
[#1967]: https://github.com/CosmWasm/cosmwasm/pull/1967

### Removed

Expand Down
12 changes: 11 additions & 1 deletion MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ major releases of `cosmwasm`. Note that you can also view the

If you were using cosmwasm-std's `ibc3` feature, you can remove it, as it is
the default now. Depending on your usage, you might have to enable the
`stargate` feature instead, since it was previously implied by `ibc3`.
`stargate` feature instead, since it was previously implied by `ibc3`. Also
remove any uses of the `backtraces` feature. You can use a `RUST_BACKTRACE=1`
env variable for this now.

- `ContractInfoResponse::new` now takes all fields of the response as
parameters:
Expand Down Expand Up @@ -125,6 +127,14 @@ major releases of `cosmwasm`. Note that you can also view the
+CosmosMsg::Any(AnyMsg { type_url, value })
```

- Replace all direct construction of `StdError` with use of the corresponding
constructor:

```diff
-StdError::GenericErr { msg }
+StdError::generic_err(msg)
```

## 1.4.x -> 1.5.0

- Update `cosmwasm-*` dependencies in Cargo.toml (skip the ones you don't use):
Expand Down
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;
Loading