You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code size (CSIZ) and code root (CROO) opcodes do not validate that the contract argument is in the transaction’s input contacts field. This check prevents operating on contracts which do not exist as the interpreter checks all transaction inputs prior to execution (see figure 11.1). Since code size charges a dynamic cost only if a contract exists, the node will perform computation without charging gas.
Figure 11.1: The interpreter validates the existence of all input contracts upfront in the run function
Rather than reverting upon seeing a contract that was not included in the transaction, the interpreter continues to execute and may revert later than it would otherwise. Notably, the call to contract_size reverts before charging gas when a contract does not exist and thus does not have a code size. This may make the node susceptible to denial of service attacks.
Figure 11.2: The contract size is looked up and may revert before charging gas in the code size
The code copy opcode correctly validates that all contract operands were specified in the transaction’s input contracts.
Figure 11.3: The correct validation performed by the code copy implementation
pub(crate)fncode_copy([...]
if !self.input_contracts.any(|input| input == contract){*self.panic_context = PanicContext::ContractId(*contract);returnErr(PanicReason::ContractNotInInputs.into())}
Exploit Scenario
An attacker sends a large number of transactions that invoke code size opcodes for non-existent accounts and does not include them in the transaction’s input contracts. Because the opcodes cannot rely on the precondition of the interpreter validating that all input contracts exist, they unnecessarily perform lookups and revert with ContractNotFound prior to charging the attacker for gas.
Recommendations
Short term, validate that the contract is specified in the transaction input contracts prior to performing lookups.
Long term, consider charging a static gas cost for dynamically priced opcodes upfront or penalizing transactions that leave out contracts from the transaction input contracts.
The text was updated successfully, but these errors were encountered:
Description
The code size (CSIZ) and code root (CROO) opcodes do not validate that the contract argument is in the transaction’s input contacts field. This check prevents operating on contracts which do not exist as the interpreter checks all transaction inputs prior to execution (see figure 11.1). Since code size charges a dynamic cost only if a contract exists, the node will perform computation without charging gas.
Figure 11.1: The interpreter validates the existence of all input contracts upfront in the run function
Rather than reverting upon seeing a contract that was not included in the transaction, the interpreter continues to execute and may revert later than it would otherwise. Notably, the call to contract_size reverts before charging gas when a contract does not exist and thus does not have a code size. This may make the node susceptible to denial of service attacks.
Figure 11.2: The contract size is looked up and may revert before charging gas in the code size
implementation
The code copy opcode correctly validates that all contract operands were specified in the transaction’s input contracts.
Figure 11.3: The correct validation performed by the code copy implementation
Exploit Scenario
An attacker sends a large number of transactions that invoke code size opcodes for non-existent accounts and does not include them in the transaction’s input contracts. Because the opcodes cannot rely on the precondition of the interpreter validating that all input contracts exist, they unnecessarily perform lookups and revert with ContractNotFound prior to charging the attacker for gas.
Recommendations
Short term, validate that the contract is specified in the transaction input contracts prior to performing lookups.
Long term, consider charging a static gas cost for dynamically priced opcodes upfront or penalizing transactions that leave out contracts from the transaction input contracts.
The text was updated successfully, but these errors were encountered: