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

Add a function to inherit the recording auth settings when switching to recording mode #1495

Merged
merged 14 commits into from
Dec 11, 2024
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ jobs:
steps:
- uses: actions/checkout@v3
- run: rustup update
- uses: stellar/binaries@v29
- uses: stellar/binaries@v33
with:
name: cargo-semver-checks
version: 0.35.0
version: 0.37.0
- run: cargo semver-checks --exclude soroban-simulation

build-and-test:
Expand Down
3 changes: 1 addition & 2 deletions soroban-env-common/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ pub trait EnvBase: Sized + Clone {
/// This trait is used by macro-generated dispatch and forwarding functions to
/// check arguments being passed to the Env. The default implementations call
/// through to the Env integrity-checking functions.

pub trait CheckedEnvArg: Sized {
fn check_env_arg<E: crate::Env>(self, _e: &E) -> Result<Self, E::Error> {
Ok(self)
Expand Down Expand Up @@ -327,7 +326,7 @@ generate_call_macro_with_all_host_functions!("env.json");
///////////////////////////////////////////////////////////////////////////////
/// X-macro use: defining trait Env
///////////////////////////////////////////////////////////////////////////////

//
// This is a helper macro used only by generate_env_trait below. It consumes
// a token-tree of the form:
//
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-common/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<'a> From<ScValObjRef<'a>> for &'a ScVal {
}
}

impl<'a> AsRef<ScVal> for ScValObjRef<'a> {
impl AsRef<ScVal> for ScValObjRef<'_> {
fn as_ref(&self) -> &ScVal {
self.0
}
Expand Down
1 change: 1 addition & 0 deletions soroban-env-common/src/storage_type.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(non_local_definitions)]
use crate::{
declare_wasmi_marshal_for_enum,
xdr::{ContractDataDurability, ScErrorCode, ScErrorType},
Expand Down
6 changes: 3 additions & 3 deletions soroban-env-common/src/vmcaller_env.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(clippy::needless_lifetimes)]
#[cfg(feature = "wasmi")]
use crate::xdr::{ScErrorCode, ScErrorType};

Expand All @@ -24,7 +25,6 @@ use core::marker::PhantomData;
/// allows code to import and use `Env` directly (such as the native
/// contract) to call host methods without having to write `VmCaller::none()`
/// everywhere.

#[cfg(feature = "wasmi")]
pub struct VmCaller<'a, T>(pub Option<wasmi::Caller<'a, T>>);
#[cfg(feature = "wasmi")]
Expand Down Expand Up @@ -68,7 +68,7 @@ impl<'a, T> VmCaller<'a, T> {
///////////////////////////////////////////////////////////////////////////////
/// X-macro use: defining trait VmCallerEnv
///////////////////////////////////////////////////////////////////////////////

//
// This is a helper macro used only by generate_vmcaller_checked_env_trait
// below. It consumes a token-tree of the form:
//
Expand Down Expand Up @@ -160,7 +160,7 @@ call_macro_with_all_host_functions! { generate_vmcaller_checked_env_trait }
///////////////////////////////////////////////////////////////////////////////
/// X-macro use: impl<E> Env for VmCallerEnv<E>
///////////////////////////////////////////////////////////////////////////////

//
// This is a helper macro used only by
// generate_impl_checked_env_for_vmcaller_checked_env below. It consumes a
// token-tree of the form:
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-common/tests/no_std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// panic handler has been already linked in. If soroban_env_common imports
/// libstd by accident then this crate will fail to build because there will be
/// two panic hanlders.

//
// Import a type from soroban_env_common so that the compiler includes it in the
// build.
#[allow(unused_imports)]
Expand Down
4 changes: 2 additions & 2 deletions soroban-env-guest/src/guest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl EnvBase for Guest {
///////////////////////////////////////////////////////////////////////////////
/// X-macro use: impl Env for Guest
///////////////////////////////////////////////////////////////////////////////

//
// This is a helper macro used only by impl_env_for_guest below. It consumes a
// token-tree of the form:
//
Expand Down Expand Up @@ -273,7 +273,7 @@ call_macro_with_all_host_functions! { impl_env_for_guest }
///////////////////////////////////////////////////////////////////////////////
/// X-macro use: extern mod blocks
///////////////////////////////////////////////////////////////////////////////

//
// This is a helper macro used only by impl_env_for_guest below. It consumes a
// token-tree of the form:
//
Expand Down
22 changes: 22 additions & 0 deletions soroban-env-host/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2335,6 +2335,28 @@ impl Host {
Ok(self.try_borrow_authorization_manager()?.clone())
}

/// Switches host to the recording authorization mode and inherits the
/// recording mode settings from the provided authorization manager settings
/// in case if it used the recording mode.
///
/// This is similar to `switch_to_recording_auth`, but should be preferred
/// to use in conjunction with `snapshot_auth_manager`, such that the
/// recording mode settings are not overridden.
pub fn switch_to_recording_auth_inherited_from_snapshot(
&self,
auth_manager_snapshot: &AuthorizationManager,
) -> Result<(), HostError> {
let disable_non_root_auth = match &auth_manager_snapshot.mode {
AuthorizationMode::Enforcing => true,
AuthorizationMode::Recording(recording_auth_info) => {
recording_auth_info.disable_non_root_auth
}
};
*self.try_borrow_authorization_manager_mut()? =
AuthorizationManager::new_recording(disable_non_root_auth);
Ok(())
}

/// Replaces authorization manager with the provided new instance.
///
/// Use this in conjunction with `snapshot_auth_manager` to do authorized
Expand Down
1 change: 1 addition & 0 deletions soroban-env-host/src/builtin_contracts/contract_error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(non_local_definitions)]
use num_derive::FromPrimitive;
use soroban_env_common::Error;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use super::storage_types::{BalanceValue, BALANCE_EXTEND_AMOUNT, BALANCE_TTL_THRE
/// semantics have been implemented for these balances. If the asset issuer has
/// the AUTH_REQUIRED flag set, then the non-account identifier must first be authorized
/// by the issuer/admin before it's allowed to hold a balance.

//
// Metering: covered by components.
pub(crate) fn read_balance(e: &Host, addr: Address) -> Result<i128, HostError> {
match addr.to_sc_address()? {
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-host/src/crypto/bls12_381.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub(crate) const FR_SERIALIZED_SIZE: usize = 32;

#[inline(always)]
fn units_of_fp<const EXPECTED_SIZE: usize>() -> u64 {
((EXPECTED_SIZE + FP_SERIALIZED_SIZE - 1) / FP_SERIALIZED_SIZE) as u64
EXPECTED_SIZE.div_ceil(FP_SERIALIZED_SIZE) as u64
}

impl Host {
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-host/src/e2e_invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ struct StorageMapSnapshotSource<'a> {
map: &'a StorageMap,
}

impl<'a> SnapshotSource for StorageMapSnapshotSource<'a> {
impl SnapshotSource for StorageMapSnapshotSource<'_> {
fn get(&self, key: &Rc<LedgerKey>) -> Result<Option<EntryWithLiveUntil>, HostError> {
if let Some(Some((entry, live_until_ledger))) =
self.map.get::<Rc<LedgerKey>>(key, self.budget)?
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-host/src/fees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// This is technically not part of the Soroban host and is provided here for
/// the sake of sharing between the systems that run Soroban host (such as
/// Stellar core or Soroban RPC service).

///
/// Rough estimate of the base size of any transaction result in the archives
/// (independent of the transaction envelope size).
pub const TX_BASE_RESULT_SIZE: u32 = 300;
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-host/src/host/invocation_metering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub(crate) struct InvocationMeterScope<'a> {
host: &'a Host,
}

impl<'a> Drop for InvocationMeterScope<'a> {
impl Drop for InvocationMeterScope<'_> {
fn drop(&mut self) {
self.meter.finish_invocation(self.host);
}
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-host/src/host/metered_xdr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct MeteredWrite<'a, W: Write> {
w: &'a mut W,
}

impl<'a, W> Write for MeteredWrite<'a, W>
impl<W> Write for MeteredWrite<'_, W>
where
W: Write,
{
Expand Down
6 changes: 3 additions & 3 deletions soroban-env-host/src/host/trace/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::{TraceEvent, TraceState};
use crate::{host::Frame, xdr::ContractExecutable, Symbol, SymbolObject, SymbolSmall, Val};
use core::fmt::{Debug, Display};

impl<'a> Debug for TraceEvent<'a> {
impl Debug for TraceEvent<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
TraceEvent::Begin => write!(f, "TraceEvent::Begin"),
Expand Down Expand Up @@ -86,7 +86,7 @@ impl Display for FrameId {
}
}

impl<'a> TraceEvent<'a> {
impl TraceEvent<'_> {
pub fn is_begin(&self) -> bool {
match self {
TraceEvent::Begin => true,
Expand Down Expand Up @@ -146,7 +146,7 @@ impl<'a> TraceEvent<'a> {
}
}

impl<'a> Display for TraceEvent<'a> {
impl Display for TraceEvent<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
TraceEvent::PushCtx(ctx) => {
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-host/src/testutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ impl Host {
let prev_source_account = self.source_account_id()?;
// Use recording auth to skip specifying the auth payload.
let prev_auth_manager = self.snapshot_auth_manager()?;
self.switch_to_recording_auth(true)?;
self.switch_to_recording_auth_inherited_from_snapshot(&prev_auth_manager)?;

let wasm_hash = self.upload_wasm(self.bytes_new_from_slice(contract_wasm)?)?;
self.set_source_account(account.clone())?;
Expand Down
1 change: 0 additions & 1 deletion soroban-env-host/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ impl Vm {
/// With the introduction of the granular cost inputs this method
/// should only be used for the one-off full parses of the new Wasms
/// during the initial upload verification.

pub fn new(host: &Host, contract_id: Hash, wasm: &[u8]) -> Result<Rc<Self>, HostError> {
let cost_inputs = VersionedContractCodeCostInputs::V0 {
wasm_bytes: wasm.len(),
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-host/src/vm/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl RelativeObjectConversion for U32Val {}
///////////////////////////////////////////////////////////////////////////////
/// X-macro use: dispatch functions
///////////////////////////////////////////////////////////////////////////////

//
// This is a callback macro that pattern-matches the token-tree passed by the
// x-macro (call_macro_with_all_host_functions) and produces a suite of
// dispatch-function definitions.
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-host/src/vm/func_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ macro_rules! host_function_info_helper {
///////////////////////////////////////////////////////////////////////////////
/// X-macro use: static HOST_FUNCTIONS array of HostFuncInfo
///////////////////////////////////////////////////////////////////////////////

//
// This is a callback macro that pattern-matches the token-tree passed by the
// x-macro (call_macro_with_all_host_functions) and produces a suite of
// dispatch-function definitions.
Expand Down
8 changes: 4 additions & 4 deletions soroban-simulation/src/snapshot_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ enum SnapshotSourceHolder<'a> {
Rc(Rc<dyn SnapshotSource>),
}

impl<'a> SnapshotSource for SnapshotSourceHolder<'a> {
impl SnapshotSource for SnapshotSourceHolder<'_> {
fn get(&self, key: &Rc<LedgerKey>) -> Result<Option<EntryWithLiveUntil>, HostError> {
match self {
SnapshotSourceHolder::Ref(r) => r.get(key),
Expand Down Expand Up @@ -216,7 +216,7 @@ impl<'a, T: SnapshotSourceWithArchive> SimulationSnapshotSourceWithArchive<'a, T
}
}

impl<'a> SnapshotSource for SimulationSnapshotSource<'a> {
impl SnapshotSource for SimulationSnapshotSource<'_> {
fn get(&self, key: &Rc<LedgerKey>) -> Result<Option<EntryWithLiveUntil>, HostError> {
Ok(self
.entry_updater
Expand All @@ -225,8 +225,8 @@ impl<'a> SnapshotSource for SimulationSnapshotSource<'a> {
}
}

impl<'a, T: SnapshotSourceWithArchive> SnapshotSourceWithArchive
for SimulationSnapshotSourceWithArchive<'a, T>
impl<T: SnapshotSourceWithArchive> SnapshotSourceWithArchive
for SimulationSnapshotSourceWithArchive<'_, T>
{
fn get_including_archived(
&self,
Expand Down
Loading