diff --git a/emmarin/apps/swapvm/app/src/lib.rs b/emmarin/apps/swapvm/app/src/lib.rs index be0c929..7a2b2f2 100644 --- a/emmarin/apps/swapvm/app/src/lib.rs +++ b/emmarin/apps/swapvm/app/src/lib.rs @@ -72,6 +72,12 @@ pub enum ZoneOp { Ledger(Tx), } +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PoolsUpdate { + pub tx: Tx, + pub notes: Vec, +} + // 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] { diff --git a/emmarin/apps/swapvm/stf/host/src/lib.rs b/emmarin/apps/swapvm/stf/host/src/lib.rs index 47bc4e8..568b2c7 100644 --- a/emmarin/apps/swapvm/stf/host/src/lib.rs +++ b/emmarin/apps/swapvm/stf/host/src/lib.rs @@ -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, pub ops: Vec, + 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)?; diff --git a/emmarin/apps/swapvm/stf/methods/guest/src/main.rs b/emmarin/apps/swapvm/stf/methods/guest/src/main.rs index e665588..52fe255 100644 --- a/emmarin/apps/swapvm/stf/methods/guest/src/main.rs +++ b/emmarin/apps/swapvm/stf/methods/guest/src/main.rs @@ -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 = env::read(); let stf: [u8; 32] = env::read(); let ops: Vec = 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, }, };