Skip to content

Commit

Permalink
Merge branch 'usage_and_setup' into usage_and_setup_changes
Browse files Browse the repository at this point in the history
  • Loading branch information
xqft authored Oct 2, 2024
2 parents dab8387 + 1a37d7f commit e5f190e
Show file tree
Hide file tree
Showing 23 changed files with 321 additions and 237 deletions.
4 changes: 3 additions & 1 deletion .env.template
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
ETH_CHAIN=<devnet/holesky>
MINA_RPC_URL=<url>
STATE_SETTLEMENT_ETH_ADDR=<address>
ACCOUNT_VALIDATION_ETH_ADDR=<address>
SAVE_PROOF=true/false # also false if other than "true" or variable were to be not defined

## These can be skipped if using devnet with Anvil.
Expand All @@ -9,7 +11,7 @@ SAVE_PROOF=true/false # also false if other than "true" or variable were to be n
# PROOF_GENERATOR_ADDR=<optional>
# BRIDGE_HOLESKY_ETH_ADDR=<optional>
# BRIDGE_ACCOUNT_HOLESKY_ETH_ADDR=<optional>
# ALIGNED_SM_HOLESKY_ETH_ADDR=<optional>
# ALIGNED_SERVICE_MANAGER_ADDR=<optional>

## You can choose to use a keystore or private key for your signing wallet.
## Leave empty if choosing Anvil Devnet.
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
.PHONY: submit-state submit-account gen_contract_abi deploy_contract
.PHONY: submit_mainnet_state submit_devnet_state submit_account gen_contract_abi deploy_contract

submit_state:
submit_mainnet_state:
@cargo run --manifest-path core/Cargo.toml --release -- submit-state

submit_devnet_state:
@cargo run --manifest-path core/Cargo.toml --release -- submit-state --devnet

submit_account:
@cargo run --manifest-path core/Cargo.toml --release -- submit-account ${PUBLIC_KEY} ${STATE_HASH}

Expand Down
74 changes: 41 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The bridge leverages [Aligned Layer](https://github.com/yetanotherco/aligned_lay
### Mina node

- If you want the Bridge to use Mina Devnet then use a node that runs a Devnet instance corresponding to the commit `599a76d` [of the Mina repo](https://github.com/MinaProtocol/mina/tree/599a76dd47be99183d2102d9eb93eda679dd46ec) or a newer one (e.g.: [this Docker image](https://console.cloud.google.com/gcr/images/o1labs-192920/GLOBAL/mina-daemon:3.0.1-compatible-599a76d-bullseye-devnet/details)). See [how to connect to Mina Devnet](https://docs.minaprotocol.com/node-operators/block-producer-node/connecting-to-devnet#docker) if you want to run an instance yourself.
- If you want the Bridge to use Mina Mainnet use a node that runs a Mainnet instance corresponding to the commit `65c84ad` [of the Mina repo](https://github.com/MinaProtocol/mina/tree/65c84adacd55272160d9f77c31063d94a942afb6) or a newer one (e.g.: [this Docker image](https://console.cloud.google.com/gcr/images/o1labs-192920/GLOBAL/mina-daemon:65c84ada-bullseye-mainnet/details?tab=info)). See [how to connect to Mina Mainnet](https://docs.minaprotocol.com/node-operators/block-producer-node/connecting-to-the-network#docker) if you want to run an instance yourself.
- If you want the Bridge to use Mina Mainnet use a node that runs a Mainnet instance corresponding to the commit `65c84ad` [of the Mina repo](https://github.com/MinaProtocol/mina/tree/65c84adacd55272160d9f77c31063d94a942afb6) or a newer one (e.g.: [this Docker image](http://gcr.io/o1labs-192920/mina-daemon:3.0.1-beta1-sai-query-snarked-ledger-c439ce5-bullseye-mainnet)). See [how to connect to Mina Mainnet](https://docs.minaprotocol.com/node-operators/block-producer-node/connecting-to-the-network#docker) if you want to run an instance yourself.

You can bridge Mina accounts to Ethereum Devnet or Ethereum Testnet. The following subsections describe how to config the Bridge for each network.

Expand All @@ -38,7 +38,7 @@ Because the Bridge uses for now a forked version of Aligned, you may need to set

You will need two Ethereum accounts: One to fund the Aligned operator (`operator_account_address`) and another to fund the Aligned batcher (`batcher_account_address`).

1. Clone the [forked Aligned repo](https://github.com/lambdaclass/aligned_layer). Checkout to the `aligned` branch.
1. Clone the [forked Aligned repo](https://github.com/lambdaclass/aligned_layer). Checkout to the `mina` branch.
1. Run:

```sh
Expand Down Expand Up @@ -93,7 +93,7 @@ You will need two Ethereum accounts: One to fund the Aligned operator (`operator

1. Deploy the contracts with `make deploy_aligned_contracts`.

1. `contracts/script/output/holesky/alignedlayer_deployment_output.json` should have been updated automatically. Set the `permissions` field on that file:
`contracts/script/output/holesky/alignedlayer_deployment_output.json` should have been updated automatically. Set the `permissions` field on that file:

```json
{
Expand All @@ -112,7 +112,7 @@ You will need two Ethereum accounts: One to fund the Aligned operator (`operator
"pauserRegistry": "0x85Ef7299F8311B25642679edBF02B62FA2212F06"
}
}
```
```

1. Create 3 EigenLayer keystores:
1. Aggregator and operator ECDSA:
Expand Down Expand Up @@ -141,21 +141,21 @@ You will need two Ethereum accounts: One to fund the Aligned operator (`operator
environment: "production"
aligned_layer_deployment_config_file_path: "./contracts/script/output/holesky/alignedlayer_deployment_output.json"
eigen_layer_deployment_config_file_path: "./contracts/script/output/holesky/eigenlayer_deployment_output.json"
eth_rpc_url: "https://holesky.internal.lambdaclass.com"
eth_rpc_url_fallback: "https://holesky.internal.lambdaclass.com"
eth_ws_url: "wss://ws.holesky.internal.lambdaclass.com"
eth_ws_url_fallback: "wss://ws.holesky.internal.lambdaclass.com"
eth_rpc_url: "<http_eth_rpc_url>"
eth_rpc_url_fallback: "<http_eth_rpc_url>"
eth_ws_url: "<ws_eth_rpc_url>"
eth_ws_url_fallback: "<ws_eth_rpc_url>"
eigen_metrics_ip_port_address: "localhost:9090"
## ECDSA Configurations
ecdsa:
private_key_store_path: "<home>/.eigenlayer/operator_keys/mina_bridge.ecdsa.key.json"
private_key_store_password: "<password_used_to_create_keystore>"
private_key_store_password: <password_used_to_create_keystore>
## BLS Configurations
bls:
private_key_store_path: "<home>/.eigenlayer/operator_keys/mina_bridge.bls.key.json"
private_key_store_password: "<password_used_to_create_keystore>"
private_key_store_password: <password_used_to_create_keystore>
## Batcher configurations
batcher:
Expand Down Expand Up @@ -201,21 +201,21 @@ You will need two Ethereum accounts: One to fund the Aligned operator (`operator
environment: "production"
aligned_layer_deployment_config_file_path: "./contracts/script/output/holesky/alignedlayer_deployment_output.json"
eigen_layer_deployment_config_file_path: "./contracts/script/output/holesky/eigenlayer_deployment_output.json"
eth_rpc_url: "https://holesky.internal.lambdaclass.com"
eth_rpc_url_fallback: "https://holesky.internal.lambdaclass.com"
eth_ws_url: "wss://ws.holesky.internal.lambdaclass.com"
eth_ws_url_fallback: "wss://ws.holesky.internal.lambdaclass.com"
eth_rpc_url: "<http_eth_rpc_url>"
eth_rpc_url_fallback: "<http_eth_rpc_url>"
eth_ws_url: "<ws_eth_rpc_url>"
eth_ws_url_fallback: "<ws_eth_rpc_url>"
eigen_metrics_ip_port_address: "localhost:9090"
## ECDSA Configurations
ecdsa:
private_key_store_path: "<home>/.eigenlayer/operator_keys/mina_bridge.ecdsa.key.json"
private_key_store_password: "<password_used_to_create_keystore>"
private_key_store_password: <password_used_to_create_keystore>
## BLS Configurations
bls:
private_key_store_path: "<home>/.eigenlayer/operator_keys/mina_bridge.bls.key.json"
private_key_store_password: "<password_used_to_create_keystore>"
private_key_store_password: <password_used_to_create_keystore>
## Aggregator Configurations
aggregator:
Expand All @@ -229,21 +229,19 @@ You will need two Ethereum accounts: One to fund the Aligned operator (`operator
1. Create `config-files/holesky/config-batcher.yaml` and set it to:

```yaml
# Common variables for all the services
# 'production' only prints info and above. 'development' also prints debug
environment: "production"
aligned_layer_deployment_config_file_path: "./contracts/script/output/holesky/alignedlayer_deployment_output.json"
eigen_layer_deployment_config_file_path: "./contracts/script/output/holesky/eigenlayer_deployment_output.json"
eth_rpc_url: "https://holesky.internal.lambdaclass.com"
eth_rpc_url_fallback: "https://holesky.internal.lambdaclass.com"
eth_ws_url: "wss://ws.holesky.internal.lambdaclass.com"
eth_ws_url_fallback: "wss://ws.holesky.internal.lambdaclass.com"
eth_rpc_url: "<http_eth_rpc_url>"
eth_rpc_url_fallback: "<http_eth_rpc_url>"
eth_ws_url: "<ws_eth_rpc_url>"
eth_ws_url_fallback: "<ws_eth_rpc_url>"
eigen_metrics_ip_port_address: "localhost:9090"
## ECDSA Configurations
ecdsa:
private_key_store_path: "<home>/.eigenlayer/operator_keys/mina_bridge.batcher.ecdsa.key.json"
private_key_store_password: "<password_used_to_create_keystore>"
private_key_store_password: <password_used_to_create_keystore>
## Batcher configurations
batcher:
Expand Down Expand Up @@ -276,6 +274,8 @@ You will need two Ethereum accounts: One to fund the Aligned operator (`operator
make operator_whitelist OPERATOR_ADDRESS=<operator_account_address>
```

1. Deposit Strategy tokens for the operator. Follow [this section from the AlignedLayer docs](https://docs.alignedlayer.com/operators/0_running_an_operator#step-4-deposit-strategy-tokens).

1. Start operator:

```sh
Expand All @@ -288,7 +288,7 @@ You will need two Ethereum accounts: One to fund the Aligned operator (`operator
{
"address": {
"batcherWallet": "<batcher_account_address>",
"alignedLayerServiceManager": "0x4d879A997f422FeB8AC2f3d9Dcc749e9d8d0E4a4"
"alignedLayerServiceManager": "<aligned_service_manager_address>"
},
"amounts": {
"gasForAggregator": "300000",
Expand All @@ -314,19 +314,25 @@ You will need two Ethereum accounts: One to fund the Aligned operator (`operator
1. Pay the batcher:

```sh
cast send <batcher_payment_service_address> --rpc-url https://holesky.internal.lambdaclass.com --private-key <batcher_account_private_key> --value 1ether
cast send <batcher_payment_service_address> --rpc-url <eth_rpc_url> --private-key <bridge_account_private_key> --value 1ether
```

1. Deposit to batcher in the Aligned Service Manager Contract:

```sh
cast send 0x4d879A997f422FeB8AC2f3d9Dcc749e9d8d0E4a4 --rpc-url https://holesky.internal.lambdaclass.com --private-key <batcher_account_private_key> --value 1ether "depositToBatcher(address)" <batcher_payment_service_address>
cast send <aligned_service_manager_address> --rpc-url <eth_rpc_url> --private-key <bridge_account_private_key> --value 1ether "depositToBatcher(address)" <batcher_payment_service_address>
```

1. Setup local storage for the batcher:

```sh
make run_storage
```

1. Start the batcher:

```sh
cargo run --manifest-path ./batcher/aligned-batcher/Cargo.toml --release -- --config ./config-files/holesky/config-batcher.yaml --env-file ./batcher/aligned-batcher/.env
cargo run --manifest-path ./batcher/aligned-batcher/Cargo.toml --release -- --config ./config-files/holesky/config-batcher.yaml --env-file ./batcher/aligned-batcher/.env.dev
```

#### Bridge environment setup
Expand All @@ -339,11 +345,11 @@ In the Mina Bridge repo, setup the `.env` file. A template is available in `.env

```sh
BATCHER_ADDR="ws://localhost:8080"
BATCHER_ETH_ADDR=<batcher_payment_service>
BATCHER_ETH_ADDR=<batcher_payment_service_address>
ETH_RPC_URL=<url>
PROOF_GENERATOR_ADDR=0x66f9664f97F2b50F62D13eA064982f936dE76657
PRIVATE_KEY=<operator_account_private_key>
ALIGNED_SM_HOLESKY_ETH_ADDR=0x4d879A997f422FeB8AC2f3d9Dcc749e9d8d0E4a4
PRIVATE_KEY=<bridge_account_private_key>
ALIGNED_SM_HOLESKY_ETH_ADDR=<aligned_service_manager_address>
```

### Bridge a Mina account
Expand Down Expand Up @@ -378,7 +384,7 @@ The `example/` folder contains a project that uses the Sudoku zkApp example from
For running the example you need to:
1. [Setup Aligned Devnet locally](https://github.com/yetanotherco/aligned_layer/blob/main/docs/guides/3_setup_aligned.md#booting-devnet-with-default-configs)
1. [Setup Aligned Devnet locally](https://github.com/yetanotherco/aligned_layer/blob/staging/docs/3_guides/6_setup_aligned.md#booting-devnet-with-default-configs)
1. Deploy the bridge smart contracts by executing
```sh
Expand Down Expand Up @@ -568,7 +574,7 @@ The first step of the verifier is to check that the public inputs correspond to
The second step of the verifier is to execute consensus checks, specific to the [Ouroboros Samasika consensus mechanism](https://github.com/MinaProtocol/mina/blob/develop/docs/specs/consensus/README.md) that the Mina Protocol uses. The checks are comparisons of state data between the candidate tip state and the bridge tip state.
There are two general rules that implement a set of checks each: a rule for short-range forks, and another for long-range forks. The implementation can be found in the [aligned_layer repo: operator/mina/lib/src/consensus_state.rs](https://github.com/lambdaclass/aligned_layer/blob/consensus_state_input_checks/operator/mina/lib/src/consensus_state.rs) file. The implementation was based on the official [Mina Protocol consensus documentation](https://github.com/MinaProtocol/mina/blob/develop/docs/specs/consensus/README.md).
There are two general rules that implement a set of checks each: a rule for short-range forks, and another for long-range forks. The implementation can be found in the [aligned_layer repo: operator/mina/lib/src/consensus_state.rs](https://github.com/lambdaclass/aligned_layer/blob/mina/operator/mina/lib/src/consensus_state.rs) file. The implementation was based on the official [Mina Protocol consensus documentation](https://github.com/MinaProtocol/mina/blob/develop/docs/specs/consensus/README.md).
### Transition frontier
Expand Down Expand Up @@ -760,7 +766,9 @@ The two curves pallas and vesta (pa(llas ve)sta) created by the [Zcash team](htt
These curves are referred to as “tick” and “tock” within the Mina source code.
- Tick - Vesta (a.k.a. Step), constraint domain size 2¹⁸ [block and transaction proofs]
- Tock - Pallas (a.k.a. Wrap), constraint domain size 2¹² [signatures]
- Tock - Pallas (a.k.a. Wrap), constraint domain size 2¹⁷ [signatures]
See [the Pickles section of the Mina book](https://o1-labs.github.io/proof-systems/specs/pickles.html) for more details.
The Tock prover does less (only performs recursive verifications and
no other logic), so it requires fewer constraints and has a smaller
Expand Down
28 changes: 21 additions & 7 deletions contract/src/MinaStateSettlement.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ pragma solidity ^0.8.12;

import "aligned_layer/contracts/src/core/AlignedLayerServiceManager.sol";

error MinaProvingSystemIdIsNotValid(bytes32); // f92aa66a
error NewStateIsNotValid(); // 114602f0
error TipStateIsWrong(bytes32 pubInputTipStateHash, bytes32 tipStatehash); // bbd80128
error MinaProvingSystemIdIsNotValid(bytes32);
error MinaNetworkIsWrong();
error NewStateIsNotValid();
error TipStateIsWrong(bytes32 pubInputTipStateHash, bytes32 tipStatehash);
error AccountIsNotValid(bytes32 accountIdHash);

/// @title Mina to Ethereum Bridge's smart contract for verifying and storing a valid state chain.
Expand All @@ -24,12 +25,15 @@ contract MinaStateSettlement {
/// the bridge's transition frontier).
bytes32[BRIDGE_TRANSITION_FRONTIER_LEN] chainLedgerHashes;

bool devnetFlag;

/// @notice Reference to the AlignedLayerServiceManager contract.
AlignedLayerServiceManager aligned;

constructor(address payable _alignedServiceAddr, bytes32 _tipStateHash) {
constructor(address payable _alignedServiceAddr, bytes32 _tipStateHash, bool _devnetFlag) {
aligned = AlignedLayerServiceManager(_alignedServiceAddr);
chainStateHashes[BRIDGE_TRANSITION_FRONTIER_LEN - 1] = _tipStateHash;
devnetFlag = _devnetFlag;
}

/// @notice Returns the last verified state hash.
Expand Down Expand Up @@ -76,9 +80,18 @@ contract MinaStateSettlement {
revert MinaProvingSystemIdIsNotValid(provingSystemAuxDataCommitment);
}

bool pubInputDevnetFlag;
assembly {
pubInputDevnetFlag := mload(add(pubInput, 0x20))
}

if (pubInputDevnetFlag != devnetFlag) {
revert MinaNetworkIsWrong();
}

bytes32 pubInputBridgeTipStateHash;
assembly {
pubInputBridgeTipStateHash := mload(add(pubInput, 0x20))
pubInputBridgeTipStateHash := mload(add(pubInput, 0x21))
}

if (pubInputBridgeTipStateHash != chainStateHashes[BRIDGE_TRANSITION_FRONTIER_LEN - 1]) {
Expand All @@ -105,9 +118,10 @@ contract MinaStateSettlement {
let slot_ledgers := chainLedgerHashes.slot

// first 32 bytes is length of byte array.
// second 32 bytes is the bridge tip state hash
// the next byte is the Devnet flag
// the next 32 bytes set is the bridge tip state hash
// the next BRIDGE_TRANSITION_FRONTIER_LEN sets of 32 bytes are state hashes.
let addr_states := add(pubInput, 64)
let addr_states := add(pubInput, 65)
// the next BRIDGE_TRANSITION_FRONTIER_LEN sets of 32 bytes are ledger hashes.
let addr_ledgers := add(addr_states, mul(32, BRIDGE_TRANSITION_FRONTIER_LEN))

Expand Down
2 changes: 1 addition & 1 deletion contract_deployer/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contract_deployer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ethers = { tag = "v2.0.15-fix-reconnections", features = [
mina-curves = { git = "https://github.com/openmina/proof-systems", branch = "ledger-newtypes-rampup4-vrf" }
o1-utils = { git = "https://github.com/lambdaclass/proof-systems", branch = "add-verifier-serializations" }
kimchi = { git = "https://github.com/openmina/proof-systems", branch = "ledger-newtypes-rampup4-vrf" }
aligned-sdk = { git = "https://github.com/lambdaclass/aligned_layer.git", branch = "update_to_0_7_for_real" }
aligned-sdk = { git = "https://github.com/lambdaclass/aligned_layer.git", branch = "use_two_vks" }
serde = { version = "1.0", features = ["derive"] }
mina-p2p-messages = { git = "https://github.com/lambdaclass/openmina/", branch = "mina_bridge" }
bincode = "1.3.3"
Expand Down
25 changes: 21 additions & 4 deletions contract_deployer/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use aligned_sdk::core::types::Chain;
use log::{debug, error, info};
use mina_bridge_core::{
eth::{
Expand All @@ -6,8 +7,9 @@ use mina_bridge_core::{
},
mina::query_root,
utils::{
constants::BRIDGE_TRANSITION_FRONTIER_LEN, contract::get_aligned_sm_contract_addr,
env::EnvironmentVariables, wallet_alloy::get_wallet,
constants::{ALIGNED_SM_DEVNET_ETH_ADDR, BRIDGE_TRANSITION_FRONTIER_LEN},
env::EnvironmentVariables,
wallet_alloy::get_wallet,
},
};
use std::process;
Expand Down Expand Up @@ -43,7 +45,13 @@ async fn main() {
process::exit(1);
});

let aligned_sm_addr = get_aligned_sm_contract_addr(&chain).unwrap_or_else(|err| {
let aligned_sm_addr = match chain {
Chain::Devnet => Ok(ALIGNED_SM_DEVNET_ETH_ADDR.to_owned()),
Chain::Holesky => std::env::var("ALIGNED_SERVICE_MANAGER_ADDR")
.map_err(|err| format!("Error getting Aligned SM contract address: {err}")),
_ => Err("Unimplemented Ethereum contract on selected chain".to_owned()),
}
.unwrap_or_else(|err| {
error!("{err}");
process::exit(1);
});
Expand All @@ -67,7 +75,16 @@ async fn main() {
process::exit(1);
});

deploy_mina_bridge_contract(&eth_rpc_url, bridge_constructor_args, &wallet)
// Contract for Devnet state proofs
deploy_mina_bridge_contract(&eth_rpc_url, &bridge_constructor_args, &wallet, true)
.await
.unwrap_or_else(|err| {
error!("Failed to deploy contract: {err}");
process::exit(1);
});

// Contract for Mainnet state proofs
deploy_mina_bridge_contract(&eth_rpc_url, &bridge_constructor_args, &wallet, false)
.await
.unwrap_or_else(|err| {
error!("Failed to deploy contract: {err}");
Expand Down
Loading

0 comments on commit e5f190e

Please sign in to comment.