Skip to content

Commit dd52e7c

Browse files
fix: public inputs sdk integration (#945)
1 parent 6908110 commit dd52e7c

File tree

9 files changed

+104
-27
lines changed

9 files changed

+104
-27
lines changed

docs/guides/3_validating_public_input.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ This guide assumes you are in the `examples/validating-public-input` directory.
1010

1111
## Generate your ZK Proof
1212

13-
> [!IMPORTANT]
13+
> [!IMPORTANT]
1414
> To generate the proof ensure you have [docker](https://www.docker.com/get-started/) installed and the docker daemon running.
1515
> This is necessary to ensure deterministic builds of the binary we want to generate a proof of. If not used, builds may differ depending on the system you are running on. To know more about this, check [this link](https://dev.risczero.com/terminology#deterministic-builds) from RiscZero docs.
1616
@@ -42,15 +42,17 @@ pragma solidity ^0.8.12;
4242
4343
contract FibonacciValidator {
4444
address public alignedServiceManager;
45+
address public paymentServiceAddr;
4546
bytes32 public fibonacciProgramId;
4647
4748
bytes32 public fibonacciProgramIdCommitment =
4849
0x069ed9f3972550a2901523723f4beb5e240749dcafa30e1623d0778e17d69d70;
4950
5051
event FibonacciNumbers(uint32 fibN, uint32 fibNPlusOne);
5152
52-
constructor(address _alignedServiceManager) {
53+
constructor(address _alignedServiceManager, address _paymentServiceAddr) {
5354
alignedServiceManager = _alignedServiceManager;
55+
paymentServiceAddr = _paymentServiceAddr;
5456
}
5557
5658
function verifyBatchInclusion(
@@ -78,14 +80,15 @@ contract FibonacciValidator {
7880
bytes memory proofIsIncluded
7981
) = alignedServiceManager.staticcall(
8082
abi.encodeWithSignature(
81-
"verifyBatchInclusion(bytes32,bytes32,bytes32,bytes20,bytes32,bytes,uint256)",
83+
"verifyBatchInclusion(bytes32,bytes32,bytes32,bytes20,bytes32,bytes,uint256,address)",
8284
proofCommitment,
8385
pubInputCommitment,
8486
programIdCommitment,
8587
proofGeneratorAddr,
8688
batchMerkleRoot,
8789
merkleProof,
88-
verificationDataBatchIndex
90+
verificationDataBatchIndex,
91+
paymentServiceAddr
8992
)
9093
);
9194
@@ -116,6 +119,7 @@ contract FibonacciValidator {
116119
return (first, second);
117120
}
118121
}
122+
119123
```
120124

121125
### Explanation
@@ -146,14 +150,15 @@ require(
146150
bytes memory proofIsIncluded
147151
) = alignedServiceManager.staticcall(
148152
abi.encodeWithSignature(
149-
"verifyBatchInclusion(bytes32,bytes32,bytes32,bytes20,bytes32,bytes,uint256)",
153+
"verifyBatchInclusion(bytes32,bytes32,bytes32,bytes20,bytes32,bytes,uint256,address)",
150154
proofCommitment,
151155
pubInputCommitment,
152156
programIdCommitment,
153157
proofGeneratorAddr,
154158
batchMerkleRoot,
155159
merkleProof,
156-
verificationDataBatchIndex
160+
verificationDataBatchIndex,
161+
paymentServiceAddr
157162
)
158163
);
159164
@@ -192,6 +197,7 @@ To deploy the contract, first you will need to set up the `.env` file in the con
192197
RPC_URL=<rpc_url> #You can use publicnode RPC: https://ethereum-holesky-rpc.publicnode.com
193198
PRIVATE_KEY=<private_key>
194199
ALIGNED_SERVICE_MANAGER_ADDRESS=<service_manager_address> #0x58F280BeBE9B34c9939C3C39e0890C81f163B623 for Holesky
200+
PAYMENT_SERVICE_ADDRESS=<payment_service_address> #0x815aeCA64a974297942D2Bbf034ABEe22a38A003 for Holesky
195201
```
196202

197203
Then, run `make deploy_fibonacci_validator`.

examples/validating-public-input/aligned-integration/Cargo.lock

Lines changed: 51 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/validating-public-input/aligned-integration/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
aligned-sdk = { git = "https://github.com/yetanotherco/aligned_layer", tag="v0.4.0" }
7+
aligned-sdk = { git = "https://github.com/yetanotherco/aligned_layer", rev="6908110aaa04ec3107f15ab8a8bb2603e7bbead9" }
88
tokio = { version = "1.37.0", features = ["io-std", "time", "macros", "rt", "rt-multi-thread", "sync"] }
99
ethers = { tag = "v2.0.15-fix-reconnections", features = ["ws", "rustls"], git = "https://github.com/yetanotherco/ethers-rs.git" }
1010
serde = { version = "1.0.201", features = ["derive"] }

examples/validating-public-input/aligned-integration/src/main.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::env;
12
use std::fs::File;
23
use std::io::Write;
34
use std::path::PathBuf;
@@ -6,7 +7,7 @@ use std::str::FromStr;
67
use aligned_sdk::core::errors::SubmitError;
78
use aligned_sdk::core::types::Chain::Holesky;
89
use aligned_sdk::core::types::{AlignedVerificationData, ProvingSystemId, VerificationData};
9-
use aligned_sdk::sdk::{get_next_nonce, submit_and_wait};
10+
use aligned_sdk::sdk::{get_next_nonce, submit_and_wait_verification};
1011
use env_logger::Env;
1112
use ethers::signers::{LocalWallet, Signer};
1213
use ethers::types::Address;
@@ -49,20 +50,23 @@ async fn main() -> Result<(), SubmitError> {
4950
proof_generator_addr,
5051
};
5152

52-
let wallet = LocalWallet::from_str(WALLET_PRIVATE_KEY).expect("Failed to create wallet");
53+
let wallet = LocalWallet::from_str(WALLET_PRIVATE_KEY)
54+
.expect("Failed to create wallet")
55+
.with_chain_id(17000u64);
5356

5457
let nonce = get_next_nonce(RPC_URL, wallet.address(), BATCHER_PAYMENTS_ADDRESS)
5558
.await
5659
.expect("Failed to get next nonce");
5760

5861
info!("Submitting Fibonacci proof to Aligned and waiting for verification...");
59-
let aligned_verification_data = submit_and_wait(
62+
let aligned_verification_data = submit_and_wait_verification(
6063
BATCHER_URL,
6164
RPC_URL,
6265
Holesky,
6366
&verification_data,
6467
wallet,
6568
nonce,
69+
BATCHER_PAYMENTS_ADDRESS,
6670
)
6771
.await?;
6872

@@ -72,14 +76,11 @@ async fn main() -> Result<(), SubmitError> {
7276
"Saving verification data to {:?}",
7377
batch_inclusion_data_directory_path
7478
);
75-
if let Some(aligned_verification_data) = aligned_verification_data {
76-
save_response(
77-
batch_inclusion_data_directory_path,
78-
&aligned_verification_data,
79-
)?;
80-
} else {
81-
return Err(SubmitError::EmptyVerificationDataList);
82-
}
79+
80+
save_response(
81+
batch_inclusion_data_directory_path,
82+
&aligned_verification_data,
83+
)?;
8384

8485
Ok(())
8586
}
@@ -104,13 +105,19 @@ fn save_response(
104105
let batch_inclusion_data_path =
105106
batch_inclusion_data_directory_path.join(batch_inclusion_data_file_name);
106107

107-
let data = serde_json::to_vec(&aligned_verification_data)?;
108+
let data = serde_json::to_vec(&aligned_verification_data).unwrap();
108109

109110
let mut file = File::create(&batch_inclusion_data_path)
110111
.map_err(|e| SubmitError::IoError(batch_inclusion_data_path.clone(), e))?;
111-
112112
file.write_all(data.as_slice())
113113
.map_err(|e| SubmitError::IoError(batch_inclusion_data_path.clone(), e))?;
114114

115+
let current_dir = env::current_dir().expect("Failed to get current directory");
116+
117+
info!(
118+
"Saved batch inclusion data to {:?}",
119+
current_dir.join(batch_inclusion_data_path)
120+
);
121+
115122
Ok(())
116123
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
RPC_URL=<rpc_url> #You can use publicnode RPC: https://ethereum-holesky-rpc.publicnode.com
22
PRIVATE_KEY=<private_key>
33
ALIGNED_SERVICE_MANAGER_ADDRESS=<service_manager_address> #0x58F280BeBE9B34c9939C3C39e0890C81f163B623 for Holesky
4+
PAYMENT_SERVICE_ADDRESS=<payment_service_address> #0x815aeCA64a974297942D2Bbf034ABEe22a38A003 for Holesky

examples/validating-public-input/contracts/deploy.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ if [ -z "$ALIGNED_SERVICE_MANAGER_ADDRESS" ]; then
1111
exit 1
1212
fi
1313

14+
if [ -z "$PAYMENT_SERVICE_ADDRESS" ]; then
15+
echo "PAYMENT_SERVICE_ADDRESS is not set. Please set it in .env"
16+
exit 1
17+
fi
18+
1419
if [ -z "$RPC_URL" ]; then
1520
echo "RPC_URL is not set. Please set it in .env"
1621
exit 1
@@ -25,7 +30,8 @@ forge install
2530

2631
forge script script/Deployer.s.sol \
2732
"$ALIGNED_SERVICE_MANAGER_ADDRESS" \
33+
"$PAYMENT_SERVICE_ADDRESS" \
2834
--rpc-url "$RPC_URL" \
2935
--private-key "$PRIVATE_KEY" \
3036
--broadcast \
31-
--sig "run(address _alignedServiceManager)"
37+
--sig "run(address _alignedServiceManager,address _paymentServiceAddr)"

examples/validating-public-input/contracts/script/Deployer.s.sol

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@ import {FibonacciValidator} from "../src/FibonacciValidator.sol";
77
contract FibonacciDeployer is Script {
88
function setUp() public {}
99

10-
function run(address _targetContract) external returns (address) {
10+
function run(
11+
address _alignedServiceManager,
12+
address _paymentServiceAddr
13+
) external returns (address) {
1114
vm.startBroadcast();
1215

1316
FibonacciValidator fibonacciContract = new FibonacciValidator(
14-
_targetContract
17+
_alignedServiceManager,
18+
_paymentServiceAddr
1519
);
1620

1721
vm.stopBroadcast();

examples/validating-public-input/contracts/src/FibonacciValidator.sol

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ pragma solidity ^0.8.12;
33

44
contract FibonacciValidator {
55
address public alignedServiceManager;
6+
address public paymentServiceAddr;
67
bytes32 public fibonacciProgramId;
78

89
bytes32 public fibonacciProgramIdCommitment =
910
0x069ed9f3972550a2901523723f4beb5e240749dcafa30e1623d0778e17d69d70;
1011

1112
event FibonacciNumbers(uint32 fibN, uint32 fibNPlusOne);
1213

13-
constructor(address _alignedServiceManager) {
14+
constructor(address _alignedServiceManager, address _paymentServiceAddr) {
1415
alignedServiceManager = _alignedServiceManager;
16+
paymentServiceAddr = _paymentServiceAddr;
1517
}
1618

1719
function verifyBatchInclusion(
@@ -39,14 +41,15 @@ contract FibonacciValidator {
3941
bytes memory proofIsIncluded
4042
) = alignedServiceManager.staticcall(
4143
abi.encodeWithSignature(
42-
"verifyBatchInclusion(bytes32,bytes32,bytes32,bytes20,bytes32,bytes,uint256)",
44+
"verifyBatchInclusion(bytes32,bytes32,bytes32,bytes20,bytes32,bytes,uint256,address)",
4345
proofCommitment,
4446
pubInputCommitment,
4547
programIdCommitment,
4648
proofGeneratorAddr,
4749
batchMerkleRoot,
4850
merkleProof,
49-
verificationDataBatchIndex
51+
verificationDataBatchIndex,
52+
paymentServiceAddr
5053
)
5154
);
5255

Binary file not shown.

0 commit comments

Comments
 (0)