check pool balances at the end

This commit is contained in:
Giacomo Pasini 2025-02-27 16:17:27 +01:00
parent ce6569b7a5
commit 44a8b6b1ff
No known key found for this signature in database
GPG Key ID: FC08489D2D895D4B
3 changed files with 17 additions and 7 deletions

View File

@ -72,6 +72,12 @@ pub enum ZoneOp {
Ledger(Tx),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PoolsUpdate {
pub tx: Tx,
pub notes: Vec<InputWitness>,
}
// Txs are of the following form:
impl ZoneData {
pub fn swap(&mut self, swap: &Swap) {
@ -180,8 +186,9 @@ impl ZoneData {
}
}
pub fn update_and_commit(self) -> ZoneData {
self
pub fn update_and_commit(mut self, updates: &PoolsUpdate) -> [u8; 32] {
self.pools_update(&updates.tx, &updates.notes);
self.commit()
}
pub fn commit(&self) -> [u8; 32] {

View File

@ -1,6 +1,4 @@
// These constants represent the RISC-V ELF and the image ID generated by risc0-build.
// The ELF is used for proving and the ID is used for verification.
use app::ZoneOp;
use app::{PoolsUpdate, ZoneOp};
use cl::mantle::{ledger::Ledger, zone::ZoneData};
use ledger_proof_statements::ledger::SyncLog;
use methods::{STF_ELF, STF_ID};
@ -12,6 +10,7 @@ pub struct StfPrivate {
pub new_ledger: Ledger,
pub sync_logs: Vec<SyncLog>,
pub ops: Vec<ZoneOp>,
pub update_tx: PoolsUpdate,
}
impl StfPrivate {
@ -22,6 +21,8 @@ impl StfPrivate {
.write(&self.new_ledger)?
.write(&self.sync_logs)?
.write(&STF_ID)?
.write(&self.ops)?
.write(&self.update_tx)?
.build()?;
let prove_info = prover.prove(env, STF_ELF)?;

View File

@ -1,4 +1,4 @@
use app::{ZoneData, ZoneOp};
use app::{PoolsUpdate, ZoneData, ZoneOp};
use cl::{
crust::Tx,
mantle::{ledger::Ledger, zone::ZoneState},
@ -16,6 +16,7 @@ fn main() {
let sync_logs: Vec<SyncLog> = env::read();
let stf: [u8; 32] = env::read();
let ops: Vec<ZoneOp> = env::read();
let update_tx: PoolsUpdate = env::read();
let zone_id = zone_data.zone_id;
@ -33,6 +34,7 @@ fn main() {
ZoneOp::RemoveLiquidity { tx, .. } => tx,
ZoneOp::Ledger(tx) => tx,
})
.chain(std::iter::once(&update_tx.tx))
.collect();
let outputs = txs
@ -71,7 +73,7 @@ fn main() {
},
new: ZoneState {
ledger,
zone_data: zone_data.commit(),
zone_data: zone_data.update_and_commit(&update_tx),
stf,
},
};