A set of Incorrect, Breaking, and Footgunned Huff Contracts.
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()
|
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
NOTE: Some of the below contracts compile correctly and thus have a [COMPILES]
postfix
Invalid Function Visibility
Functions in huff can only have the visibility specifiers
view
, pure
, payable
, or nonpayable
. On line 6 of InvalidFunctionVisibility.huff, the function has a specifier internal
which is invalid, generating the following error:
Invalid Macro Invocation
On line 10 of InvalidMacroInvocation.huff, we invoke a macro called
UNKNOWN
, but it doesn't exist in either the InvalidMacroInvocation
Huff contract or any of its imports (there are none in this simple example).
Thus, the compiler will generate an error message like so when compiling the contract:
Invalid Macro Statement
On line 11 of InvalidMacroStatement.huff, we make a call to the
FREE_STORAGE_POINTER()
keyword which is invalid within the context of a macro.
Thus, the compiler will generate an error message like so when compiling the contract:
Missing Constant Definition
On line 10 of MissingConstantDef.huff, the constant
[UNKNOWN_CONSTANT_DEFINITION]
is referenced (the brackets notate the item's location will be pushed to the stack) but there is no UNKNOWN_CONSTANT_DEFINITION
definition present in the contract. This will generate an error message similar to below during compilation.
Missing Constructor [COMPILES]
Since missing constructors are allowed, the MissingConstructor.huff contract will compile correctly, producing the below output:
Missing Table Definition used in Table Size Builtin
On line 7 of MissingDefTableSize.huff, the table reference
STANDARD_JUMPTABLE
passed into the __tablesize()
builtin is missing. This results in the following error being generated:
Missing Table Definition used in Table Start Builtin
On line 7 of MissingDefTableStart.huff, the table reference
DIFFERENT_TABLE
passed into the __tablestart()
builtin is missing. This results in the following error being generated:
Missing Main Macro Definition
MissingMainMacroDefinition.huff is missing a `MAIN` macro definition which is invalid behavior as the contract needs an entrypoint.
Table Builtins
On line 6 of TableBuiltins.huff, the builting table contains references to labels that aren't defined, thus causing this contract to fail to compile.
Unmatched Jump Labels
On line 16 of UnmatchedJumpLabel.huff, the jump label
err
is referenced but there is no matching label definition. This will generate the following Unmatched Jump Label
error:
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.
To install with Foundry:
forge install huff-language/huff-breakage
To install with Hardhat or Truffle:
npm install @huff-language/huff-breakage
- huff-rs
- huffmate SOON
- huff-examples