Skip to content

Commit 56dd64d

Browse files
committed
Merge branch 'main' into joby.thundil/retire-games-template
2 parents 88d35c9 + 7c6cbdf commit 56dd64d

File tree

152 files changed

+11094
-1157
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+11094
-1157
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ yarn-error.log
2626
.gitmodules
2727

2828
.DS_Store
29+
signer-tool/

Makefile

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
FOUNDRY_COMMIT ?= 3b1129b5bc43ba22a9bcf4e4323c5a9df0023140
2+
13
PROJECT_DIR = $(network)/$(shell date +'%Y-%m-%d')-$(task)
24
GAS_INCREASE_DIR = $(network)/$(shell date +'%Y-%m-%d')-increase-gas-limit
35
FAULT_PROOF_UPGRADE_DIR = $(network)/$(shell date +'%Y-%m-%d')-upgrade-fault-proofs
@@ -116,7 +118,7 @@ checkout-base-contracts-commit:
116118
##
117119
# Task Signer Tool
118120
##
119-
SIGNER_TOOL_COMMIT=f33affd459859882b30fbda29e43abfded77903a
121+
SIGNER_TOOL_COMMIT=dc9dcd57e66cc71d8e8f40afc2d0bad454cba998
120122
SIGNER_TOOL_PATH=signer-tool
121123

122124
.PHONY: checkout-signer-tool
@@ -130,14 +132,11 @@ checkout-signer-tool:
130132
git fetch --depth=1 origin $(SIGNER_TOOL_COMMIT); \
131133
git reset --hard FETCH_HEAD
132134

133-
.PHONY: sign
134-
sign:
135+
.PHONY: sign-task
136+
sign-task: checkout-signer-tool
135137
cd $(SIGNER_TOOL_PATH); \
136138
npm ci; \
137-
bun dev
138-
139-
.PHONY: sign-task
140-
sign-task: checkout-signer-tool sign
139+
npm run dev
141140

142141
##
143142
# Solidity Testing

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ Next, `cd` into the directory that was created for you and follow the steps list
4848

4949
> **👥 For Signers:** Please read the [Signer Guide](SIGNER.md) for step-by-step instructions on using the validation UI.
5050
51+
Please note, you will need to manually create validation file(s) for your task as they are bespoke to each task and therefore not created automatically as a part of the templates. We use one validation Markdown file per multisig involved in the task, so if there's only one multisig involved in your task, then you can simply create a `VALIDATION.md` file at the root of your task containing the validation instructions, while if there are multiple multisigs involved in the task, then create a `validations/` sub-directory at the root of your task containing the corresponding validation Markdown files. If you need examples to work from, you can browse through similar past tasks in this repo and adapt them to your specific task. Also, please note that we have tooling to generate these files (like the `task-signer-tool`) which removes the manual aspect of creating these validation files, we will soon update these instructions to reflect how this process can be automated.
52+
5153
## Directory structure
5254

5355
Each task will have a directory structure similar to the following:
@@ -92,7 +94,7 @@ This template is increasing the throughput on Base Chain.
9294
1. Go to the folder that was created using the `make setup-gas-increase network=<network>` step
9395
1. Fill in all TODOs (search for "TODO" in the folder) in the `.env` and `README` files. Tip: you can run `make deps` followed by `make sign-upgrade` to produce a Tenderly simulation which will help fill in several of the TODOs in the README (and also `make sign-rollback`).
9496
1. Check in the task when it's ready to sign and collect signatures from signers
95-
1. Once executed, check in the records files and mark the task `DONE` in the README.
97+
1. Once executed, check in the records files and mark the task `EXECUTED` in the README.
9698

9799
## Using the fault proof upgrade template
98100

@@ -108,7 +110,7 @@ This template is used to upgrade the fault proof contracts. This is commonly don
108110
1. Build the contracts with `forge build`
109111
1. Remove the unneeded validations from `VALIDATION.md` and update the relevant validations accordingly
110112
1. Check in the task when it's ready to sign and collect signatures from signers
111-
1. Once executed, check in the records files and mark the task `DONE` in the README.
113+
1. Once executed, check in the records files and mark the task `EXECUTED` in the README.
112114

113115
## Using the swap owner template
114116

@@ -122,7 +124,7 @@ This template is used to perform ownership management on a Gnosis Safe multisig,
122124
1. Build the contracts with `forge build`.
123125
1. Simulate the task with `make sign` and update the generic validations in `VALIDATION.md` with the real values.
124126
1. Check in the task when it's ready to sign and request the facilitators to collect signatures from signers.
125-
1. Once executed, check in the records files and mark the task `DONE` in the README.
127+
1. Once executed, check in the records files and mark the task `EXECUTED` in the README.
126128

127129
## Using the funding template
128130

@@ -137,7 +139,7 @@ This template is used to fund addresses from a Gnosis Safe.
137139
1. Build the contracts with `forge build`.
138140
1. Simulate the task with `make sign` and update the generic validations in `VALIDATION.md` with the real values.
139141
1. Check in the task when it's ready to sign and request the facilitators to collect signatures from signers.
140-
1. Once executed, check in the records files and mark the task `DONE` in the README.
142+
1. Once executed, check in the records files and mark the task `EXECUTED` in the README.
141143

142144
## Using the Base Bridge set partner threshold template
143145

@@ -153,7 +155,7 @@ This template is used to update the partner threshold in [Base Bridge](https://g
153155
1. Build the contracts with `forge build`.
154156
1. Generate the validation file for signers with `make gen-validation`.
155157
1. Check in the task when it's ready to sign and request the facilitators to collect signatures from signers.
156-
1. Once executed, check in the records files and mark the task `DONE` in the README.
158+
1. Once executed, check in the records files and mark the task `EXECUTED` in the README.
157159

158160
## Using the pause Base Bridge template
159161

@@ -169,4 +171,4 @@ This template is used to pause or un-pause [Base Bridge](https://github.com/base
169171
1. Build the contracts with `forge build`.
170172
1. Generate the validation file for signers with `make gen-validation`.
171173
1. Check in the task when it's ready to sign and request the facilitators to collect signatures from signers.
172-
1. Once executed, check in the records files and mark the task `DONE` in the README.
174+
1. Once executed, check in the records files and mark the task `EXECUTED` in the README.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
OP_COMMIT=ef7a933ca7f3d27ac40406f87fea25e0c3ba2016
2+
BASE_CONTRACTS_COMMIT=132ba0f33cb455ffff783924588df8864767bd9c
3+
4+
OWNER_SAFE=0xB5fa2Ea9845C67c76b1813D4778601F209875Bf6
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
include ../../Makefile
2+
include ../.env
3+
include .env
4+
5+
ifndef LEDGER_ACCOUNT
6+
override LEDGER_ACCOUNT = 0
7+
endif
8+
9+
.PHONY: do-sign
10+
do-sign:
11+
$(GOPATH)/bin/eip712sign --ledger --hd-paths "m/44'/60'/$(LEDGER_ACCOUNT)'/0/0" -- \
12+
forge script --rpc-url $(L2_RPC_URL) SwapOwner \
13+
--sig "sign(address[])" []
14+
15+
.PHONY: execute
16+
execute:
17+
forge script --rpc-url $(L2_RPC_URL) SwapOwner \
18+
--sig "run(bytes)" $(SIGNATURES) --ledger --hd-paths "m/44'/60'/$(LEDGER_ACCOUNT)'/0/0" --broadcast
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"OwnersToAdd": [
3+
"0xB4AE52A401C34Ed24F49413170690255e737D414",
4+
"0xB9F93278843351Dd1F1fB7045349aCA4401CB76e",
5+
"0x8793C36f3721B751Aa03A365be4862ac4aCD21Ef",
6+
"0x16eBE22A951D96A3CA15407b04dD873A14018992",
7+
"0x7233C120cd9D601EC0ad4DBaA51aE55A4851FaC6",
8+
"0x4Ae6Da8c76d4a628594a2154bDC31C9e04f43A48",
9+
"0x14b849bcc8034b2cd4c4669f9CEB47b190F3fb1F"
10+
],
11+
"OwnersToRemove": [
12+
"0xC29A4a69886d5ee1E08BDBbdd4e35558A668ee04",
13+
"0x23AB3425EC02328eBB0dB3d93213a2238A78a026",
14+
"0x7CD1a2f18CBef60F63F6fe35FC02A6305a77E3E2",
15+
"0xd458da0810f6924623575a4b965310F008c1C8fe",
16+
"0xE4fdB41d002844cfb43d5d50DE7210625C6f5a09",
17+
"0xA608EA330D51A5109454f3Ea4F5d0cdEc5a1aCAa"
18+
]
19+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# Swap Owner on Gnosis Safe
2+
3+
Status: PENDING
4+
5+
## Description
6+
7+
This task contains a single script that can be used to swap an owner in a Gnosis Safe.
8+
9+
## Procedure
10+
11+
### 1. Update repo:
12+
13+
```bash
14+
cd <network>/<date>safe-swap-owner
15+
make deps
16+
```
17+
18+
### 2. Setup Ledger
19+
20+
Your Ledger needs to be connected and unlocked. The Ethereum
21+
application needs to be opened on Ledger with the message "Application
22+
is ready".
23+
24+
### 3. Simulate, Validate, and Sign
25+
26+
#### 3.1. Simulate and validate the transaction
27+
28+
Make sure your ledger is still unlocked and run the following.
29+
30+
```bash
31+
make do-sign
32+
```
33+
34+
You will see a "Simulation link" from the output.
35+
36+
Paste this URL in your browser. A prompt may ask you to choose a
37+
project, any project will do. You can create one if necessary.
38+
39+
Click "Simulate Transaction".
40+
41+
We will be performing 3 validations and extract the domain hash and
42+
message hash to approve on your Ledger:
43+
44+
1. Validate integrity of the simulation.
45+
2. Validate correctness of the state diff.
46+
3. Validate and extract domain hash and message hash to approve.
47+
48+
##### 3.1.1. Validate integrity of the simulation.
49+
50+
Make sure you are on the "Summary" tab of the tenderly simulation, to
51+
validate integrity of the simulation, we need to check the following:
52+
53+
1. "Network": Check the network is `<network>`.
54+
2. "Timestamp": Check the simulation is performed on a block with a
55+
recent timestamp (i.e. close to when you run the script).
56+
3. "Sender": Check the address shown is your signer account.
57+
58+
##### 3.1.2. Validate correctness of the state diff.
59+
60+
Now click on the "State" tab, and refer to the [State Validations](./VALIDATION.md) instructions for the transaction you are signing.
61+
Once complete return to this document to complete the signing.
62+
63+
### 4. Extract the domain hash and the message hash to approve.
64+
65+
Now that we have verified the transaction performs the right
66+
operation, we need to extract the domain hash and the message hash to
67+
approve.
68+
69+
Go back to the "Summary" tab, and find the
70+
`Safe.checkSignatures` call. This call's `data` parameter
71+
contains both the domain hash and the message hash that will show up
72+
in your Ledger.
73+
74+
It will be a concatenation of `0x1901`, the domain hash, and the
75+
message hash: `0x1901[domain hash][message hash]`.
76+
77+
Note down this value. You will need to compare it with the ones
78+
displayed on the Ledger screen at signing.
79+
80+
Once the validations are done, it's time to actually sign the
81+
transaction.
82+
83+
> [!WARNING]
84+
> This is the most security critical part of the playbook: make sure the
85+
> domain hash and message hash in the following three places match:
86+
>
87+
> 1. On your Ledger screen.
88+
> 2. In the terminal output.
89+
> 3. In the Tenderly simulation. You should use the same Tenderly
90+
> simulation as the one you used to verify the state diffs, instead
91+
> of opening the new one printed in the console.
92+
>
93+
94+
After verification, sign the transaction. You will see the `Data`,
95+
`Signer` and `Signature` printed in the console. Format should be
96+
something like this:
97+
98+
```shell
99+
Data: <DATA>
100+
Signer: <ADDRESS>
101+
Signature: <SIGNATURE>
102+
```
103+
104+
Double check the signer address is the right one.
105+
106+
#### 4.1. Send the output to Facilitator(s)
107+
108+
Nothing has occurred onchain - these are offchain signatures which
109+
will be collected by Facilitators for execution. Execution can occur
110+
by anyone once a threshold of signatures are collected, so a
111+
Facilitator will do the final execution for convenience.
112+
113+
Share the `Data`, `Signer` and `Signature` with the Facilitator, and
114+
congrats, you are done!
115+
116+
### [For Facilitator ONLY] How to execute
117+
118+
#### Execute the transaction
119+
120+
1. Collect outputs from all participating signers.
121+
1. Concatenate all signatures and export it as the `SIGNATURES`
122+
environment variable, i.e. `export
123+
SIGNATURES="[SIGNATURE1][SIGNATURE2]..."`.
124+
1. Run the `make execute` command as described below to execute the transaction.
125+
126+
For example, if the quorum is 2 and you get the following outputs:
127+
128+
```shell
129+
Data: 0xDEADBEEF
130+
Signer: 0xC0FFEE01
131+
Signature: AAAA
132+
```
133+
134+
```shell
135+
Data: 0xDEADBEEF
136+
Signer: 0xC0FFEE02
137+
Signature: BBBB
138+
```
139+
140+
Then you should run:
141+
142+
Coinbase facilitator:
143+
144+
```bash
145+
SIGNATURES=AAAABBBB make execute
146+
```
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Validation
2+
3+
This document can be used to validate the state diff resulting from the execution of the swap owner transaction.
4+
5+
For each contract listed in the state diff, please verify that no contracts or state changes shown in the Tenderly diff are missing from this document. Additionally, please verify that for each contract:
6+
7+
- The following state changes (and no others) are made to that contract. This validates that no unexpected state changes occur.
8+
- All addresses (in section headers and storage values) match the provided name, using the Etherscan links provided. This validates the bytecode deployed at the addresses contains the correct logic.
9+
- All key values match the semantic meaning provided, which can be validated using the storage layout links provided.
10+
11+
## State Changes
12+
13+
### `<safe_address>` (Base `GnosisSafeProxy`)
14+
15+
- **Key**: `owners[newOwner]` <br/>
16+
**Before**: `0x0000000000000000000000000000000000000000000000000000000000000000` <br/>
17+
**After**: `Next address in the list returned by getOwners()` <br/>
18+
**Meaning**: Sets the address value at the mapping key `owners[newOwner]` to the next address in the list returned by `getOwners()`. This is the first step required to replace the `oldOwner` address in the linked list data structure of owners. <br/>
19+
**Verify**: You can verify the key derivation by running `cast index address <newOwner> 2` in your terminal. See the following section for an explanation of the storage and value calculations.
20+
- **Key**: `owners[prevOwner]` <br/>
21+
**Before**: `oldOwner address` <br/>
22+
**After**: `newOwner address` <br/>
23+
**Meaning**: Points the address value at mapping key `owners[prevOwner]` to the `newOwner` address. This is the second step required to replace the `oldOwner` address in the linked list data structure of owners. <br/>
24+
**Verify**: You can verify the key derivation by running `cast index address <prevOwner> 2` in your terminal. See the following section for an explanation of the storage and value calculations.
25+
- **Key**: `owners[oldOwner]` <br/>
26+
**Before**: `Next address in the list returned by getOwners()` <br/>
27+
**After**: `0x0000000000000000000000000000000000000000000000000000000000000000` <br/>
28+
**Meaning**: Clears the address value at the mapping key `owners[oldOwner]`. This removes the final reference to the `oldOwner` from the `owners` linked list. <br/>
29+
**Verify**: You can verify the key derivation by running `cast index address <oldOwner> 2` in your terminal. See the following section for an explanation of the storage and value calculations.
30+
- **Key**: `0x0000000000000000000000000000000000000000000000000000000000000005` <br/>
31+
**Before**: `Current nonce value (in hexadecimal)` <br/>
32+
**After**: `Current nonce value + 1 (in hexadecimal)` <br/>
33+
**Meaning**: Increments the `nonce` value of the Gnosis Safe. <br/>
34+
**Verify**: You can verify the value by running `cast storage <safe_address> 5 -r <rpc_url>` in your terminal. This value represents the _current_ nonce value.
35+
36+
### `SwapOwner` Storage Calculations
37+
38+
The [`swapOwner`](https://github.com/safe-global/safe-smart-account/blob/8823fa3e44936e2aecf23bb97662eb0ffeff2f93/contracts/base/OwnerManager.sol#L94) function in the Gnosis Safe implementation will perform [three storage changes](https://github.com/safe-global/safe-smart-account/blob/8823fa3e44936e2aecf23bb97662eb0ffeff2f93/contracts/base/OwnerManager.sol#L106-L108):
39+
40+
- Point the `newOwner` address to the owner address that was previously pointed to by the `oldOwner` that is being removed.
41+
- Point the `prevOwner` address to the `newOwner` address.
42+
- Remove the pointer value stored at the mapping of the `oldOwner` address.
43+
44+
These changes are needed on account of the data structure that holds the owners in the Gnosis Safe implementation being a singly-linked list. To calculate the expected storage locations of these mapping values, we can perform the following:
45+
46+
#### Calculating `prevOwner`
47+
48+
The `prevOwner` is identified by the script, but can be manually checked by running the cast command:
49+
50+
```sh
51+
cast call <safe_address> "getOwners()(address[])" -r <rpc_url>
52+
53+
[0x6CD3850756b7894774Ab715D136F9dD02837De50, 0x3cd692eCE8b6573A2220ae00d0dEb98f0DfFA9a1, 0x5FbEFA105bbd53b43bf537Cbc5cD30804Dd0c993, 0x3Dad2200849925Bb46d9bF05aFa5f7F213F4c18E, 0xB011a32ED8b4F70D9943A2199F539bbeCd7b62F7, 0xf9e320f3dA12E68af219d9E2A490Dd649f6B177c]
54+
```
55+
56+
The order that the owner addresses are returned in indicates who the `prevOwner` and next owner values of the address to remove is. If the owner to remove is the 0th value, its `prevOwner` would be the special sentinel node value [`SENTINEL_OWNERS`](https://github.com/safe-global/safe-smart-account/blob/f9cc387f72640eb2c1d6ae8abe9d6ff25ca1ed3b/contracts/base/OwnerManager.sol#L17). Otherwise, if the owner to remove is the last value in the array, its next owner address would be the special sentinel node value [`SENTINEL_OWNERS`](https://github.com/safe-global/safe-smart-account/blob/f9cc387f72640eb2c1d6ae8abe9d6ff25ca1ed3b/contracts/base/OwnerManager.sol#L17).
57+
58+
#### Calculating storage locations and values
59+
60+
With the order of the owners identified, we can calculate the expected storage mapping locations and their values. For the first change, the expected storage slot and value will be the following:
61+
62+
**Storage Slot**: `cast index address <newOwner> 2`
63+
64+
**Value**: The address immediately following `oldOwner` in the `getOwners` list, or the `SENTINEL_OWNERS` special value if the address is the last in the array.
65+
66+
For the second change, it will be:
67+
68+
**Storage Slot**: `cast index address <prevOwner> 2`
69+
70+
**Value**: `newOwner` address
71+
72+
For the final storage change, it will be:
73+
74+
**Storage Slot**: `cast index address <oldOwner> 2`
75+
76+
**Value**: `address(0)`
77+
78+
Note that for all the above storage calculations, we used storage slot 2 as that is the location of the `owners` mapping in the Gnosis Safe storage layout. This can be confirmed with the following command: `cast storage <safe_address> -r <rpc_url> -e <etherscan_api_key>`. Also note that while the storage changes may not appear in the same order in the Tenderly simulation, there should still be 3 storage changes related to the `owner` linked list and one change for the `nonce` value on the `GnosisSafeProxy`. There should be no additional changes to the proxy besides these ones!
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[profile.default]
2+
src = 'src'
3+
out = 'out'
4+
libs = ['lib']
5+
broadcast = 'records'
6+
fs_permissions = [ {access = "read-write", path = "./"} ]
7+
optimizer = true
8+
optimizer_runs = 999999
9+
solc_version = "0.8.15"
10+
via-ir = false
11+
remappings = [
12+
'@eth-optimism-bedrock/=lib/optimism/packages/contracts-bedrock/',
13+
'@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts',
14+
'@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts',
15+
'@rari-capital/solmate/=lib/solmate/',
16+
'@base-contracts/=lib/base-contracts',
17+
'@solady/=lib/solady/src/'
18+
]
19+
20+
# See more config options https://github.com/foundry-rs/foundry/tree/master/config

0 commit comments

Comments
 (0)