From 3aac9736831da9f5aa65718c4ec353a60a25a15c Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Fri, 13 Oct 2023 14:34:36 -0400 Subject: [PATCH 1/2] Decorate error for nonce missing from the footprint. --- soroban-env-host/src/auth.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/soroban-env-host/src/auth.rs b/soroban-env-host/src/auth.rs index 057bb49b1..1a7c58e69 100644 --- a/soroban-env-host/src/auth.rs +++ b/soroban-env-host/src/auth.rs @@ -1704,7 +1704,7 @@ impl AccountAuthorizationTracker { fn snapshot(&self, budget: &Budget) -> Result { Ok(AccountAuthorizationTrackerSnapshot { invocation_tracker_root_snapshot: self.invocation_tracker.snapshot(budget)?, - // We need to snapshot authenctioncation and nocne-related fields as + // We need to snapshot authentication and nonce-related fields as // during the rollback the nonce might be 'un-consumed' during // the storage rollback. We don't snapshot `is_valid` since this is // not recoverable and nonce is never consumed for invalid @@ -1799,7 +1799,19 @@ impl Host { let live_until_ledger = live_until_ledger .max(self.get_min_live_until_ledger(xdr::ContractDataDurability::Temporary)?); self.with_mut_storage(|storage| { - if storage.has(&nonce_key, self.budget_ref())? { + if storage.has(&nonce_key, self.budget_ref()).map_err(|err| { + if err.error.is_type(ScErrorType::Storage) + && err.error.is_code(ScErrorCode::ExceededLimit) + { + return self.err( + ScErrorType::Storage, + ScErrorCode::ExceededLimit, + "trying to access nonce outside of footprint for address", + &[address.to_val()], + ); + } + err + })? { return Err(self.err( ScErrorType::Auth, ScErrorCode::ExistingValue, @@ -1857,6 +1869,7 @@ impl Host { #[cfg(any(test, feature = "testutils"))] use crate::{host::frame::ContractReentryMode, xdr::SorobanAuthorizedInvocation}; + #[cfg(any(test, feature = "testutils"))] impl Host { /// Invokes the reserved `__check_auth` function on a provided contract. From f1f435f5f657b70ce1ed0c08f2fbedec8bfc3213 Mon Sep 17 00:00:00 2001 From: Dmytro Kozhevin Date: Fri, 13 Oct 2023 15:32:34 -0400 Subject: [PATCH 2/2] Add more context to 'unknown object reference' error. This seems to be the only object error that is easy to encounter without tampering with `Val`s. --- soroban-env-host/src/host_object.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/soroban-env-host/src/host_object.rs b/soroban-env-host/src/host_object.rs index 25c2ee5d9..afb93f5fd 100644 --- a/soroban-env-host/src/host_object.rs +++ b/soroban-env-host/src/host_object.rs @@ -379,7 +379,7 @@ impl Host { Err(self.err( ScErrorType::Object, ScErrorCode::MissingValue, - "unknown object reference", + "unknown object reference, is it coming from a different environment?", &[payload_val], )) }