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

Feature: L1 <> L2 messaging with Token Bridge example #253

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5f8715a
Add token bridge scaffold
0xNeshi Oct 21, 2024
33188fc
Create L2 bridge
0xNeshi Oct 21, 2024
251ff2c
Add tests for L2 bridge
0xNeshi Oct 21, 2024
5b507bb
Add solidity bridge contract
0xNeshi Oct 21, 2024
b4e93b5
rename consumeMessage->consumeWithdrawal & initiateWithdrawal->bridge…
0xNeshi Oct 22, 2024
bbf3a56
Rename initiate_withdrawal->bridge_to_l1
0xNeshi Oct 22, 2024
7efed11
make TokenBridge work + add tests
0xNeshi Oct 22, 2024
1936c31
Add ability to set l2bridge post deployment
0xNeshi Oct 22, 2024
8bc413f
Add ability to set l1bridge and token post deployment to cairo
0xNeshi Oct 22, 2024
8cd9ff3
Add getters + pass governor in ctor
0xNeshi Oct 22, 2024
db4565a
Split uint256 amount to low/high before bridging to L2
0xNeshi Oct 22, 2024
f4d5687
TokenBridge: remove token from ctor + token ops limited to bridge
0xNeshi Oct 23, 2024
ad6fcae
Move starknet contracts to lib
0xNeshi Oct 23, 2024
09a3ff0
leave source to orig strk mess local
0xNeshi Oct 23, 2024
08a0a14
make l2 handler selector customizable
0xNeshi Oct 23, 2024
8fa90a1
manually set token and l1 bridge address in STRK
0xNeshi Oct 23, 2024
0170de5
MintableTokenMock: OnlyBridge->Unauthorized
0xNeshi Oct 23, 2024
195bb71
Strk: set token post-ctor + add missing mock token
0xNeshi Oct 23, 2024
f9ca0f6
add comments to contract.cairo
0xNeshi Oct 23, 2024
28bac93
Remove cache and out from solidity
0xNeshi Oct 23, 2024
4602eef
move ./cairo contents to root folder
0xNeshi Oct 23, 2024
30ed1c7
mintableToken->token
0xNeshi Oct 23, 2024
c018053
Merge remote-tracking branch 'origin/main' into l1-l2-token-bridge
0xNeshi Oct 23, 2024
5813aaf
Remove redundant l1_bridge felt252 init in tests
0xNeshi Oct 23, 2024
3d18859
mocks.cairo->mintable_token_mock.cairo
0xNeshi Oct 23, 2024
b8b57e1
Update the .md file
0xNeshi Oct 23, 2024
8e0c198
remove TokenBridge @author tag
0xNeshi Oct 23, 2024
8a1ea4c
Merge remote-tracking branch 'origin/main' into l1-l2-token-bridge
0xNeshi Oct 24, 2024
6ce10e8
Update edition to point to workspace
0xNeshi Oct 24, 2024
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
8 changes: 8 additions & 0 deletions Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ version = "0.1.0"
name = "interfaces_traits"
version = "0.1.0"

[[package]]
name = "l1_l2_token_bridge"
version = "0.1.0"
dependencies = [
"openzeppelin",
"snforge_std",
]

[[package]]
name = "library_calls"
version = "0.1.0"
Expand Down
2 changes: 2 additions & 0 deletions listings/applications/l1_l2_token_bridge/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target
.snfoundry_cache/
17 changes: 17 additions & 0 deletions listings/applications/l1_l2_token_bridge/Scarb.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "l1_l2_token_bridge"
version.workspace = true
edition = "2024_07"

[dependencies]
starknet.workspace = true
openzeppelin.workspace = true

[dev-dependencies]
assert_macros.workspace = true
snforge_std.workspace = true

[scripts]
test.workspace = true

[[target.starknet-contract]]
2 changes: 2 additions & 0 deletions listings/applications/l1_l2_token_bridge/solidity/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cache
out
66 changes: 66 additions & 0 deletions listings/applications/l1_l2_token_bridge/solidity/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
## Foundry

**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**

Foundry consists of:

- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.

## Documentation

https://book.getfoundry.sh/

## Usage

### Build

```shell
$ forge build
```

### Test

```shell
$ forge test
```

### Format

```shell
$ forge fmt
```

### Gas Snapshots

```shell
$ forge snapshot
```

### Anvil

```shell
$ anvil
```

### Deploy

```shell
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
```

### Cast

```shell
$ cast <subcommand>
```

### Help

```shell
$ forge --help
$ anvil --help
$ cast --help
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[profile.default]
src = "src"
out = "out"
libs = ["lib"]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
remappings = ["starknet/=lib/starknet/"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/Vm.sol linguist-generated
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of notes/questions:

  • I added tests for the Solidity contracts to ensure correctness, and opted for Foundry for consistency (as we already use it for Starknet contract tests). If you think this adds to many other files (see next point), and don't think they're that necessary for this example, we can delete.
  • forge-std library is included in the source, as it makes it any extra setup unnecessary to run tests for the Solidity TokenBridge in the future. Let me know if you want this removed, and we can add a README note with instructions on how to set this up.
  • I didn't update ./scripts/cairo_programs_verifier.sh to run Solidity tests, but this can be done.

Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: CI

on:
workflow_dispatch:
pull_request:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Print forge version
run: forge --version

# Backwards compatibility checks:
# - the oldest and newest version of each supported minor version
# - versions with specific issues
- name: Check compatibility with latest
if: always()
run: |
output=$(forge build --skip test)
if echo "$output" | grep -q "Warning"; then
echo "$output"
exit 1
fi

- name: Check compatibility with 0.8.0
if: always()
run: |
output=$(forge build --skip test --use solc:0.8.0)
if echo "$output" | grep -q "Warning"; then
echo "$output"
exit 1
fi

- name: Check compatibility with 0.7.6
if: always()
run: |
output=$(forge build --skip test --use solc:0.7.6)
if echo "$output" | grep -q "Warning"; then
echo "$output"
exit 1
fi

- name: Check compatibility with 0.7.0
if: always()
run: |
output=$(forge build --skip test --use solc:0.7.0)
if echo "$output" | grep -q "Warning"; then
echo "$output"
exit 1
fi

- name: Check compatibility with 0.6.12
if: always()
run: |
output=$(forge build --skip test --use solc:0.6.12)
if echo "$output" | grep -q "Warning"; then
echo "$output"
exit 1
fi

- name: Check compatibility with 0.6.2
if: always()
run: |
output=$(forge build --skip test --use solc:0.6.2)
if echo "$output" | grep -q "Warning"; then
echo "$output"
exit 1
fi

# via-ir compilation time checks.
- name: Measure compilation time of Test with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationTest.sol --use solc:0.8.17 --via-ir

- name: Measure compilation time of TestBase with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationTestBase.sol --use solc:0.8.17 --via-ir

- name: Measure compilation time of Script with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationScript.sol --use solc:0.8.17 --via-ir

- name: Measure compilation time of ScriptBase with 0.8.17 --via-ir
if: always()
run: forge build --skip test --contracts test/compilation/CompilationScriptBase.sol --use solc:0.8.17 --via-ir

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Print forge version
run: forge --version

- name: Run tests
run: forge test -vvv

fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Print forge version
run: forge --version

- name: Check formatting
run: forge fmt --check
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Sync Release Branch

on:
release:
types:
- created

jobs:
sync-release-branch:
runs-on: ubuntu-latest
if: startsWith(github.event.release.tag_name, 'v1')
steps:
- name: Check out the repo
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: v1

# The email is derived from the bots user id,
# found here: https://api.github.com/users/github-actions%5Bbot%5D
- name: Configure Git
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com

- name: Sync Release Branch
run: |
git fetch --tags
git checkout v1
git reset --hard ${GITHUB_REF}
git push --force
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cache/
out/
.vscode
.idea
Loading