Skip to content

Commit 2bd111b

Browse files
committed
Merge branch 'tomas/more-checked-arith' (#3214)
* origin/tomas/more-checked-arith: changelog: add #3214 doc/sdk: fix bare urls doc/gas: fix broken link apps: fix lint warnings apps: add lints namada: fix lint warnings namada: add lints vp_env: fix lint warnings vp_env: add lints tx_env: add lints ethereum_bridge: fix lint warnings ethereum_bridge: add lints ibc: fix lint warnings ibc: add lints vm_env: fix lint warnings vm_env: add lints state: fix lint warnings state: add lints token: fix lint warnings token: add lints proof_of_stake: fix lint warnings proof_of_stake: add lints governance: fix lint warnings governance: add lints account: fix lint warnings account: add lints shielded_token: fix lint warnings shielded_token: add lints trans_token: add lints parameters: add lints controller: fix lint warnings controller: add lints storage: fix lint warnings storage: add lints vote_ext: add lints tx: fix lints warnings tx: add lints gas: fix lints warning gas: add lints merkle_tree: fix lints warning merkle_tree: add lints crates: update for checked events gas events: use checked arith events: add lints replay_protection: add lints
2 parents 594b1bc + 860132b commit 2bd111b

File tree

127 files changed

+1464
-600
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+1464
-600
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Sanitized unchecked arithmetics and conversions in the codebase.
2+
([\#3214](https://github.com/anoma/namada/pull/3214))

Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/account/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22
//! using public key(s) and signature threshold (minimum number of signatures
33
//! needed to authorize an action) stored on-chain.
44
5+
#![doc(html_favicon_url = "https://dev.namada.net/master/favicon.png")]
6+
#![doc(html_logo_url = "https://dev.namada.net/master/rustdoc-logo.png")]
7+
#![deny(rustdoc::broken_intra_doc_links)]
8+
#![deny(rustdoc::private_intra_doc_links)]
9+
#![warn(
10+
missing_docs,
11+
rust_2018_idioms,
12+
clippy::cast_sign_loss,
13+
clippy::cast_possible_truncation,
14+
clippy::cast_possible_wrap,
15+
clippy::cast_lossless,
16+
clippy::arithmetic_side_effects
17+
)]
18+
519
mod storage;
620
mod storage_key;
721
mod types;

crates/account/src/storage.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Cryptographic signature keys storage API
22
33
use namada_core::storage;
4-
use namada_storage::{Result, StorageRead, StorageWrite};
4+
use namada_storage::{Result, ResultExt, StorageRead, StorageWrite};
55

66
use super::*;
77

@@ -31,7 +31,7 @@ where
3131
S: StorageWrite + StorageRead,
3232
{
3333
for (index, public_key) in public_keys.iter().enumerate() {
34-
let index = index as u8;
34+
let index = u8::try_from(index).into_storage_result()?;
3535
pks_handle(owner).insert(storage, index, public_key.clone())?;
3636
}
3737
let threshold_key = threshold_key(owner);
@@ -114,6 +114,7 @@ where
114114
S: StorageWrite + StorageRead,
115115
{
116116
let total_pks = pks_handle(owner).len(storage)?;
117+
let total_pks = u8::try_from(total_pks).into_storage_result()?;
117118
for index in 0..total_pks as u8 {
118119
pks_handle(owner).remove(storage, &index)?;
119120
}

crates/account/src/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub struct UpdateAccount {
5555
pub threshold: Option<u8>,
5656
}
5757

58+
#[allow(clippy::cast_possible_truncation)]
5859
#[cfg(any(test, feature = "testing"))]
5960
/// Tests and strategies for accounts
6061
pub mod tests {

crates/apps/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ serde_json = {workspace = true, features = ["raw_value"]}
138138
serde.workspace = true
139139
sha2.workspace = true
140140
signal-hook.workspace = true
141+
smooth-operator.workspace = true
141142
sysinfo.workspace = true
142143
tar.workspace = true
143144
tempfile.workspace = true

crates/apps/src/lib/bench_utils.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! Library code for benchmarks provides a wrapper of the ledger's shell
22
//! `BenchShell` and helper functions to generate transactions.
33
4+
#![allow(clippy::arithmetic_side_effects)]
5+
46
use std::cell::RefCell;
57
use std::collections::BTreeSet;
68
use std::fs::{File, OpenOptions};

crates/apps/src/lib/client/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(clippy::arithmetic_side_effects)]
2+
13
pub mod masp;
24
pub mod rpc;
35
pub mod tx;

crates/apps/src/lib/config/genesis.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ impl<'de> Deserialize<'de> for GenesisAddress {
9595
impl<'de> serde::de::Visitor<'de> for FieldVisitor {
9696
type Value = GenesisAddress;
9797

98-
fn expecting(&self, formatter: &mut Formatter) -> std::fmt::Result {
98+
fn expecting(
99+
&self,
100+
formatter: &mut Formatter<'_>,
101+
) -> std::fmt::Result {
99102
formatter.write_str(
100103
"a bech32m encoded public key or an established address",
101104
)
@@ -324,6 +327,7 @@ pub struct Parameters {
324327
///
325328
/// This includes adding the Ethereum bridge parameters and
326329
/// adding a specified number of validators.
330+
#[allow(clippy::arithmetic_side_effects)]
327331
#[cfg(all(any(test, feature = "benches"), not(feature = "integration")))]
328332
pub fn make_dev_genesis(
329333
num_validators: u64,

crates/apps/src/lib/config/genesis/chain.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,14 @@ impl Finalized {
254254
if !is_localhost {
255255
set_ip(&mut config.ledger.cometbft.rpc.laddr, "0.0.0.0");
256256
}
257-
set_port(&mut config.ledger.cometbft.rpc.laddr, first_port + 1);
258-
set_port(&mut config.ledger.cometbft.proxy_app, first_port + 2);
257+
set_port(
258+
&mut config.ledger.cometbft.rpc.laddr,
259+
first_port.checked_add(1).expect("Port must not overflow"),
260+
);
261+
set_port(
262+
&mut config.ledger.cometbft.proxy_app,
263+
first_port.checked_add(2).expect("Port must not overflow"),
264+
);
259265

260266
// Validator node should turned off peer exchange reactor
261267
config.ledger.cometbft.p2p.pex = false;
@@ -318,7 +324,10 @@ impl Finalized {
318324
.ok()
319325
.map(Hash::sha256);
320326

321-
let min_duration: i64 = 60 * 60 * 24 * 365 / (epochs_per_year as i64);
327+
let epy_i64 = i64::try_from(epochs_per_year)
328+
.expect("`epochs_per_year` must not exceed `i64::MAX`");
329+
#[allow(clippy::arithmetic_side_effects)]
330+
let min_duration: i64 = 60 * 60 * 24 * 365 / epy_i64;
322331
let epoch_duration = EpochDuration {
323332
min_num_of_blocks,
324333
min_duration: namada::core::time::Duration::seconds(min_duration)

0 commit comments

Comments
 (0)