Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 3 additions & 10 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
## RPC_URL for connecting to an Ethereum node.
RPC_URL=

## SP1 prover network rpc URL
NETWORK_RPC_URL=
## Proof requester
NETWORK_RPC_URL=https://rpc.mainnet.succinct.xyz
RPC_URL=https://eth-sepolia.g.alchemy.com/v2/URjQnzNCUHumxPFL8VDoFBmpX4uqL6X8
PRIVATE_KEY=
## Interval (in seconds) at which to check for new transactions and create new rollup proofs.
BLOCK_INTERVAL=

DATABASE_URL=

DATA_STRATEGY=persist

DATA_STRATEGY=delete
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
"[rust]": {
"editor.defaultFormatter": "rust-lang.rust-analyzer",
"editor.formatOnSave": true,
"editor.hover.enabled": true
"editor.hover.enabled": "on"
},
}
8 changes: 7 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ members = ["lib", "program", "contracts", "node"]
default-members = ["node"]
resolver = "2"

[profile.release]
lto = "thin"
codegen-units = 1
panic = "abort"
strip = true

[workspace.dependencies]
tokio = { version = "1", features = ["full"] }
alloy-sol-types = "1.0.0"
Expand All @@ -21,4 +27,4 @@ tiny-keccak = { git = "https://github.com/sp1-patches/tiny-keccak", tag = "patch
curve25519-dalek = { git = "https://github.com/sp1-patches/curve25519-dalek", tag = "patch-4.1.3-sp1-5.0.0" }
k256 = { git = "https://github.com/sp1-patches/elliptic-curves", tag = "patch-k256-13.4-sp1-5.0.0" }
p256 = { git = "https://github.com/sp1-patches/elliptic-curves", tag = "patch-p256-13.2-sp1-5.0.0" }
ecdsa = { git = "https://github.com/sp1-patches/signatures", tag = "patch-16.9-sp1-4.1.0" }
ecdsa = { git = "https://github.com/sp1-patches/signatures", tag = "patch-16.9-sp1-4.1.0" }
21 changes: 14 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
FROM rust:1.86
WORKDIR /app
FROM rust:1.86 AS builder

RUN apt-get update && apt-get install -y \
clang mold \
libpq-dev libssl-dev pkg-config libssl3 libpq5 \
&& rm -rf /var/lib/apt/lists/

RUN apt-get update && apt-get install -y libpq-dev libssl-dev pkg-config curl libssl3 libpq5 ca-certificates && rm -rf /var/lib/apt/lists/
WORKDIR /app

COPY . .

RUN curl -L https://sp1up.succinct.xyz | bash && \
export PATH="$HOME/.sp1/bin:$PATH" && \
sp1up

RUN cargo clean && \
cargo build --release
RUN cargo clean && cargo build --release

FROM debian:bookworm-slim

RUN apt-get update && apt-get install -y libpq-dev libpq5 ca-certificates && rm -rf /var/lib/apt/lists/*

RUN cargo install diesel_cli --no-default-features --features postgres
COPY --from=builder /app/target/release/node /usr/local/bin/prover-node

CMD ["sh", "-c", "diesel migration run --database-url $DATABASE_URL && /app/target/release/node"]
CMD ["prover-node"]
6 changes: 0 additions & 6 deletions contracts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ name = "energy-tracker-verifier"
version = "0.1.0"
edition = "2021"

default-run = "energy-tracker-verifier"

[[bin]]
name = "energy-tracker-verifier"
path = "src/bin/main.rs"

[dependencies]
alloy = { version = "1.0.13", features = ["full"] }
alloy-rlp = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ fn get_rollup_address() -> Address {
.expect("Invalid address")
}

fn get_m3ter_address() -> Address {
"0x40a36C0eF29A49D1B1c1fA45fab63762f8FC423F"
pub fn get_m3ter_address() -> Address {
"0x9C547B649475f1bE81323AefdbcF209C17961D5E"
.parse()
.expect("Invalid address")
}
Expand Down
17 changes: 13 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,25 @@ services:
ports:
- 8080:8080
environment:
# - DB_PASSWORD=$(cat /run/secrets/db-password)
- DATABASE_URL=${DATABASE_URL:-postgres://postgres:m3tering@db:5432/m3tering-db}
depends_on:
db:
condition: service_healthy
image: energy-tracker.public.dappnode.eth:0.1.0
restart: unless-stopped

streamr-client:
build:
context: ./streamr-client
ports:
- 3000:3000
environment:
- DATABASE_URL=${DATABASE_URL:-postgres://postgres:m3tering@db:5432/m3tering-db}
depends_on:
db:
condition: service_healthy
image: streamr-client.public.dappnode.eth:0.1.0
restart: unless-stopped

volumes:
db-data:
# secrets:
# db-password:
# file: db/password.txt
72 changes: 29 additions & 43 deletions lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ use alloy_primitives::{Bytes, B256, U256};
use alloy_sol_types::sol;
use alloy_trie::Nibbles;
use ed25519_dalek::VerifyingKey;
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use serde::{Deserialize, Deserializer, Serialize, Serializer};

mod util;
use util::validate_signature;

pub use util::{
calc_slot_key, decode_slice, destructure_payload, extract_nonce, get_state_root, to_b256,
to_keccak_hash, to_u256, trim_zeros, verify_account_proof
to_keccak_hash, to_u256, trim_zeros, verify_account_proof,
};

sol! {
Expand Down Expand Up @@ -197,46 +196,33 @@ pub fn track_energy(
}

let verifying_key = util::build_verifying_key(&m3ter.public_key).unwrap();
let mut nonce = start_nonce;
let mut energy_sum = 0u64;
for payload in m3ter_payloads {
println!("nonce {}, payload nonce {}", nonce, payload.nonce);
if !m3ter.validate_payload(payload, verifying_key) {
println!("Invalid payload: {:?}", payload);
break;
};
if nonce + 1 != payload.nonce {
println!(
"Invalid nonce: {} not consercutive to {} for m3ter_id {}",
&nonce, &payload.nonce, &m3ter.m3ter_id
);
nonce = if nonce < payload.nonce {
nonce
} else {
payload.nonce
};
break;
}
nonce = payload.nonce;
energy_sum += payload.energy;
println!(
"State: energy {:?}, nonce {:?}",
payload.energy, payload.nonce
);
}

// let mut energy_sum = 0;
// let mut latest_nonce = start_nonce;
m3ter_payloads
.par_iter()
.fold(
|| (0, start_nonce),
|(energy, nonce), payload| {
println!("nonce {}, payload nonce {}", nonce, payload.nonce);
if !m3ter.validate_payload(payload, verifying_key) {
println!("Invalid payload: {:?}", payload);
return (energy, nonce);
};
if nonce + 1 != payload.nonce {
println!(
"Invalid nonce: {} not consercutive to {} for m3ter_id {}",
&nonce, &payload.nonce, &m3ter.m3ter_id
);
return (
energy,
if nonce < payload.nonce {
payload.nonce
} else {
nonce
},
);
}
let energy_sum = energy + payload.energy;
println!(
"State: energy {:?}, nonce {:?}",
payload.energy, payload.nonce
);
(energy_sum, payload.nonce)
},
)
.reduce(
|| (0, 0),
|a, b| {
println!("Reducing: {:?} + {:?}", a.0, b.0);
if a.0 != 0 || b.0 != 0 { (a.0 + b.0, a.1.max(b.1)) } else { (0, start_nonce) }
},
)
(energy_sum, nonce)
}
Empty file removed migrations/.keep
Empty file.
6 changes: 0 additions & 6 deletions migrations/00000000000000_diesel_initial_setup/down.sql

This file was deleted.

52 changes: 0 additions & 52 deletions migrations/00000000000000_diesel_initial_setup/up.sql

This file was deleted.

Loading
Loading