Skip to content

Commit a2ad64c

Browse files
key management contract implmentation (#440)
* update readme with additional pre-requisites for those new to the project * wip timeboost contracts, alloy contract binding * quick test of contract deployment in rust, added contract related builds and tests in the ci workflow * Fix forge-std submodule * rust lint fix * reorg contracts * use build.rs instead of forge bind * update deployer * fmt after gen bindings, update justfile * update CI * add foundry toolchain in CI tasks and run forge build in build.rs * wip removed unused vars and added additional functions based on design feedback * added nextCommittee(), refactored events and errors * remove gen bindings command reference in readme * add storage gap for upgradeability in the event the base contract is changed * improve contract extensibility by adding the vi rtual keyword to key functions so that child contracts can upgrade them if necessary * changed storage from arrays to mappings to make deletions more straight-forward, changed currentCommittee logic and add delete by id function * changed field names in the committeemember, replace removeCOmmittee() with pruneUNtil() for bulk deletion and removed linked list complexity * refactor: remove unused or duplicate errors, optimize gas usage a bit * rename contract events and updated tests * always regen bindings, forge fmt * ci: install foundry toolchain for timeboost ci * fix cargo::error instruction, add nightly rustfmt --------- Co-authored-by: Alex Xiong <[email protected]>
1 parent 69ae488 commit a2ad64c

File tree

18 files changed

+987
-8
lines changed

18 files changed

+987
-8
lines changed

.github/workflows/build-and-test.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ jobs:
3131
wget https://github.com/casey/just/releases/download/1.14.0/just-1.14.0-x86_64-unknown-linux-musl.tar.gz
3232
tar -vxf just-1.14.0-x86_64-unknown-linux-musl.tar.gz just
3333
sudo cp just /usr/bin/just
34+
- name: Install rustfmt for nightly
35+
run: rustup component add --toolchain nightly rustfmt
36+
- name: Install Foundry
37+
uses: foundry-rs/foundry-toolchain@v1
3438
- name: Install protobuf compiler
3539
run: |
3640
sudo apt-get update
@@ -60,6 +64,10 @@ jobs:
6064
wget https://github.com/casey/just/releases/download/1.14.0/just-1.14.0-x86_64-unknown-linux-musl.tar.gz
6165
tar -vxf just-1.14.0-x86_64-unknown-linux-musl.tar.gz just
6266
sudo cp just /usr/bin/just
67+
- name: Install rustfmt for nightly
68+
run: rustup component add --toolchain nightly rustfmt
69+
- name: Install Foundry
70+
uses: foundry-rs/foundry-toolchain@v1
6371
- name: Run tests
6472
run: just test_ci
6573

@@ -81,10 +89,13 @@ jobs:
8189
sudo cp just /usr/bin/just
8290
- name: Install rustfmt for nightly
8391
run: rustup component add --toolchain nightly rustfmt
92+
- name: Install Foundry
93+
uses: foundry-rs/foundry-toolchain@v1
8494
- name: Check packages individually
8595
run: just check-individually
8696
- name: Run lint
8797
run: just lint
98+
8899
build-docker:
89100
runs-on: ubuntu-latest
90101
steps:
@@ -100,6 +111,7 @@ jobs:
100111
sudo cp just /usr/bin/just
101112
- name: Build Docker
102113
run: just build_docker
114+
103115
integration:
104116
runs-on: ubuntu-latest
105117
timeout-minutes: 25
@@ -117,12 +129,36 @@ jobs:
117129
wget https://github.com/casey/just/releases/download/1.14.0/just-1.14.0-x86_64-unknown-linux-musl.tar.gz
118130
tar -vxf just-1.14.0-x86_64-unknown-linux-musl.tar.gz just
119131
sudo cp just /usr/bin/just
132+
- name: Install rustfmt for nightly
133+
run: rustup component add --toolchain nightly rustfmt
134+
- name: Install Foundry
135+
uses: foundry-rs/foundry-toolchain@v1
120136
- name: Run tests
121137
run: just run_demo -s /tmp/stamp --ignore-stamp --yapper -k test-configs/local-5.json
122138
- name: Run tests with late-start node
123139
run: just run_demo -l -s /tmp/stamp --ignore-stamp --yapper -k test-configs/local-5.json
124140
- name: Run sailfish demo
125141
run: just run_sailfish_demo
142+
143+
contracts:
144+
runs-on: ubuntu-latest
145+
steps:
146+
- uses: actions/checkout@v4
147+
with:
148+
submodules: recursive
149+
fetch-depth: 0
150+
- name: Install Just
151+
run: |
152+
wget https://github.com/casey/just/releases/download/1.14.0/just-1.14.0-x86_64-unknown-linux-musl.tar.gz
153+
tar -vxf just-1.14.0-x86_64-unknown-linux-musl.tar.gz just
154+
sudo cp just /usr/bin/just
155+
- name: Install rustfmt for nightly
156+
run: rustup component add --toolchain nightly rustfmt
157+
- name: Install Foundry
158+
uses: foundry-rs/foundry-toolchain@v1
159+
- name: Run contract tests
160+
run: forge test -vvv
161+
126162
nitro-timeboost-integration:
127163
runs-on: ubuntu-latest
128164
timeout-minutes: 60
@@ -140,6 +176,10 @@ jobs:
140176
wget https://github.com/casey/just/releases/download/1.14.0/just-1.14.0-x86_64-unknown-linux-musl.tar.gz
141177
tar -vxf just-1.14.0-x86_64-unknown-linux-musl.tar.gz just
142178
sudo cp just /usr/bin/just
179+
- name: Install rustfmt for nightly
180+
run: rustup component add --toolchain nightly rustfmt
181+
- name: Install Foundry
182+
uses: foundry-rs/foundry-toolchain@v1
143183
- name: Clone Espresso Testnode Repository
144184
run: |
145185
git clone --recursive https://github.com/EspressoSystems/decentralized-timeboost-nitro-testnode.git

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,7 @@ timeboost-proto/src/*.rs
3131
bacon.toml
3232

3333
__pycache__/
34+
*.DS_Store
3435

36+
# Rust bindings for smart contracts
37+
timeboost-contract/src/bindings

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "timeboost-proto/protos"]
22
path = timeboost-proto/protos
33
url = https://github.com/EspressoSystems/timeboost-proto.git
4+
[submodule "contracts/lib/openzeppelin-contracts-upgradeable"]
5+
path = contracts/lib/openzeppelin-contracts-upgradeable
6+
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable

Cargo.lock

Lines changed: 65 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ members = [
1111
"tests",
1212
"timeboost",
1313
"timeboost-builder",
14+
"timeboost-contract",
1415
"timeboost-crypto",
1516
"timeboost-proto",
1617
"timeboost-sequencer",
@@ -28,7 +29,8 @@ rust-version = "1.85.0"
2829

2930
[workspace.dependencies]
3031
aes-gcm = { version = "0.10.3" }
31-
alloy = { version = "1.0", features = ["default", "arbitrary", "k256", "serde", "rlp"] }
32+
alloy = { version = "1.0", features = ["default", "arbitrary", "k256", "serde", "rlp", "node-bindings", "getrandom"] }
33+
alloy-chains = "0.2"
3234
# derive feature is not exposed via `alloy`, thus has to explicitly declare here
3335
alloy-rlp = { version = "0.3.12", features = ["derive"] }
3436
anyhow = "1.0.89"

README.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,29 @@ of the protocol in Rust, as well as exhaustive testing. The layout of the reposi
3030
- `timeboost-proto`: Contains protobuf schema and protobuf generated code for inlusion list
3131
- `yapper`: Transaction submission test tool.
3232

33-
## MSRV (minimum supported Rust version)
34-
The MSRV of this repository is 1.85.
33+
## Pre-requisites
34+
- **Rust toolchain** (Minimum supported rust version (MSRV): 1.88): [Install via rustup](https://rustup.rs/)
35+
- **just** (for command aliases):
36+
```sh
37+
cargo install just
38+
```
39+
- **cargo-nextest** (for running tests):
40+
```sh
41+
cargo install cargo-nextest
42+
```
43+
44+
- **Foundry** (for Solidity development and testing): [Install Foundry](https://book.getfoundry.sh/getting-started/installation)
45+
```sh
46+
curl -L https://foundry.paradigm.xyz | bash
47+
foundryup
48+
```
49+
50+
- **Docker** (for integration tests, if needed): [Install Docker](https://docs.docker.com/get-docker/)
51+
52+
- **Initialize Submodules:**
53+
```sh
54+
git submodule update --init --recursive
55+
```
3556

3657
## Build
3758

@@ -45,6 +66,11 @@ Release build
4566
just build_release
4667
```
4768

69+
## Contracts Build
70+
```sh
71+
just build-contracts
72+
```
73+
4874
## Run
4975

5076
Run in docker
@@ -87,6 +113,11 @@ ln -s ../../scripts/pre-commit .git/hooks/pre-commit
87113
just test
88114
```
89115

116+
Contracts test
117+
```shell
118+
just test-contracts
119+
```
120+
90121
[noise]: https://noiseprotocol.org/
91122
[sailfish]: https://eprint.iacr.org/2024/472.pdf
92-
[timeboost]: https://github.com/OffchainLabs/decentralized-timeboost-spec
123+
[timeboost]: https://github.com/OffchainLabs/decentralized-timeboost-spec

contracts/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Compiler files
2+
cache/
3+
out/
4+
5+
# Ignores development broadcast logs
6+
!/broadcast
7+
/broadcast/*/31337/
8+
/broadcast/**/dry-run/
9+
10+
# Docs
11+
docs/
12+
13+
# Dotenv file
14+
.env

0 commit comments

Comments
 (0)