Skip to content

Commit 1155c4d

Browse files
Merge branch 'staging' into featcontracts/make-payment-service-enumerable-acl
2 parents 37c0a65 + 3170684 commit 1155c4d

25 files changed

Lines changed: 1340 additions & 18 deletions

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,8 @@ circuit_js
4141

4242
# Reports
4343
docs/dead_links_report.txt
44+
45+
**/.terraform
46+
terraform.tfstate
47+
terraform.tfstate.backup
48+

aggregation_mode/Cargo.lock

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

aggregation_mode/cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ alloy = { workspace = true }
1313
agg_mode_sdk = { path = "../sdk"}
1414
sp1-sdk = "5.0.0"
1515
clap = { version = "4.5.4", features = ["derive"] }
16+
rpassword = "7.3.1"

aggregation_mode/cli/src/commands/deposit.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@ use alloy::{
33
network::{EthereumWallet, TransactionBuilder},
44
primitives::{Address, U256},
55
providers::{Provider, ProviderBuilder},
6-
signers::local::LocalSigner,
76
};
87
use clap::{self, Args};
9-
use std::str::FromStr;
108

11-
use crate::commands::helpers::parse_network;
9+
use crate::commands::helpers::{parse_network, PrivateKeyType};
1210

1311
const PAYMENT_AMOUNT: &str = "1"; // ether
1412

1513
/// Send 1 ether to the aggregation mode payment service to fund proof submissions
1614
#[derive(Debug, Clone, Args)]
1715
pub struct SendPaymentArgs {
18-
#[arg(long = "private-key")]
19-
private_key: String,
16+
#[command(flatten)]
17+
private_key_type: PrivateKeyType,
2018
#[arg(short = 'n', long = "network", default_value = "devnet", value_parser = parse_network)]
2119
network: Network,
2220
#[arg(long = "rpc-url")]
@@ -29,10 +27,10 @@ pub async fn run(args: SendPaymentArgs) {
2927
args.network
3028
);
3129

32-
let signer = match LocalSigner::from_str(args.private_key.trim()) {
30+
let signer = match args.private_key_type.into_signer() {
3331
Ok(s) => s,
3432
Err(e) => {
35-
tracing::error!("Failed to parse private key: {e}");
33+
tracing::error!("{e}");
3634
return;
3735
}
3836
};

aggregation_mode/cli/src/commands/helpers.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use clap::{self, ValueEnum};
1+
use alloy::signers::local::{LocalSigner, PrivateKeySigner};
2+
use clap::{self, Args, ValueEnum};
3+
use std::path::PathBuf;
24
use std::str::FromStr;
35

46
use agg_mode_sdk::types::Network;
@@ -14,3 +16,30 @@ pub enum ProvingSystemArg {
1416
#[clap(name = "Risc0")]
1517
Risc0,
1618
}
19+
20+
#[derive(Args, Debug, Clone)]
21+
#[group(required = true, multiple = false)]
22+
pub struct PrivateKeyType {
23+
#[arg(name = "keystore_path", long = "keystore-path")]
24+
pub keystore_path: Option<PathBuf>,
25+
#[arg(name = "private_key", long = "private-key")]
26+
pub private_key: Option<String>,
27+
}
28+
29+
impl PrivateKeyType {
30+
/// Creates a LocalSigner from either a keystore file or a raw private key.
31+
/// If a keystore path is provided, prompts for the password interactively.
32+
pub fn into_signer(self) -> Result<PrivateKeySigner, String> {
33+
if let Some(keystore_path) = self.keystore_path {
34+
let password = rpassword::prompt_password("Please enter your keystore password: ")
35+
.map_err(|e| format!("Failed to read password: {e}"))?;
36+
LocalSigner::decrypt_keystore(&keystore_path, password)
37+
.map_err(|e| format!("Failed to decrypt keystore: {e}"))
38+
} else if let Some(private_key) = self.private_key {
39+
LocalSigner::from_str(private_key.trim())
40+
.map_err(|e| format!("Failed to parse private key: {e}"))
41+
} else {
42+
Err("Either --keystore-path or --private-key must be provided".to_string())
43+
}
44+
}
45+
}

aggregation_mode/cli/src/commands/submit.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use agg_mode_sdk::{gateway::provider::AggregationModeGatewayProvider, types::Network};
2-
use alloy::signers::local::LocalSigner;
32
use clap::{command, Args, Subcommand};
43
use sp1_sdk::{SP1ProofWithPublicValues, SP1VerifyingKey};
5-
use std::{path::PathBuf, str::FromStr};
4+
use std::path::PathBuf;
65

7-
use crate::commands::helpers::parse_network;
6+
use crate::commands::helpers::{parse_network, PrivateKeyType};
87

98
#[derive(Debug, Subcommand)]
109
pub enum SubmitCommand {
@@ -18,8 +17,8 @@ pub struct SubmitSP1Args {
1817
proof_path: PathBuf,
1918
#[arg(long = "vk")]
2019
verifying_key_path: PathBuf,
21-
#[arg(long = "private-key")]
22-
private_key: String,
20+
#[command(flatten)]
21+
private_key_type: PrivateKeyType,
2322
#[arg(short = 'n', long = "network", default_value = "devnet", value_parser = parse_network)]
2423
network: Network,
2524
}
@@ -30,8 +29,13 @@ pub async fn run(args: SubmitSP1Args) {
3029
let proof = load_proof(&args.proof_path).expect("Valid proof");
3130
let vk = load_vk(&args.verifying_key_path).expect("Valid vk");
3231

33-
let signer =
34-
LocalSigner::from_str(args.private_key.trim()).expect("failed to parse private key: {e}");
32+
let signer = match args.private_key_type.into_signer() {
33+
Ok(s) => s,
34+
Err(e) => {
35+
tracing::error!("{e}");
36+
return;
37+
}
38+
};
3539

3640
let provider = AggregationModeGatewayProvider::new_with_signer(args.network.clone(), signer)
3741
.expect("failed to initialize gateway client: {e:?}");

contracts/scripts/anvil/state/alignedlayer-deployed-anvil-state.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

contracts/src/core/AggregationModePaymentService.sol

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,13 @@ contract AggregationModePaymentService is Initializable, UUPSUpgradeable, Access
205205
for (uint256 i=0; i < addressesToAdd.length; ++i) {
206206
address addressToAdd = addressesToAdd[i];
207207

208+
bool isActive = subscribedAddresses[addressToAdd] > block.timestamp;
209+
208210
subscribedAddresses[addressToAdd] = expirationTimestamp;
209211

210-
++activeSubscriptionsAmount;
212+
if (!isActive && expirationTimestamp > block.timestamp) {
213+
++activeSubscriptionsAmount;
214+
}
211215

212216
emit UserPayment(addressToAdd, amountToPayInWei, block.timestamp, expirationTimestamp);
213217
}
@@ -230,6 +234,7 @@ contract AggregationModePaymentService is Initializable, UUPSUpgradeable, Access
230234
if (subscribedAddresses[msg.sender] < block.timestamp) {
231235
// Subscription is inactive/expired: start a new period from now.
232236
subscribedAddresses[msg.sender] = block.timestamp + paymentExpirationTimeSeconds;
237+
++activeSubscriptionsAmount;
233238
} else {
234239
// Subscription is still active: extend the current expiry by one period.
235240
subscribedAddresses[msg.sender] = subscribedAddresses[msg.sender] + paymentExpirationTimeSeconds;
@@ -241,7 +246,6 @@ contract AggregationModePaymentService is Initializable, UUPSUpgradeable, Access
241246
revert SubscriptionTimeExceedsLimit(newExpiration, maxSubscriptionTimeAhead);
242247
}
243248

244-
++activeSubscriptionsAmount;
245249

246250
emit UserPayment(msg.sender, amount, block.timestamp, block.timestamp + paymentExpirationTimeSeconds);
247251
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#cloud-config
2+
hostname: ${hostname}
3+
fqdn: ${hostname}
4+
manage_etc_hosts: true
5+
6+
users:
7+
- name: app
8+
shell: /bin/bash
9+
ssh_authorized_keys:
10+
- ${ssh_public_key}
11+
- name: admin
12+
shell: /bin/bash
13+
sudo: ALL=(ALL) NOPASSWD:ALL
14+
ssh_authorized_keys:
15+
- ${ssh_public_key}
16+
17+
package_update: true
18+
package_upgrade: true
19+
20+
packages:
21+
- ca-certificates
22+
- curl
23+
- wget
24+
- gnupg
25+
- vim
26+
- git
27+
- zip
28+
- unzip
29+
- openssl
30+
- libssl-dev
31+
- build-essential
32+
- rsyslog
33+
- htop
34+
- rsync
35+
- pkg-config
36+
- locales
37+
- ufw
38+
39+
write_files:
40+
- path: /etc/environment
41+
content: |
42+
LANG=en_US.UTF-8
43+
LC_ALL=C
44+
LANGUAGE=en_US.UTF-8
45+
LC_TYPE=en_US.UTF-8
46+
LC_CTYPE=en_US.UTF-8
47+
48+
runcmd:
49+
- loginctl enable-linger app
50+
# Tailscale installation https://tailscale.com/kb/1293/cloud-init
51+
- curl -fsSL https://tailscale.com/install.sh | sh
52+
- tailscale up --ssh --advertise-tags=tag:server --auth-key=${tailscale_auth_key}
53+
- tailscale set --auto-update
54+
- sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen
55+
- locale-gen
56+
- ufw enable
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#cloud-config
2+
hostname: ${hostname}
3+
fqdn: ${hostname}
4+
manage_etc_hosts: true
5+
6+
users:
7+
- name: app
8+
shell: /bin/bash
9+
ssh_authorized_keys:
10+
- ${ssh_public_key}
11+
- name: admin
12+
shell: /bin/bash
13+
sudo: ALL=(ALL) NOPASSWD:ALL
14+
ssh_authorized_keys:
15+
- ${ssh_public_key}
16+
17+
package_update: true
18+
package_upgrade: true
19+
20+
packages:
21+
- ca-certificates
22+
- curl
23+
- wget
24+
- gnupg
25+
- vim
26+
- git
27+
- zip
28+
- unzip
29+
- openssl
30+
- libssl-dev
31+
- build-essential
32+
- rsyslog
33+
- htop
34+
- rsync
35+
- pkg-config
36+
- locales
37+
38+
write_files:
39+
- path: /etc/environment
40+
content: |
41+
LANG=en_US.UTF-8
42+
LC_ALL=C
43+
LANGUAGE=en_US.UTF-8
44+
LC_TYPE=en_US.UTF-8
45+
LC_CTYPE=en_US.UTF-8
46+
47+
runcmd:
48+
- loginctl enable-linger app
49+
# Tailscale installation https://tailscale.com/kb/1293/cloud-init
50+
- curl -fsSL https://tailscale.com/install.sh | sh
51+
- tailscale up --ssh --advertise-tags=tag:server --auth-key=${tailscale_auth_key}
52+
- tailscale set --auto-update
53+
- sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen
54+
- locale-gen

0 commit comments

Comments
 (0)