Skip to content

Commit

Permalink
Merge pull request #18 from anton-rs/anna/refactor-adds
Browse files Browse the repository at this point in the history
README/docs & deprecate huff 🥺
  • Loading branch information
anna-carroll authored Apr 26, 2024
2 parents e0f80d3 + 0ef6e12 commit b8f3e28
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 440 deletions.
7 changes: 0 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ build-solc-patch:
cp solc/solc ../../../bin/solc
@echo "Done, patched solc binary is located at `bin/solc` relative to the project root"

.PHONY: install-huff
install-huff:
@echo "Installing huff..."
@curl -L get.huff.sh | bash
@huffup
@echo "Done!"

.PHONY: test
test:
@[[ ! -a ./bin/forge ]] && make build-forge-patch || true
Expand Down
83 changes: 18 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,35 @@
# `eip-3074-foundry`
# EIP-3074 Invokers

This repository contains patched versions of [`foundry`][foundry] & [the `solidity` compiler][solc], integrated with patches to [`revm`][revm] / [`ethers-rs`][ethers-rs], that support
the [EIP-3074][eip-3074] opcodes (`AUTH` & `AUTHCALL`).
Generalized [EIP-3074](https://eips.ethereum.org/EIPS/eip-3074) Invokers.

## Patches
- `BaseInvoker` - Invoker template for building arbitrary Invoker logic.
- `BatchInvoker` - Invoker with batch transaction support.

> **NOTE**:
> These are *patches*, don't spin up a production system with these and expect security.
> [!WARNING]
> WIP. Very experimental, not audited, use with caution.
- `revm` patch: https://github.com/clabby/revm/pull/1
- See review comments. Incomplete atm, but functionally works as expected.
- `ethers-rs` patch: https://github.com/clabby/ethers-rs/tree/cl/call-type-3074
- `foundry` patch: https://github.com/clabby/foundry/tree/cl/eip-3074
- `solc` patch: https://github.com/clabby/solidity/tree/cl/eip-3074
- `reth` patch: https://github.com/paradigmxyz/reth/tree/cl/eip-3074
## Patches

## Usage
This repository contains patches (h/t @clabby) of the following repositories to support EIP-3074 opcodes:

**Building `forge`**
- [`revm`](https://github.com/jxom/revm/tree/jxom/eip-3074)
- [`foundry`](https://github.com/jxom/foundry/tree/jxom/eip-3074)
- [`solc`](https://github.com/clabby/solidity/tree/cl/eip-3074)

First, build the patched version of `foundry` (this will take a while):
## Installation

```sh
git submodule update --init --recursive && \
make build-forge-patch
```
git submodule update --init --recursive && make
```

This command will place the patched `forge` binary in `bin/forge`.

**Building `solc`**

Next, build the patched version of `solc` (this will also take a while):
## Building Contracts

```
make build-solc-patch
make build
```

This patch supports the following semantics:
```solidity
function example() public {
// AUTHCALL by `address` member access
address(0xbeefbabe).authcall(hex"...");
assembly {
// AUTH
let authSuccess := auth(<authorized>, <args_offset_mem>, <args_length>)
## Running Tests

// AUTHCALL
let authCallSuccess := authcall(
<gas>,
<to_addr>,
<value>, // NOTE: This is currently sent from the Invoker contract, NOT the `authorized` account.
<valueExt>, // Must always be `0` per the current 3074 spec, reserved for future use.
<args_offset_mem>,
<args_length>,
<ret_offset_mem>,
<ret_length>
)
}
}
```

**Installing `huffc`**

The [`huff`][huff-rs] version of the `EIP-3074` invoker requires `huffc` to be installed.

```sh
make install-huff
make test
```

**Running Examples**

To run the examples, interact with the patched `forge` binary as normal. There is a special override for the `Prague` hardfork within the `foundry.toml` which
will enable the `AUTH` & `AUTHCALL` opcodes, and the `foundry.toml` specifies the patched `solc` binary as the compiler.

[foundry]: https://github.com/foundry-rs/foundry
[revm]: https://github.com/bluealloy/revm
[ethers-rs]: https://github.com/gakonst/ethers-rs
[eip-3074]: https://eips.ethereum.org/EIPS/eip-3074
[solc]: https://github.com/ethereum/solidity
[huff-rs]: https://github.com/huff-language/huff-rs
213 changes: 0 additions & 213 deletions src/AsmInvoker.huff

This file was deleted.

1 change: 1 addition & 0 deletions src/Auth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.20;
/// @title Auth
/// @author Anna Carroll <https://github.com/anna-carroll/3074>
/// @author Jake Moxey <https://github.com/jxom>
/// @notice Utils for EIP-3074 AUTH & AUTHCALL opcodes.
contract Auth {
uint8 constant MAGIC = 0x04;

Expand Down
4 changes: 2 additions & 2 deletions src/BaseInvoker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { Auth } from "src/Auth.sol";
/// @title BaseInvoker
/// @author Anna Carroll <https://github.com/anna-carroll/3074>
/// @author Jake Moxey <https://github.com/jxom>
/// @notice Shared functionality for Invoker contracts to efficiently AUTH a signer, then execute arbitrary application logic.
/// @dev To implement an Invoker contract, simply inherit BaseInvoker and override the exec function with your Invoker logic.
/// @notice Invoker contract template.
/// @dev Inherit & override the `exec` function to implement arbitrary Invoker logic.
abstract contract BaseInvoker is Auth {
/// @notice produce a digest to sign that authorizes the invoker
/// to execute actions using AUTHCALL
Expand Down
9 changes: 1 addition & 8 deletions src/BatchInvoker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@ import { MultiSendAuthCallOnly } from "src/MultiSendAuthCallOnly.sol";
/// @title BatchInvoker
/// @author Anna Carroll <https://github.com/anna-carroll/3074>
/// @author Jake Moxey <https://github.com/jxom>
/// @notice Example EIP-3074 Invoker contract which executes a batch of calls using AUTH and AUTHCALL.
/// BatchInvoker enables multi-transaction flows for EOAs,
/// such as performing an ERC-20 approve & transfer with just one signature.
/// It also natively enables gas sponsored transactions.
/// @dev batches are executed in sequence based on their nonce;
/// each calls within the batch is executed in sequence based on the order it is included in the array;
/// calls are executed non-interactively (return data from one call is not passed into the next);
/// batches are executed atomically (if one sub-call reverts, the whole batch reverts)
/// @notice Invoker with batched transaction execution.
contract BatchInvoker is BaseInvoker, MultiSendAuthCallOnly {
/// @notice authority => next valid nonce
mapping(address => uint256) public nextNonce;
Expand Down
7 changes: 3 additions & 4 deletions src/MultiSendAuthCallOnly.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// SPDX-License-Identifier: LGPL-3.0-only
pragma solidity >=0.7.0 <0.9.0;

// VENDORED from Gnosis Safe
// Modified to make AUTHCALL-only instead of CALL-only
// https://github.com/safe-global/safe-contracts/blob/main/contracts/libraries/MultiSendCallOnly.sol

/// @dev VENDORED from Gnosis Safe:
/// https://github.com/safe-global/safe-contracts/blob/main/contracts/libraries/MultiSendCallOnly.sol
/// MODIFIED to perform AUTHCALL-only instead of CALL-only
/**
* @title Multi Send Call Only - Allows to batch multiple transactions into one, but only calls
* @notice The guard logic is not required here as this contract doesn't support nested delegate calls
Expand Down
Loading

0 comments on commit b8f3e28

Please sign in to comment.