Skip to content

Commit c78db1c

Browse files
committed
Merge branch 'refs/heads/main' into 480-chore-implement-pausable-in-servicemanager
# Conflicts: # contracts/script/output/devnet/alignedlayer_deployment_output.json
2 parents 4976e0b + aef7f8a commit c78db1c

Some content is hidden

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

49 files changed

+7685
-75
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@
77
[submodule "examples/verify/lib/forge-std"]
88
path = examples/verify/lib/forge-std
99
url = https://github.com/foundry-rs/forge-std
10+
[submodule "examples/zkquiz/contracts/lib/forge-std"]
11+
path = examples/zkquiz/contracts/lib/forge-std
12+
url = https://github.com/foundry-rs/forge-std
13+
[submodule "examples/zkquiz/contracts/lib/openzeppelin-contracts"]
14+
path = examples/zkquiz/contracts/lib/openzeppelin-contracts
15+
url = https://github.com/OpenZeppelin/openzeppelin-contracts

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ batcher_fund_service_manager_balance:
183183

184184
batcher_start: ./batcher/aligned-batcher/.env batcher_fund_service_manager_balance
185185
@echo "Starting Batcher..."
186-
@cargo +nightly-2024-04-17 run --manifest-path ./batcher/aligned-batcher/Cargo.toml --release -- --config ./config-files/config.yaml --env-file ./batcher/aligned-batcher/.env
186+
@cargo +nightly-2024-04-17 run --manifest-path ./batcher/aligned-batcher/Cargo.toml --release -- --config ./config-files/config-batcher.yaml --env-file ./batcher/aligned-batcher/.env
187187

188188
install_batcher:
189189
@cargo +nightly-2024-04-17 install --path batcher/aligned-batcher
@@ -530,7 +530,15 @@ upgrade_stake_registry: ## Upgrade Stake Registry
530530
deploy_verify_batch_inclusion_caller:
531531
@echo "Deploying VerifyBatchInclusionCaller contract..."
532532
@. examples/verify/.env && . examples/verify/scripts/deploy_verify_batch_inclusion_caller.sh
533-
533+
534+
deploy_batcher_payment_service:
535+
@echo "Deploying BatcherPayments contract..."
536+
@. contracts/scripts/.env && . contracts/scripts/deploy_batcher_payment_service.sh
537+
538+
upgrade_batcher_payment_service:
539+
@echo "Upgrading BatcherPayments contract..."
540+
@. contracts/scripts/.env && . contracts/scripts/upgrade_batcher_payment_service.sh
541+
534542
build_aligned_contracts:
535543
@cd contracts/src/core && forge build
536544

README_BATCHER_PAYMENTS.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Batcher Payments
2+
3+
## Introduction
4+
5+
To be able to use the batcher, a user must fund its transactions. For this, there is a simple Batcher Payment System.
6+
7+
The Batcher has a Batcher Payments smart contract, which is in charge of recieving user's payments, and which guarantees the batcher can only spend this money to send users' proofs to Aligned.
8+
9+
Users must first deposit into this contract, via a normal transfer to its address.
10+
11+
Then, users can send proofs to the Batcher, the Batcher will preemptively check if the user has funds for this, and once accumulating the whole batch, the Batcher will call its smart contract with the data it has recieved from the users.
12+
13+
The smart contract will then discount the corresponding amount of funds from each of the senders' balances, and create a new Task in Aligned, sending also the corresponding amount of tokens for the batch verification.
14+
15+
Users are also allowed to withdraw extra funds deposited to the Batcher Payments smart contract.
16+
17+
This way, the Batcher can only use User funds to fund the verification of the User's proofs.
18+
19+
## Helpful commands
20+
21+
If you are a User, and want to fund your Batcher so that he can include your proofs in its batch, you can send funds with the following command:
22+
23+
```bash
24+
cast send <batcher_payments_smart_contract_address> --value <desired_amount_to_transfer> --rpc-url <your_rpc_url> --private-key <your_private_key>
25+
```
26+
27+
For example:
28+
```bash
29+
cast send 0x7969c5eD335650692Bc04293B07F5BF2e7A673C0 --value 1ether --rpc-url http://localhost:8545 --private-key 0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6
30+
```
31+
32+
After sending funds, you can check your current balance:
33+
```bash
34+
cast call 0x7969c5eD335650692Bc04293B07F5BF2e7A673C0 "UserBalances(address)(uint256)" 0xa0Ee7A142d267C1f36714E4a8F75612F20a79720
35+
```
36+
37+
The Batcher will then call something similar to the following command, to submit the batch to Aligned:
38+
```bash
39+
cast send 0x7969c5eD335650692Bc04293B07F5BF2e7A673C0 "createNewTask(bytes32, string, address[], uint256)" 0xc1b2a3c3aec88bb41478922438b0698add6a9a6c57170176115bda61748df59a "http://storage.alignedlayer.com/c1b2a3c3aec88bb41478922438b0698add6a9a6c57170176115bda61748df59a.json" "[0xa0Ee7A142d267C1f36714E4a8F75612F20a79720]" 1000000000000000 --private-key 0x8b3a350cf5c34c9194ca85829a2df0ec3153be0318b5e2d3348e872092edffba
40+
```
41+
42+
Finally, the User can extract excess funds from the smart contract if he desires, or he can leave them there to fund future proofs:
43+
44+
```bash
45+
cast send 0x7969c5eD335650692Bc04293B07F5BF2e7A673C0 "withdraw(uint256)" 1000 --private-key 0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6
46+
```

README_SEND_PROOFS.md

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,37 @@ Make sure you have Aligned installed as specified [here](./README.md#how-to-use-
44

55
If you run the examples below, make sure you are in Aligned's repository root.
66

7+
## 1. Import/Create Keystore file
8+
9+
If you already have a keystore file, you can ignore this section and start sending proofs. We give two examples of how to generate one. The first one using Foundry, and the second one using EigenLayerCLI
10+
11+
### Alternative 1: With foundry
12+
13+
Install foundry following this guide:
14+
15+
Install [Foundry](https://book.getfoundry.sh/getting-started/installation):
16+
17+
- If you are creating a new account. Create a private key with:
18+
19+
```bash
20+
cast wallet new-mnemonic --words 12
21+
```
22+
23+
If you are using this wallet outside testnet, write down the mnemonic phrase given by anvil
24+
25+
- Import the wallet using the private key previously generated, or whichever you want to use, and write a password to use it.
26+
27+
```bash
28+
mkdir -p ~/.aligned_keystore/
29+
cast wallet import --private-key <YOUR_ECDSA_PRIVATE_KEY> ~/.aligned_keystore/keystore0
30+
```
31+
32+
This will create the ECDSA keystore file in `~/.aligned_keystore/keystore0`
33+
34+
### Alternative 2: With EigenlayerCLI
35+
36+
- If you have the EigenLayer CLI installed, the keystore can be generated following [this](https://docs.eigenlayer.xyz/eigenlayer/operator-guides/operator-installation#import-keys) instructions. The key will be stored into `~/.eigenlayer/operator_keys`.
37+
738
## SP1 proof
839

940
The SP1 proof needs the proof file and the vm program file.
@@ -16,7 +47,8 @@ aligned submit \
1647
--vm_program <vm_program_file> \
1748
--conn wss://batcher.alignedlayer.com \
1849
--proof_generator_addr [proof_generator_addr] \
19-
--batch_inclusion_data_directory_path [batch_inclusion_data_directory_path]
50+
--batch_inclusion_data_directory_path [batch_inclusion_data_directory_path] \
51+
--keystore_path <path_yo_ecdsa_keystore>
2052
```
2153

2254
**Example**
@@ -27,7 +59,8 @@ aligned submit \
2759
--proving_system SP1 \
2860
--proof ./batcher/aligned/test_files/sp1/sp1_fibonacci.proof \
2961
--vm_program ./batcher/aligned/test_files/sp1/sp1_fibonacci-elf \
30-
--conn wss://batcher.alignedlayer.com
62+
--conn wss://batcher.alignedlayer.com \
63+
--keystore_path ~/.aligned_keystore/keystore0
3164
```
3265

3366
## Risc0 proof
@@ -42,7 +75,8 @@ aligned submit \
4275
--vm_program <vm_program_file> \
4376
--conn wss://batcher.alignedlayer.com \
4477
--proof_generator_addr [proof_generator_addr] \
45-
--batch_inclusion_data_directory_path [batch_inclusion_data_directory_path]
78+
--batch_inclusion_data_directory_path [batch_inclusion_data_directory_path] \
79+
--keystore_path <path_yo_ecdsa_keystore>
4680
```
4781

4882
**Example**
@@ -53,7 +87,8 @@ aligned submit \
5387
--proving_system Risc0 \
5488
--proof ./batcher/aligned/test_files/risc_zero/risc_zero_fibonacci.proof \
5589
--vm_program ./batcher/aligned/test_files/risc_zero/fibonacci_id.bin \
56-
--aligned_verification_data_path ~/.aligned/aligned_verification_data
90+
--aligned_verification_data_path ~/.aligned/aligned_verification_data \
91+
--keystore_path ~/.aligned_keystore/keystore0
5792
```
5893

5994
## GnarkPlonkBn254, GnarkPlonkBls12_381 and Groth16Bn254
@@ -69,7 +104,8 @@ aligned submit \
69104
--vk <verification_key_file> \
70105
--conn wss://batcher.alignedlayer.com \
71106
--proof_generator_addr [proof_generator_addr] \
72-
--batch_inclusion_data_directory_path [batch_inclusion_data_directory_path]
107+
--batch_inclusion_data_directory_path [batch_inclusion_data_directory_path] \
108+
--keystore_path <path_yo_ecdsa_keystore>
73109
```
74110

75111
**Examples**:
@@ -81,7 +117,8 @@ aligned submit \
81117
--proof ./batcher/aligned/test_files/plonk_bn254/plonk.proof \
82118
--public_input ./batcher/aligned/test_files/plonk_bn254/plonk_pub_input.pub \
83119
--vk ./batcher/aligned/test_files/plonk_bn254/plonk.vk \
84-
--conn wss://batcher.alignedlayer.com
120+
--conn wss://batcher.alignedlayer.com \
121+
--keystore_path ~/.aligned_keystore/keystore0
85122
```
86123

87124
```bash
@@ -91,7 +128,8 @@ aligned submit \
91128
--proof ./batcher/aligned/test_files/plonk_bls12_381/plonk.proof \
92129
--public_input ./batcher/aligned/test_files/plonk_bls12_381/plonk_pub_input.pub \
93130
--vk ./batcher/aligned/test_files/plonk_bls12_381/plonk.vk \
94-
--conn wss://batcher.alignedlayer.com
131+
--conn wss://batcher.alignedlayer.com \
132+
--keystore_path ~/.aligned_keystore/keystore0
95133
```
96134

97135
```bash
@@ -101,5 +139,6 @@ aligned submit \
101139
--proof ./batcher/aligned/test_files/groth16/ineq_1_groth16.proof \
102140
--public_input ./batcher/aligned/test_files/groth16/ineq_1_groth16.pub \
103141
--vk ./batcher/aligned/test_files/groth16/ineq_1_groth16.vk \
104-
--conn wss://batcher.alignedlayer.com
142+
--conn wss://batcher.alignedlayer.com \
143+
--keystore_path ~/.aligned_keystore/keystore0
105144
```

batcher/Cargo.lock

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

batcher/aligned-batcher-lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ serde = { version = "1.0.201", features = ["derive"] }
1111
sha3 = { version = "0.10.8"}
1212
lambdaworks-crypto = { version = "0.7.0", features = ["serde"] }
1313
hex = "0.4.3"
14+
serde_json = "1.0.117"

batcher/aligned-batcher-lib/src/types/mod.rs

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
use ethers::core::k256::ecdsa::SigningKey;
2+
use ethers::signers::Signer;
3+
use ethers::signers::Wallet;
14
use ethers::types::Address;
5+
use ethers::types::Signature;
6+
use ethers::types::SignatureError;
27
use lambdaworks_crypto::merkle_tree::{
38
merkle::MerkleTree, proof::Proof, traits::IsMerkleTreeBackend,
49
};
@@ -17,7 +22,7 @@ pub enum ProvingSystemId {
1722
Risc0,
1823
}
1924

20-
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
25+
#[derive(Debug, Serialize, Deserialize, Clone)]
2126
pub struct VerificationData {
2227
pub proving_system: ProvingSystemId,
2328
pub proof: Vec<u8>,
@@ -122,31 +127,39 @@ impl BatchInclusionData {
122127
.unwrap();
123128

124129
BatchInclusionData {
125-
batch_merkle_root: batch_merkle_tree.root.clone(),
130+
batch_merkle_root: batch_merkle_tree.root,
126131
batch_inclusion_proof,
127132
index_in_batch: verification_data_batch_index,
128133
}
129134
}
130135
}
131136

132-
#[cfg(test)]
133-
mod test {
134-
use super::*;
135-
136-
#[test]
137-
fn hash_new_parent_is_correct() {
138-
let mut hasher = Keccak256::new();
139-
hasher.update(vec![1u8]);
140-
let child_1 = hasher.finalize_reset().into();
141-
hasher.update(vec![2u8]);
142-
let child_2 = hasher.finalize().into();
137+
#[derive(Debug, Clone, Serialize, Deserialize)]
138+
pub struct ClientMessage {
139+
pub verification_data: VerificationData,
140+
pub signature: Signature,
141+
}
143142

144-
let parent = VerificationCommitmentBatch::hash_new_parent(&child_1, &child_2);
143+
impl ClientMessage {
144+
/// Client message is a wrap around verification data and its signature.
145+
/// The signature is obtained by calculating the commitments and then hashing them.
146+
pub async fn new(verification_data: VerificationData, wallet: Wallet<SigningKey>) -> Self {
147+
let hashed_leaf = VerificationCommitmentBatch::hash_data(&verification_data.clone().into());
148+
let signature = wallet.sign_message(hashed_leaf).await.unwrap();
145149

146-
// This value is built using Openzeppelin's module for Merkle Trees, in particular using
147-
// the SimpleMerkleTree. For more details see the openzeppelin_merkle_tree/merkle_tree.js script.
148-
let expected_parent = "71d8979cbfae9b197a4fbcc7d387b1fae9560e2f284d30b4e90c80f6bc074f57";
150+
ClientMessage {
151+
verification_data,
152+
signature,
153+
}
154+
}
149155

150-
assert_eq!(hex::encode(parent), expected_parent)
156+
/// The signature of the message is verified, and when it correct, the
157+
/// recovered address from the signature is returned.
158+
pub fn verify_signature(&self) -> Result<Address, SignatureError> {
159+
let hashed_leaf =
160+
VerificationCommitmentBatch::hash_data(&self.verification_data.clone().into());
161+
let recovered = self.signature.recover(hashed_leaf)?;
162+
self.signature.verify(hashed_leaf, recovered)?;
163+
Ok(recovered)
151164
}
152165
}

0 commit comments

Comments
 (0)