Awesome
<img align="right" width="150" height="150" top="100" src="./assets/breakage.png">
huff-breakage •
A set of Incorrect, Breaking, and Footgunned Huff Contracts.
Overview
huff-breakage contains many contracts that demonstrate incorrect usage of the Huff Language.
To reproduce contract errors, make sure huffc
is installed by running:
curl -L get.huff.sh | bash
# `source ~/.bashrc` OR `source ~/.zshrc` OR `source ~/.profile`
huffup
Then, compile a given contract to view the error message. For example, to view an invalid macro invocation error, run huffc -b ./src/InvalidMacroInvocation.huff
, which will produce output similar to:
Error: Missing Macro Definition For Invocation: "UNKNOWN"
-> src/InvalidMacroInvocation.huff:468-477
|
> 10 | UNKNOWN()
|
Contracts
NOTE: Some of the below contracts compile correctly and have a [COMPILES]
postfix
src
├─ InvalidFunctionVisibility — An invalid function visibility specifier
├─ InvalidMacroInvocation — An invocation of a macro that doesn't exist
├─ InvalidMacroStatement — An invalid statement in a macro definition
├─ MissingConstantDef — A constant definition is missing
├─ MissingConstructor — A constructor macro definition is missing [COMPILES]
├─ MissingDefTableSize — Table definition used in __tablesize builtin is missing
├─ MissingDefTableStart — Table definition used in __tablestart builtin is missing
├─ TableBuiltins — Table Builtins created on deployment with missing label definitions
├─ UnmatchedJumpLabel — A jump label that has no matching label definition
Explanations
NOTE: Some of the below contracts compile correctly and thus have a [COMPILES]
postfix
<details>
<summary>Invalid Function Visibility</summary>
<br />
Functions in huff can only have the visibility specifiers <code>view</code>, <code>pure</code>, <code>payable</code>, or <code>nonpayable</code>. On line 6 of <a href="./src/InvalidFunctionVisibility.huff">InvalidFunctionVisibility.huff</a>, the function has a specifier <code>internal</code> which is invalid, generating the following error:
<p align="center">
<img height="300px" style="display: block; margin: 0 auto" src="./assets/invalidfunctionvisibility.png">
</p>
</details>
<details>
<summary>Invalid Macro Invocation</summary>
<br />
On line 10 of <a href="./src/InvalidMacroInvocation.huff">InvalidMacroInvocation.huff</a>, we invoke a macro called <code>UNKNOWN</code>, but it doesn't exist in either the <code>InvalidMacroInvocation</code> Huff contract or any of its imports (there are none in this simple example).
<br />
Thus, the compiler will generate an error message like so when compiling the contract:
<p align="center">
<img height="300px" style="display: block; margin: 0 auto" src="./assets/invalidmacroinvocation.png">
</p>
</details>
<details>
<summary>Invalid Macro Statement</summary>
<br />
On line 11 of <a href="./src/InvalidMacroStatement.huff">InvalidMacroStatement.huff</a>, we make a call to the <code>FREE_STORAGE_POINTER()</code> keyword which is invalid within the context of a macro.
<br />
Thus, the compiler will generate an error message like so when compiling the contract:
<p align="center">
<img height="300px" style="display: block; margin: 0 auto" src="./assets/invalidmacrostatement.png">
</p>
</details>
<details>
<summary>Missing Constant Definition</summary>
<br />
On line 10 of <a href="./src/MissingConstantDef.huff">MissingConstantDef.huff</a>, the constant <code>[UNKNOWN_CONSTANT_DEFINITION]</code> is referenced (the brackets notate the item's location will be pushed to the stack) but there is no <code>UNKNOWN_CONSTANT_DEFINITION</code> definition present in the contract. This will generate an error message similar to below during compilation.
<p align="center">
<img height="300px" style="display: block; margin: 0 auto" src="./assets/missingconstantdef.png">
</p>
</details>
<details>
<summary>Missing Constructor [COMPILES]</summary>
<br />
Since missing constructors are allowed, the <a href="./src/MissingConstructor.huff">MissingConstructor.huff</a> contract will compile correctly, producing the below output:
<p align="center">
<img height="300px" style="display: block; margin: 0 auto" src="./assets/missingconstructor.png">
</p>
</details>
<details>
<summary>Missing Table Definition used in Table Size Builtin</summary>
<br />
On line 7 of <a href="./src/MissingDefTableSize.huff">MissingDefTableSize.huff</a>, the table reference <code>STANDARD_JUMPTABLE</code> passed into the <code>__tablesize()</code> builtin is missing. This results in the following error being generated:
<p align="center">
<img height="300px" style="display: block; margin: 0 auto" src="./assets/missingdeftablesize.png">
</p>
</details>
<details>
<summary>Missing Table Definition used in Table Start Builtin</summary>
<br />
On line 7 of <a href="./src/MissingDefTableStart.huff">MissingDefTableStart.huff</a>, the table reference <code>DIFFERENT_TABLE</code> passed into the <code>__tablestart()</code> builtin is missing. This results in the following error being generated:
<p align="center">
<img height="300px" style="display: block; margin: 0 auto" src="./assets/missingdeftablestart.png">
</p>
</details>
<details>
<summary>Missing Main Macro Definition</summary>
<br />
<a href="./src/MissingMainMacroDefinition.huff">MissingMainMacroDefinition.huff</a> is missing a `MAIN` macro definition which is invalid behavior as the contract needs an entrypoint.
<p align="center">
<img height="300px" style="display: block; margin: 0 auto" src="./assets/missingmaindef.png">
</p>
</details>
<details>
<summary>Table Builtins</summary>
<br />
On line 6 of <a href="./src/TableBuiltins.huff">TableBuiltins.huff</a>, the builting table contains references to labels that aren't defined, thus causing this contract to fail to compile.
<p align="center">
<img height="300px" style="display: block; margin: 0 auto" src="./assets/tablebuiltins.png">
</p>
</details>
<details>
<summary>Unmatched Jump Labels</summary>
<br />
On line 16 of <a href="./src/UnmatchedJumpLabel.huff">UnmatchedJumpLabel.huff</a>, the jump label <code>err</code> is referenced but there is no matching label definition. This will generate the following <code>Unmatched Jump Label</code> error:
<p align="center">
<img height="300px" style="display: block; margin: 0 auto" src="./assets/unmatchedjumplabels.png">
</p>
</details>
Safety Notice
This is experimental software and is provided on an "as is" and "as available" basis.
We do not give any warranties and will not be liable for any loss incurred through any use of this codebase.
Installation
To install with Foundry:
forge install huff-language/huff-breakage
To install with Hardhat or Truffle:
npm install @huff-language/huff-breakage
Acknowledgements