Skip to content

Commit

Permalink
Minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
graydon committed Sep 28, 2023
1 parent 35f83bc commit 7b1d7ba
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
9 changes: 4 additions & 5 deletions soroban-env-host/src/host/metered_xdr.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
use crate::{
budget::Budget,
xdr::ContractCostType,
xdr::{ReadXdr, ScBytes, WriteXdr},
xdr::{
ContractCostType, DepthLimitedWrite, ReadXdr, ScBytes, ScErrorCode, ScErrorType, WriteXdr,
DEFAULT_XDR_RW_DEPTH_LIMIT,
},
BytesObject, Host, HostError,
};
use std::io::Write;

use sha2::{Digest, Sha256};
use soroban_env_common::xdr::{
DepthLimitedWrite, ScErrorCode, ScErrorType, DEFAULT_XDR_RW_DEPTH_LIMIT,
};

struct MeteredWrite<'a, W: Write> {
budget: &'a Budget,
Expand Down
16 changes: 5 additions & 11 deletions soroban-env-host/src/host/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,10 @@ impl Host {
a: usize,
b: usize,
) -> Result<usize, HostError> {
let lim = u32::MAX as usize;
if a > lim || b > lim || a > (lim - b) {
Err(self.err(
ScErrorType::Value,
ScErrorCode::ExceededLimit,
"sum of sizes exceeds u32::MAX",
&[],
))
} else {
Ok(a + b)
}
let a = u32::try_from(a).map_err(|_| self.err_arith_overflow())?;
let b = u32::try_from(b).map_err(|_| self.err_arith_overflow())?;
a.checked_add(b)
.ok_or_else(|| self.err_arith_overflow())
.map(|u| u as usize)
}
}
11 changes: 4 additions & 7 deletions soroban-env-host/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
//! crate for use by host (or contract local-testing) code. Most of the type and
//! module definitions visible here are actually defined in the common crate.
//!
//! It may seem unusual to configure a contract host _without_ a VM, but this
//! configuration makes more sense when considering that Soroban supports a
//! "local testing" configuration where host and guest code are _both compiled
//! natively_ and linked together for a faster and richer debugging and testing
//! experience. When testing this way, developers may also wish to enable the
//! `"testutils"` feature, which enables an interface on [Host] for registering
//! other test contracts by ID.
//! When unit-testing contracts natively (not using wasm), developers may also
//! wish to enable the `"testutils"` feature, which enables an interface on
//! [Host] for registering other test contracts by ID.
//!
//! The [Host] type provides some facilities above and beyond just the [Env]
//! trait, including:
Expand Down Expand Up @@ -55,6 +51,7 @@ pub mod auth;
pub mod vm;
pub use vm::Vm;
#[cfg(any(test, feature = "testutils"))]
#[doc(hidden)]
pub mod cost_runner;
pub mod storage;
#[cfg(test)]
Expand Down

0 comments on commit 7b1d7ba

Please sign in to comment.