Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions crates/core/src/decode/mappings/context.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//! Context error subcode mappings.
//!
//! Context errors describe problems with the Soroban execution environment or
//! with host functions being invoked from the wrong execution context.

/// Human-readable detail for a Context category host error subcode.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ContextErrorDetail {
pub code: u32,
pub name: &'static str,
pub summary: &'static str,
pub severity: &'static str,
}

/// All Context category subcodes currently emitted by soroban-env-host.
pub const CONTEXT_ERROR_DETAILS: &[ContextErrorDetail] = &[
ContextErrorDetail {
code: 6,
name: "InvalidAction",
summary: "A host function was called in an execution context where that action is not valid; this usually points to contract code using the environment at the wrong time.",
severity: "Error",
},
ContextErrorDetail {
code: 7,
name: "InternalError",
summary: "The Soroban host hit an unexpected internal state; this points to the execution environment rather than normal contract logic.",
severity: "Fatal",
},
];

/// Look up detail for a Context category host error subcode.
pub fn lookup_context_error(code: u32) -> Option<&'static ContextErrorDetail> {
CONTEXT_ERROR_DETAILS
.iter()
.find(|detail| detail.code == code)
}
3 changes: 3 additions & 0 deletions crates/core/src/decode/mappings/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! Static host error subcode mappings used by the decode engine.

pub mod context;
1 change: 1 addition & 0 deletions crates/core/src/decode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub mod context;
pub mod contract_error;
pub mod diagnostic;
pub mod host_error;
pub mod mappings;
pub mod report;

use crate::error::PrismResult;
Expand Down
29 changes: 28 additions & 1 deletion crates/core/src/taxonomy/data/context.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,37 @@ name = "Context"
description = "Errors triggered by invalid execution context, such as calling host functions outside of a valid invocation or re-entrancy violations."
source_module = "soroban-env-host/src/host.rs"

[[errors]]
id = "host.context.invalid_action"
category = "context"
code = 6
name = "InvalidAction"
severity = "Error"
since_protocol = 20
summary = "A host function was called in an execution context where that action is not valid."
detailed_explanation = """
InvalidAction means the contract or host integration attempted an operation from the wrong \
execution context, such as using a host capability before the host is ready or outside the \
allowed invocation lifecycle. This usually points to contract or caller behavior, not a broken \
network environment.
"""

[[errors.common_causes]]
description = "Contract code or a host integration called an environment action outside its valid lifecycle"
likelihood = "high"

[[errors.suggested_fixes]]
description = "Review where the host function is called and move it into a valid contract invocation context"
difficulty = "medium"
requires_upgrade = false

related_errors = []
source_file = "soroban-env-host/src/host.rs"

[[errors]]
id = "host.context.internal_error"
category = "context"
code = 0
code = 7
name = "InternalError"
severity = "Fatal"
since_protocol = 20
Expand Down