Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hack fixes #28

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions docs/how-to/create-precompiles.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ functions:
type: Bid
```

There are three to-level objects: `types`, `structs` and `functions`. In this guide, we will focus on the `functions`, as adding a new precompile will most often entail writing a new function.
There are three top-level objects: `types`, `structs` and `functions`. In this guide, we will focus on the `functions`, as adding a new precompile will most often entail writing a new function.

If you can specify the function's name, the address its logic is deployed at on SUAVE, and what form you expect the inputs and output to take, then our codegen tool will automatically generate both the Solidity and Go bindings required to make your precompile work.

Expand Down Expand Up @@ -107,9 +107,9 @@ Then, run our code generator:
$ go run suave/gen/main.go --write
```

If your `yaml` additions have no errors and the `--write` flag is set, the bindings will be regenerated [here](https://github.com/flashbots/suave-geth/blob/main/suave/sol/libraries/Suave.sol) and [here](https://github.com/flashbots/suave-geth/blob/main/core/vm/contracts_suave_runtime_adapter.go).
If your `yaml` additions have no errors and the `--write` flag is set, the bindings will be (re)generated [here](https://github.com/flashbots/suave-geth/blob/main/suave/sol/libraries/Suave.sol) and [here](https://github.com/flashbots/suave-geth/blob/main/core/vm/contracts_suave_runtime_adapter.go).

A new `Add` function will have been created will have been created in the interface, which looks like:
A new `Add` function will have been created in the interface, which looks like:

```go
type SuaveRuntime interface {
Expand All @@ -119,7 +119,9 @@ type SuaveRuntime interface {
}
```

You will now need to write the logic required for your precompile to work as expected based on this generated skeleton. You can do this in the specific `suaveRuntime` struct generated in the same `contracts_suave_runtime_adapter.go` file. In our case, the logic is very simple: just a straightforward addition of the values passed in as inputs. Your implementation may be arbitrarily more complex based on what you want the precompile to achieve.
You will now need to write the logic required for your precompile to work as expected based on this generated skeleton.

You can do this in `contracts_suave.go`. In our case, the logic is very simple: just a straightforward addition of the values passed in as inputs. Your implementation may be arbitrarily more complex based on what you want the precompile to achieve.

````go
func (b *suaveRuntime) Add(a uint64, b uint64) (uint64, error) {
Expand Down
64 changes: 58 additions & 6 deletions docs/how-to/run-suave.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,29 @@ git clone https://github.com/flashbots/suave-geth.git
```bash
cd suave-geth/
```
3. Run SUAVE (depending on your docker setup, you may need to run this as `sudo`):
3. Run SUAVE:
```bash
make devnet-up
```

<details>
<summary>1. Docker permission errors</summary>
<div>
<div>
<div>
It is likely best to create a new user group for Docker, rather than run the above command as <code>sudo</code>. You can do by running:<br/><br/>
<code>
sudo usermod -aG docker $USER
</code><br/>
<code>
newgrp docker
</code>
</div>
</div>
</div>
</details>


### Optional testing

4. Test your node by deploying a contract and sending it some transactions:
Expand Down Expand Up @@ -69,10 +87,40 @@ You can also navigate to [http://localhost:8080](http://localhost:8080) in your
make devnet-down
```

### Common problems
### Troubleshooting

<details>
<summary>1. Docker not running</summary>
<summary>1. Go permission errors</summary>
<div>
<div>
<div>
If you are seeing:<br/>
<code>
"cp: cannot create regular file '/bin/suave': Permission denied"
</code><br/><br/>
it is most likely because you have not set your GOPATH correctly. You can do so by running:<br/><br/>
<code>
export GOPATH=$HOME/go
</code>
</div>
</div>
</div>
</details>
<details>
<summary>2. Missing packages</summary>
<div>
<div>
<div>
If you have set up a new machine to run through this, you'll also need to install Make and Go:<br/>
<code>
sudo apt install make golang-go
</code>
</div>
</div>
</div>
</details>
<details>
<summary>2. Docker not running</summary>
<div>
<div>
<div>
Expand All @@ -83,21 +131,25 @@ make devnet-down
You can check the current status with:<br/>
<code>
sudo systemctl status docker
</code><br/><br/>
If you installed Docker and still run into issues wit docker-compose, you can try:<br/>
<code>
sudo apt install docker-compose
</code>
</div>
</div>
</div>
</details>
<details>
<summary>2. Unsupported version</summary>
<summary>3. Unsupported version</summary>
<div>
<div>
<div>
If you're running an older version of Docker, you may get a message that looks like this:<br/><br/>
<code>
ERROR: Version in "././suave/devenv/docker-compose.yml" is unsupported.
</code><br/><br/>
Simply go to the file in <code>/suave/devenv/docker-compose.yml</code> and change the first line to use <code>3.3</code> rather than <code>3.8</code>.
Go to the file in <code>/suave/devenv/docker-compose.yml</code> and change the first line to use <code>3.3</code> rather than <code>3.8</code>.
</div>
</div>
</div>
Expand Down Expand Up @@ -147,7 +199,7 @@ If the `--datadir` flag is not set, a geth client stores data in the `$HOME/.eth
You can attach to the usual Geth javascript console to get any interactive data you need with:

```bash
./build/bin/suave attach ./suave/geth.ipc
./build/bin/suave attach /tmp/geth.ipc
```

From within the console, you can run:
Expand Down
Loading