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

ETH settlement #9

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e7e8a7e
feat: mempool starter.
l-monninger Feb 27, 2024
94a8352
chore: eth settlement example.
l-monninger Feb 28, 2024
9208d3a
chore: eth settlement example.
l-monninger Feb 28, 2024
1c9af88
add tests
0xmovses Mar 6, 2024
eb0a868
update sol tests
0xmovses Mar 7, 2024
48a5cd1
add mangled test
0xmovses Mar 7, 2024
75bac62
impl Tokenizable
0xmovses Mar 7, 2024
c607f5c
impl Tokenizable
0xmovses Mar 7, 2024
711da88
fix Tokenizable errors, fixes
0xmovses Mar 7, 2024
1681740
add publisher and methods code
0xmovses Mar 7, 2024
7098549
soidity script updates, tweaks
0xmovses Mar 8, 2024
76873fa
updates
0xmovses Mar 11, 2024
9558114
forge test
0xmovses Mar 11, 2024
02553c6
forge install: openzeppelin-contracts
0xmovses Mar 11, 2024
74a00cf
update sol contracts
0xmovses Mar 11, 2024
73aa3a6
fix diff
0xmovses Mar 11, 2024
fb88057
fix merge conflicts
0xmovses Mar 11, 2024
66a2072
Update shared-sequencer/movement-sequencer to match main
0xmovses Mar 11, 2024
511ec04
turn m2 workspace into package
0xmovses Mar 11, 2024
dce2a8f
Revert "Update shared-sequencer/movement-sequencer to match main"
0xmovses Mar 11, 2024
138ffcd
reorg workspace
0xmovses Mar 11, 2024
eaf4237
workspace updates
0xmovses Mar 11, 2024
4469238
update submodules paths, update .gitignores
0xmovses Mar 11, 2024
bf232df
fix .gitignore typo
0xmovses Mar 11, 2024
4b403be
clean
0xmovses Mar 11, 2024
4f01236
clean
0xmovses Mar 11, 2024
0234cfd
add lib submodule
0xmovses Mar 11, 2024
3557e9a
forge install: openzeppelin-contracts
0xmovses Mar 11, 2024
6a679ff
cleanup workspace, remove dead Cargo.tomls
0xmovses Mar 11, 2024
bcec02d
create testing structure and utils
0xmovses Mar 12, 2024
ed03f42
create eth client
0xmovses Mar 12, 2024
68c76ef
update testing tooling
0xmovses Mar 12, 2024
5804de7
update integration tests
0xmovses Mar 13, 2024
6aa6095
path update
0xmovses Mar 15, 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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,10 @@
Cargo.lock
methods/guest/Cargo.lock
target/

# Ignores Foundry Generated files
## Generated ABI files in the /out dir
protocol-units/eth-settlement/contracts/out
protocol-units/eth-settlement/contracts/broadcast
protocol-units/eth-settlement/contracts/broadcast/*/31337/
protocol-units/eth-settlement/contracts/broadcast/**/dry-run/
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@
[submodule "vendors/ed25519-dalek"]
path = movement-sdk/vendors/ed25519-dalek
url = https://github.com/movemntdev/ed25519-dalek
[submodule "protocol-units/eth-settlement/contracts/lib/forge-std"]
path = protocol-units/eth-settlement/contracts/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "protocol-units/eth-settlement/contracts/lib/openzeppelin-contracts"]
path = protocol-units/eth-settlement/contracts/lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
46 changes: 42 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,29 +1,53 @@
[workspace.package]
authors = ["Movement Labs"]
edition = "2021"
version = "0.1.0"
repository = "https://github.com/movemntdev/sdk"
license = "Apache-2.0"

[workspace]
resolver = "2"
members = [
"protocol-units/data-availability",
"protocol-units/zkfp/host",
"protocol-units/zkfp/methods",
"protocol-units/zkfp/methods/guest"
"protocol-units/eth-settlement/eth-adapter",
"protocol-units/eth-settlement/eth-publisher",
"protocol-units/eth-settlement/methods",
"protocol-units/eth-settlement/contracts",
"protocol-units/clients/eth",
"tests/integration/methods",
"tests/integration",

]

exclude = [
"protocol-units/zkfp/host",
"protocol-units/zkfp/methods",
"protocol-units/zkfp/methods/guest",
"shared-sequencer/movement-sequencer"
]

[workspace.dependencies]
anyhow = "1.0"
async-trait = { version = "0.1" }
alloy-primitives = { version = "0.6", default-features = false, features = ["rlp", "serde", "std"] }
alloy-sol-types = { version = "0.6" }
bincode = { version = "1.3" }
tokio = { version = "1", features = ["full"] }
# To try (experimental) std support, add `features = [ "std" ]` to risc0-zkvm
risc0-zkvm = { version = "0.20.1", features = ["std"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
serde = "1.0"
serde_json = "1.0.68"
log = { version = "0.4" }
tempfile = "3.2.0"
ethers = { version = "2.0" }
hex = "0.4.3"
bytemuck = { version = "1.14" }

# Sovereign Labs dependencies
sov-rollup-interface = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "nightly", features = ["native"] }
sov-mock-da = { git = "https://github.com/Sovereign-Labs/sovereign-sdk.git", branch = "nightly", features = ["native"] }
web3 = "0.19.0"

# Move dependencies
move-vm-runtime = { path = "protocol-units/zkfp/vendors/move/language/move-vm/runtime" }
Expand All @@ -34,6 +58,20 @@ move-core-types = { path = "protocol-units/zkfp/vendors/move/language/move-core/
move-compiler = { path = "protocol-units/zkfp/vendors/move/language/move-compiler" }
move-stdlib = { path = "protocol-units/zkfp/vendors/move/language/move-stdlib" }

# Risc0 dependencies
# NOTE: Using a git rev temporarily to get an unreleased version of risc0-build.
# Once the referenced commit is in a released version of risc0-build, this will go back to using a version.
bonsai-rest-api-mock = { version = "0.6.1", default-features = false }
bonsai-sdk = { version = "0.6.1", default-features = false }
risc0-build = { git = "https://github.com/risc0/risc0", rev = "7f731662", features = ["docker"] }
risc0-build-ethereum = { git = "https://github.com/risc0/risc0-ethereum", branch = "release-0.7" }
risc0-ethereum-relay= { git = "https://github.com/risc0/risc0-ethereum", branch = "release-0.7" }
risc0-ethereum-contracts = { git = "https://github.com/risc0/risc0-ethereum", branch = "release-0.7" }
risc0-zkvm = { version = "0.20.1", features = ["std"] }
risc0-zkp = { version = "0.20", default-features = false }

eth-relay-test-methods = { path = "./tests/integration/methods" }


# Always optimize; building and running the guest takes much longer without optimization.
[profile.dev]
Expand Down
8 changes: 8 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[profile.default]
src = "contracts"
out = "out"
libs = ["lib"]
test = "tests"
ffi = true

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
39 changes: 0 additions & 39 deletions protocol-units/Cargo.toml

This file was deleted.

16 changes: 16 additions & 0 deletions protocol-units/clients/eth/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "eth-client"
version = "0.1.0"
edition = "2021"

[lib]
path = "src/lib.rs"

[dependencies]
anyhow = { workspace = true }
ethers = { workspace = true }
hex = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }

risc0-ethereum-relay = { workspace = true }
119 changes: 119 additions & 0 deletions protocol-units/clients/eth/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
use std::{str::FromStr, time::Duration};
use anyhow::{anyhow, Context, Error, Result};
use ethers::{
core::k256::{ecdsa::SigningKey, SecretKey},
middleware::SignerMiddleware,
prelude::*,
providers::{Provider, Ws},
};
use risc0_ethereum_relay::EthersClientConfig as Risc0EthersClientConfig;
use tracing::{debug, error};

/// We use this in combination with `EthersClientConfig` to
/// create the client. An example of this can be found in tests/integration/src/lib.rs.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct WalletKey(SecretKey);

impl TryFrom<String> for WalletKey {
type Error = Error;
fn try_from(value: String) -> Result<Self, Self::Error> {
let decoded =
hex::decode(value.trim_start_matches("0x")).context("Failed to decode private key.")?;
let key =
SecretKey::from_slice(&decoded).context("Failed to derive SecretKey instance.")?;
Ok(Self(key))
}
}

impl FromStr for WalletKey {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
s.to_string().try_into()
}
}

impl From<SecretKey> for WalletKey {
fn from(value: SecretKey) -> Self {
Self(value)
}
}

impl From<WalletKey> for SecretKey {
fn from(value: WalletKey) -> Self {
value.0
}
}

impl WalletKey {
pub fn get_key(&self) -> SecretKey {
self.0.clone()
}
}

type EthersClientConfig = Risc0EthersClientConfig;

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct EthersClientConfig {
pub eth_node_url: String,
pub eth_chain_id: u64,
pub wallet_key_identifier: WalletKey,
pub retries: u64,
pub wait_time: Duration,
}

impl EthersClientConfig {
pub fn new(
eth_node_url: String,
eth_chain_id: u64,
wallet_key_identifier: WalletKey,
retries: u64,
wait_time: Duration,
) -> Self {
Self {
eth_node_url,
eth_chain_id,
wallet_key_identifier,
retries,
wait_time,
}
}

pub async fn get_client(&self) -> Result<SignerMiddleware<Provider<Ws>, Wallet<SigningKey>>> {
let provider = self.provider().await?;
let signer = self.get_signer()?;
let client = SignerMiddleware::new(provider, signer);
Ok(client)
}

pub async fn provider(&self) -> Result<Provider<Ws>> {
let provider = Provider::<Ws>::connect_with_reconnects(self.eth_node_url.clone(), 60)
.await
.context("Failed to connect to Ethereum node.")?;
Ok(provider)
}

pub fn get_signer(&self) -> Result<Wallet<SigningKey>> {
let signing_key = SigningKey::from(self.wallet_key_identifier.get_key());
let signer = LocalWallet::from(signing_key).with_chain_id(self.eth_chain_id);
Ok(signer)
}

pub async fn get_client_with_reconnects(
&self,
) -> Result<SignerMiddleware<Provider<Ws>, Wallet<SigningKey>>> {
for _ in 0..self.retries {
let client = self.get_client().await;
if client.is_ok() {
return client;
} else {
debug!(
"Failed to create client. Retrying in {:?} seconds.",
self.wait_time.as_secs()
);
tokio::time::sleep(self.wait_time).await;
}
}
error!("Failed to create client.");
Err(anyhow!("Failed to create client."))
}
}
33 changes: 33 additions & 0 deletions protocol-units/eth-settlement/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# `m2`

## `eth-settlement`
To run the tests, first install the following dependencies:
- foundry

Start the Anvil local network:
```bash
anvil
```

Deploy the contracts in `contracts/eth-settlement`:
```bash
# from root of the project
cd contracts/eth-settlement
forge script script/DeploySettlement.s.sol --broadcast --rpc-url http://localhost:8545 --private-key <pick-key-from-anvil-avialable-accounts>
```

**Note**: Never use the private key above in production.

Set your environment variables:
```bash
ETH_RPC_URL=http://localhost:8545
ETH_CONTRACT_ADDRESS=<deployed-contract-address>
ETH_CONTRACT_ABI_PATH=../contracts/eth-settlement/out/Settlement.sol/Settlement.json
```

Run the tests:
```bash
# from root of the project
cd eth-settlement
cargo test test_eth_settlement_service_env
```
11 changes: 11 additions & 0 deletions protocol-units/eth-settlement/contracts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "eth-contracts"
version = "0.1.0"
edition = "2021"
description = "Movement Labs Contracts for Eth Settlement with Risc0 Groth16 Bonsai service"

[lib]
path = "src/lib.rs"

[dependencies]
ethers = { workspace = true }
23 changes: 23 additions & 0 deletions protocol-units/eth-settlement/contracts/ImageID.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0

// This file is automatically generated

pragma solidity ^0.8.20;

library ImageID {
bytes32 public constant IS_EVEN_ID = bytes32(0x04d6ce2d1c7ffa390e73114c5213f76aada67c8301d88b7698a48fd7543a444b);
}
Loading
Loading