TOB-FUEL-18: Crash when executing CCP (Copy Code) instruction #523
Labels
audit-report
Issue from the audit report
bug
Something isn't working
fuel-vm
Related to the `fuel-vm` crate.
mainnet
testing
Description
When executing the CCP (Copy Code) instruction with a code offset larger than the code being copied, then the interpreter panics. The following unit test will cause a panic.
Figure 18.1: Unit test which panics while executing the CCP instruction.
The reason for this panic is that the code_copy function does not verify that the parameter c is in bounds of the contract.
Figure 18.2: Code with bug because array bounds are not checked. (fuel-vm/fuel-vm/src/interpreter/blockchain.rs#625–653)
This issue has been discovered by manual code review, but can also automatically be discovered using the fuzzer from the fuzzing appendix (see appendix E)
Exploit Scenario
An attacker deploys a contract that includes a malicious CCP instruction. The interpreter will panic, and the whole node will crash. Because the same code is executed on multiple nodes maybe the whole network comes to a halt.
Recommendations
Short term, check that the range c..cd is in the bounds of the contract.
Long term, consider to automatically restart fuel-core when it crashed and report an error to the Fuel team. This would increase the reliability of fuel-core nodes. There should be a delay between restarts and also a maximum amount of restarts.
While this could also be solved on a Rust level by making sure to use the Rust unwinding behavior and catching panics at a higher level, a solution which does not depend on specific Rust compiler flags seems more robust.
Also deploy the fuzzer from the fuzzing appendix (see appendix E), which is able to discover this bug automatically.
The text was updated successfully, but these errors were encountered: