Attackathon _ Fuel Network 33172 - [Smart Contract - Insight] OOB in type_check_analyze of ImplTrait
Submitted on Sat Jul 13 2024 12:01:36 GMT-0400 (Atlantic Standard Time) by @InquisitorScythe for Attackathon | Fuel Network
Report ID: #33172
Report type: Smart Contract
Report severity: Insight
Target: https://github.com/FuelLabs/sway/tree/v0.61.2
Impacts:
Compiler bug
Description
Brief/Intro
The identified bug is a panic in the Sway compiler's semantic analysis module, specifically in the implementation of trait declarations. This occurs due to an index out of bounds error, suggesting a failure to properly handle empty collections or unexpected data structures in trait implementations. If exploited in production, this bug could lead to compiler crashes when processing certain trait implementations, potentially preventing developers from compiling valid Sway code. This could result in deployment failures, introduce inconsistencies in smart contract behavior, and potentially create vulnerabilities if incomplete or incorrectly compiled code makes it to the blockchain due to compiler errors.
Vulnerability Details
The bug is in https://github.com/FuelLabs/sway/blob/v0.61.2/sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs#L1554
In some cases, impl_trait.items
is not synced with ctx.items_node_stack
, It cause OOB panic like:
Possible Fix
A quick fix is like:
This fix check the index before getting node from ctx.items_node_stack
, it prevents compiler panics and return a error. Alternatively, you can refactor the logic in push_nodes_for_impl_trait
to enforce impl_trait.items
is synced with ctx.items_node_stack
.
Impact Details
While this bug doesn't directly put funds at risk, its potential to introduce vulnerabilities and disrupt the development process makes it a severe issue. The compiler is a critical component of the blockchain development stack, and its reliability is paramount for the security and success of the entire ecosystem. Addressing this vulnerability is crucial to maintain the integrity and trustworthiness of the Fuel platform.
References
None
Proof of concept
Step1
Step2
write minimized code to main.sw
Step3
It return panic like:
Last updated