Complete clearing service impl

This commit is contained in:
hu55a1n1 2024-02-29 05:53:00 -08:00
parent f961c2fdbc
commit 3a713c38df
2 changed files with 24 additions and 20 deletions

18
Cargo.lock generated
View file

@ -835,7 +835,7 @@ dependencies = [
[[package]]
name = "cw-tee-mtcs"
version = "0.1.0"
source = "git+ssh://git@github.com/informalsystems/bisenzone-cw-mvp.git?branch=hu55a1n1/11-use-quartz#3382463b74411fd873a927e1d26b09c35b339753"
source = "git+ssh://git@github.com/informalsystems/bisenzone-cw-mvp.git?branch=hu55a1n1/11-use-quartz#48508d739427bd3f2a983c8e8d4c6eb2e677aff2"
dependencies = [
"cosmwasm-schema",
"cosmwasm-std",
@ -1416,7 +1416,7 @@ dependencies = [
"futures-sink",
"futures-util",
"http",
"indexmap 2.2.3",
"indexmap 2.2.4",
"slab",
"tokio",
"tokio-util",
@ -1452,9 +1452,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "hermit-abi"
version = "0.3.8"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "379dada1584ad501b383485dd706b8afb7a70fcbc7f4da7d780638a5a6124a60"
checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
[[package]]
name = "hex"
@ -1630,9 +1630,9 @@ dependencies = [
[[package]]
name = "indexmap"
version = "2.2.3"
version = "2.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "233cf39063f058ea2caae4091bf4a3ef70a653afbc026f5c4a4135d114e3c177"
checksum = "967d6dd42f16dbf0eb8040cb9e477933562684d3918f7d253f2ff9087fb3e7a3"
dependencies = [
"equivalent",
"hashbrown 0.14.3",
@ -2251,7 +2251,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9"
dependencies = [
"fixedbitset",
"indexmap 2.2.3",
"indexmap 2.2.4",
]
[[package]]
@ -2455,7 +2455,7 @@ dependencies = [
[[package]]
name = "quartz-cw"
version = "0.1.0"
source = "git+ssh://git@github.com/informalsystems/bisenzone-cw-mvp.git?branch=hu55a1n1/11-use-quartz#3382463b74411fd873a927e1d26b09c35b339753"
source = "git+ssh://git@github.com/informalsystems/bisenzone-cw-mvp.git?branch=hu55a1n1/11-use-quartz#48508d739427bd3f2a983c8e8d4c6eb2e677aff2"
dependencies = [
"cosmwasm-schema",
"cosmwasm-std",
@ -2530,7 +2530,7 @@ dependencies = [
[[package]]
name = "quartz-tee-ra"
version = "0.1.0"
source = "git+ssh://git@github.com/informalsystems/bisenzone-cw-mvp.git?branch=hu55a1n1/11-use-quartz#3382463b74411fd873a927e1d26b09c35b339753"
source = "git+ssh://git@github.com/informalsystems/bisenzone-cw-mvp.git?branch=hu55a1n1/11-use-quartz#48508d739427bd3f2a983c8e8d4c6eb2e677aff2"
dependencies = [
"cosmwasm-schema",
"cosmwasm-std",

View file

@ -50,20 +50,22 @@ where
serde_json::from_str(&message).map_err(|e| Status::invalid_argument(e.to_string()))?;
let sk = self.sk.lock().unwrap();
let obligations: Vec<_> = obligations_enc
.into_values()
.map(|ciphertext| {
let o = decrypt(&sk.as_ref().unwrap().to_bytes(), &ciphertext).unwrap();
serde_json::from_slice::<SimpleObligation<HexBinary, i64>>(&o).unwrap()
})
.collect();
let (digests, obligations): (Vec<RawHash>, Vec<SimpleObligation<HexBinary, i64>>) =
obligations_enc
.into_iter()
.map(|(digest, ciphertext)| {
let o = decrypt(&sk.as_ref().unwrap().to_bytes(), &ciphertext).unwrap();
(digest, serde_json::from_slice(&o).unwrap())
})
.unzip();
let mut mtcs = ComplexIdMtcs::wrapping(DefaultMtcs::new(PrimalDual::default()));
let setoffs: Vec<SimpleSetoff<HexBinary, i64>> = mtcs.run(obligations).unwrap();
let setoffs_enc: Vec<HexBinary> = setoffs
let setoffs_enc: BTreeMap<RawHash, RawCipherText> = setoffs
.into_iter()
.flat_map(|so| {
.zip(digests)
.flat_map(|(so, digest)| {
let debtor_pk = VerifyingKey::from_sec1_bytes(&so.debtor).unwrap();
let creditor_pk = VerifyingKey::from_sec1_bytes(&so.creditor).unwrap();
@ -71,9 +73,11 @@ where
let so_debtor = encrypt(&debtor_pk.to_sec1_bytes(), so_ser.as_bytes()).unwrap();
let so_creditor = encrypt(&creditor_pk.to_sec1_bytes(), so_ser.as_bytes()).unwrap();
[so_debtor, so_creditor]
[
(digest.clone(), so_debtor.into()),
(digest, so_creditor.into()),
]
})
.map(Into::into)
.collect();
let message = serde_json::to_string(&SubmitSetoffsMsg { setoffs_enc }).unwrap();