diff --git a/internal/cmd/dry_run.go b/internal/cmd/dry_run.go index 650d4546..bc2b72da 100644 --- a/internal/cmd/dry_run.go +++ b/internal/cmd/dry_run.go @@ -74,7 +74,7 @@ func runDryRun(cmd *cobra.Command, args []string) error { } // Validate envelope is parseable - envBytes, err := base64.StdEncoding.DecodeString(envXdrB64) + envBytes, err := base64.StdEncoding.Strict().DecodeString(envXdrB64) if err != nil { return errors.WrapUnmarshalFailed(err, "envelope base64") } diff --git a/simulator/Cargo.toml b/simulator/Cargo.toml index cc4d837a..1a5a313f 100644 --- a/simulator/Cargo.toml +++ b/simulator/Cargo.toml @@ -21,7 +21,7 @@ nursery = "warn" # HostedContractEvent.failed_call field that this simulator relies on. # We accept any release in the 21-25 range so the binary stays compatible # with both mainnet protocol 21 and subsequent minor protocol bumps. -soroban-env-host = { version = ">=21.0, <26" } # Updated to latest version +soroban-env-host = { version = ">=21.0, <26", features = ["testutils"] } # Updated to latest version base64 = "0.21" clap = { version = "4.4", features = ["derive"] } serde = { version = "1.0", features = ["derive"] } diff --git a/simulator/src/runner.rs b/simulator/src/runner.rs index bebc6343..c99c69f4 100644 --- a/simulator/src/runner.rs +++ b/simulator/src/runner.rs @@ -57,6 +57,18 @@ impl SimHost { host.set_diagnostic_level(DiagnosticLevel::Debug) .expect("failed to set diagnostic level"); + // Hook memory_limit into the Budget tracking mechanism via reset_limits() + if let Some(mem_limit) = memory_limit { + // Get the current CPU limit to preserve it + let cpu_limit = host.budget_cloned() + .get_cpu_insns_remaining() + .unwrap_or(100_000_000); + // Reset both CPU and memory limits to enforce memory_limit during execution + if let Err(e) = host.budget_ref().reset_limits(cpu_limit, mem_limit) { + eprintln!("Warning: Failed to set memory limit: {:?}", e); + } + } + Self { inner: host, ledger_snapshot: LedgerSnapshot::new(), @@ -79,6 +91,18 @@ impl SimHost { let host = Host::with_storage_and_budget(storage, budget); host.set_diagnostic_level(DiagnosticLevel::Debug)?; + // Hook memory_limit into the Budget tracking mechanism via reset_limits() + if let Some(mem_limit) = memory_limit { + // Get the current CPU limit to preserve it + let cpu_limit = host.budget_cloned() + .get_cpu_insns_remaining() + .unwrap_or(100_000_000); + // Reset both CPU and memory limits to enforce memory_limit during execution + if let Err(e) = host.budget_ref().reset_limits(cpu_limit, mem_limit) { + eprintln!("Warning: Failed to set memory limit: {:?}", e); + } + } + Ok(Self { inner: host, ledger_snapshot: snapshot.clone(),