Attackathon _ Fuel Network 33139 - [Smart Contract - Insight] Unreachable panic in sway compiler whe

Submitted on Fri Jul 12 2024 07:01:05 GMT-0400 (Atlantic Standard Time) by @ret2happy for Attackathon | Fuel Network

Report ID: #33139

Report type: Smart Contract

Report severity: Insight

Target: https://github.com/FuelLabs/sway/tree/v0.61.2

Impacts:

  • Compiler bug

Description

Brief/Intro

While parsing malicious contract, the sway compiler crashed with unreachable code.

Vulnerability Details

There exists an edge case which is not handled properly when parsing the cfg tree, this finally cause the unreachable panic in [1]

    _ => { // [1] unhandled case causes panic:
        // Already checked with `AttributeKind::expected_args_*`
        unreachable!("cfg attribute should only have the `target` or the `program_type` argument");
    }

Impact Details

Online verification service or sway playground which accept sw contract using sway compiler could be crashed by the malicous sw contract.

References

[1] https://github.com/FuelLabs/sway/blob/f82d9e67c2a81e600ae61a86dd1a7c905facf6c5/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs#L4897-L4900

Proof of concept

Proof of Concept

build the following contract using forc would crash:

Running it would get:

Last updated

Was this helpful?