The Contract Manager module implements a crucial safety mechanism for IBC-enabled smart contracts. This document explains the principles, architecture, and internal mechanisms of the module.
When smart contracts interact with IBC, they must handle acknowledgments from counterparty chains. These acknowledgments are delivered to contracts via sudo calls, which are privileged operations that bypass normal permission checks. This creates several potential issues:
IBC Channel Disruption: If a contract’s sudo handler fails when processing an acknowledgment on an ORDERED channel, it can disrupt the entire channel.
Relayer Load: Even on UNORDERED channels, a failing sudo handler can force relayers to repeatedly attempt delivery, causing unnecessary load.
Attack Vector: Malicious contracts could deliberately implement failing sudo handlers to attack the network infrastructure.
To prevent DoS attacks via recursive IBC messages that could deplete block gas, the module enforces a strict gas limit for sudo calls. This limit is defined by the SudoCallGasLimit parameter.The gas limitation has important implications:
Complex operations shouldn’t be performed directly in sudo handlers since they may exceed the gas limit.
As a best practice, sudo handlers should store the received data in the contract’s state and defer processing to a later explicit execution.
If a contract exceeds the gas limit, the operation is terminated, and a failure record is created.
Since raw error messages may not be deterministic across nodes, the module redacts errors stored in the state to contain only the codespace and code ID. The full error text is emitted as an event rather than stored in state.