Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/huff-language/huff-breakage

Incorrect, Breaking, and Footgunned Huff Contracts.
https://github.com/huff-language/huff-breakage

evm foundry huff solidity

Last synced: about 1 month ago
JSON representation

Incorrect, Breaking, and Footgunned Huff Contracts.

Awesome Lists containing this project

README

        

# huff-breakage • [![ci](https://github.com/huff-language/huff-breakage/actions/workflows/ci.yaml/badge.svg)](https://github.com/huff-language/huff-breakage/actions/workflows/ci.yaml) [![license](https://img.shields.io/badge/License-Apache_2.0-blue.svg?label=license)](https://opensource.org/licenses/Apache-2.0) ![solidity](https://img.shields.io/badge/solidity-%3E%3D%200.8.13-lightgrey)

A set of **Incorrect**, **Breaking**, and **Footgunned** [Huff](https://github.com/huff-language) Contracts.

## Overview

[huff-breakage](https://github.com/huff-language/huff-breakage) contains many contracts that demonstrate incorrect usage of the [Huff Language](https://huff.sh).

To reproduce contract errors, make sure `huffc` is installed by running:
```bash
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:
```bash
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_

```ml
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_

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:



## 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**](https://github.com/foundry-rs/foundry):

```sh
forge install huff-language/huff-breakage
```

To install with [**Hardhat**](https://github.com/nomiclabs/hardhat) or [**Truffle**](https://github.com/trufflesuite/truffle):

```sh
npm install @huff-language/huff-breakage
```

## Acknowledgements

- [huff-rs](https://github.com/huff-language/huff-rs)
- [huffmate](https://github.com/huff-language) _SOON_
- [huff-examples](https://github.com/huff-language/huff-examples)