Merge pull request #52 from vacp2p/Pravdyvy/UTXO-encoded-with-a-tag

UTXO with tags
This commit is contained in:
tyshko-rostyslav 2025-04-03 00:22:34 -04:00 committed by GitHub
commit ea20f0be48
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 551 additions and 264 deletions

721
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@ use anyhow::Result;
use k256::AffinePoint;
use log::info;
use serde::Serialize;
use storage::{merkle_tree_public::TreeHashType, nullifier::UTXONullifier};
use storage::{merkle_tree_public::TreeHashType, nullifier::UTXONullifier, transaction::Tag};
use utxo::{
utxo_core::{UTXOPayload, UTXO},
utxo_tree::UTXOSparseMerkleTree,
@ -122,6 +122,10 @@ impl Account {
info!("Account address is {:?}", hex::encode(self.address));
info!("Account balance is {:?}", self.balance);
}
pub fn make_tag(&self) -> Tag {
self.address[0]
}
}
impl Default for Account {

View File

@ -10,7 +10,7 @@ serde_json.workspace = true
serde.workspace = true
reqwest.workspace = true
monotree.workspace = true
risc0-zkvm = { git = "https://github.com/risc0/risc0.git", branch = "release-1.2" }
risc0-zkvm = { git = "https://github.com/risc0/risc0.git", branch = "release-2.0" }
[dependencies.rpc_primitives]
path = "../rpc_primitives"

View File

@ -19,7 +19,7 @@ reqwest.workspace = true
thiserror.workspace = true
tokio.workspace = true
tempfile.workspace = true
risc0-zkvm = { git = "https://github.com/risc0/risc0.git", branch = "release-1.2" }
risc0-zkvm = { git = "https://github.com/risc0/risc0.git", branch = "release-2.0" }
hex.workspace = true
actix-rt.workspace = true

View File

@ -189,6 +189,8 @@ impl NodeCore {
&serde_json::to_vec(&utxo).unwrap(),
);
let tag = accout.make_tag();
let comm = generate_commitments(&vec![utxo]);
Ok((
@ -206,7 +208,7 @@ impl NodeCore {
receipt,
)
.unwrap(),
encoded_data: vec![(encoded_data.0, encoded_data.1.to_vec())],
encoded_data: vec![(encoded_data.0, encoded_data.1.to_vec(), tag)],
ephemeral_pub_key: eph_pub_key.to_vec(),
}
.into(),
@ -235,13 +237,16 @@ impl NodeCore {
let encoded_data = utxos
.iter()
.map(|utxo| {
Account::encrypt_data(
&ephm_key_holder,
accout.key_holder.viewing_public_key,
&serde_json::to_vec(&utxo).unwrap(),
(
Account::encrypt_data(
&ephm_key_holder,
accout.key_holder.viewing_public_key,
&serde_json::to_vec(&utxo).unwrap(),
),
accout.make_tag(),
)
})
.map(|(ciphertext, nonce)| (ciphertext, nonce.to_vec()))
.map(|((ciphertext, nonce), tag)| (ciphertext, nonce.to_vec(), tag))
.collect();
let comm = generate_commitments(&utxos);
@ -305,7 +310,7 @@ impl NodeCore {
let eph_pub_key = ephm_key_holder.generate_ephemeral_public_key().to_bytes();
let encoded_data: Vec<(Vec<u8>, Vec<u8>)> = utxos
let encoded_data: Vec<(Vec<u8>, Vec<u8>, u8)> = utxos
.iter()
.map(|utxo_enc| {
let accout_enc = acc_map_read_guard.acc_map.get(&utxo_enc.owner).unwrap();
@ -316,7 +321,9 @@ impl NodeCore {
&serde_json::to_vec(&utxo_enc).unwrap(),
);
(ciphertext, nonce.to_vec())
let tag = accout_enc.make_tag();
(ciphertext, nonce.to_vec(), tag)
})
.collect();
@ -387,7 +394,7 @@ impl NodeCore {
let eph_pub_key = ephm_key_holder.generate_ephemeral_public_key().to_bytes();
let mut encoded_data: Vec<(Vec<u8>, Vec<u8>)> = resulting_utxos_receiver
let mut encoded_data: Vec<(Vec<u8>, Vec<u8>, u8)> = resulting_utxos_receiver
.iter()
.map(|utxo_enc| {
let accout_enc = acc_map_read_guard.acc_map.get(&utxo_enc.owner).unwrap();
@ -398,11 +405,13 @@ impl NodeCore {
&serde_json::to_vec(&utxo_enc).unwrap(),
);
(ciphertext, nonce.to_vec())
let tag = accout_enc.make_tag();
(ciphertext, nonce.to_vec(), tag)
})
.collect();
let encoded_data_1: Vec<(Vec<u8>, Vec<u8>)> = resulting_utxos_not_spent
let encoded_data_1: Vec<(Vec<u8>, Vec<u8>, u8)> = resulting_utxos_not_spent
.iter()
.map(|utxo_enc| {
let accout_enc = acc_map_read_guard.acc_map.get(&utxo_enc.owner).unwrap();
@ -413,7 +422,9 @@ impl NodeCore {
&serde_json::to_vec(&utxo_enc).unwrap(),
);
(ciphertext, nonce.to_vec())
let tag = accout_enc.make_tag();
(ciphertext, nonce.to_vec(), tag)
})
.collect();
@ -489,7 +500,7 @@ impl NodeCore {
let eph_pub_key = ephm_key_holder.generate_ephemeral_public_key().to_bytes();
let encoded_data: Vec<(Vec<u8>, Vec<u8>)> = utxos
let encoded_data: Vec<(Vec<u8>, Vec<u8>, u8)> = utxos
.iter()
.map(|utxo_enc| {
let accout_enc = acc_map_read_guard.acc_map.get(&utxo_enc.owner).unwrap();
@ -500,7 +511,9 @@ impl NodeCore {
&serde_json::to_vec(&utxo_enc).unwrap(),
);
(ciphertext, nonce.to_vec())
let tag = accout_enc.make_tag();
(ciphertext, nonce.to_vec(), tag)
})
.collect();
@ -1113,7 +1126,7 @@ impl NodeCore {
let eph_pub_key = ephm_key_holder.generate_ephemeral_public_key().to_bytes();
let encoded_data: Vec<(Vec<u8>, Vec<u8>)> = utxos
let encoded_data: Vec<(Vec<u8>, Vec<u8>, u8)> = utxos
.iter()
.map(|utxo_enc| {
let accout_enc = acc_map_read_guard.acc_map.get(&utxo_enc.owner).unwrap();
@ -1124,7 +1137,9 @@ impl NodeCore {
&serde_json::to_vec(&utxo_enc).unwrap(),
);
(ciphertext, nonce.to_vec())
let tag = accout_enc.make_tag();
(ciphertext, nonce.to_vec(), tag)
})
.collect();

View File

@ -111,7 +111,7 @@ impl NodeChainStore {
if ephemeral_public_key_sender.is_some().into() {
let ephemeral_public_key_sender = ephemeral_public_key_sender.unwrap();
for (ciphertext, nonce) in tx.encoded_data.clone() {
for (ciphertext, nonce, tag) in tx.encoded_data.clone() {
let slice = nonce.as_slice();
let nonce =
accounts::key_management::constants_types::Nonce::clone_from_slice(
@ -119,19 +119,21 @@ impl NodeChainStore {
);
for (acc_id, acc) in self.acc_map.iter_mut() {
let decoded_data_curr_acc = acc.decrypt_data(
ephemeral_public_key_sender,
ciphertext.clone(),
nonce,
);
if acc_id[0] == tag {
let decoded_data_curr_acc = acc.decrypt_data(
ephemeral_public_key_sender,
ciphertext.clone(),
nonce,
);
if let Ok(decoded_data_curr_acc) = decoded_data_curr_acc {
let decoded_utxo_try =
serde_json::from_slice::<UTXO>(&decoded_data_curr_acc);
if let Ok(decoded_data_curr_acc) = decoded_data_curr_acc {
let decoded_utxo_try =
serde_json::from_slice::<UTXO>(&decoded_data_curr_acc);
if let Ok(utxo) = decoded_utxo_try {
if &utxo.owner == acc_id {
acc.utxo_tree.insert_item(utxo)?;
if let Ok(utxo) = decoded_utxo_try {
if &utxo.owner == acc_id {
acc.utxo_tree.insert_item(utxo)?;
}
}
}
}

View File

@ -20,7 +20,7 @@ light-poseidon.workspace = true
ark-bn254.workspace = true
ark-ff.workspace = true
risc0-zkvm = { git = "https://github.com/risc0/risc0.git", branch = "release-1.2" }
risc0-zkvm = { git = "https://github.com/risc0/risc0.git", branch = "release-2.0" }
[dependencies.accounts]
path = "../accounts"

View File

@ -12,6 +12,7 @@ use sha2::digest::typenum::{UInt, UTerm};
pub type CipherText = Vec<u8>;
pub type Nonce = GenericArray<u8, UInt<UInt<UInt<UInt<UTerm, B1>, B1>, B0>, B0>>;
pub type Tag = u8;
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
pub enum TxKind {
@ -39,7 +40,7 @@ pub struct Transaction {
///Execution proof (private part)
pub execution_proof_private: String,
///Encoded blobs of data
pub encoded_data: Vec<(CipherText, Vec<u8>)>,
pub encoded_data: Vec<(CipherText, Vec<u8>, Tag)>,
///Transaction senders ephemeral pub key
pub ephemeral_pub_key: Vec<u8>,
}
@ -61,7 +62,7 @@ pub struct TransactionPayload {
///Execution proof (private part)
pub execution_proof_private: String,
///Encoded blobs of data
pub encoded_data: Vec<(CipherText, Vec<u8>)>,
pub encoded_data: Vec<(CipherText, Vec<u8>, Tag)>,
///Transaction senders ephemeral pub key
pub ephemeral_pub_key: Vec<u8>,
}

View File

@ -11,7 +11,7 @@ log.workspace = true
serde.workspace = true
thiserror.workspace = true
risc0-zkvm = { git = "https://github.com/risc0/risc0.git", branch = "release-1.2" }
risc0-zkvm = { git = "https://github.com/risc0/risc0.git", branch = "release-2.0" }
test-methods = { path = "test_methods" }
[dependencies.accounts]

View File

@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"
[build-dependencies]
risc0-build = { git = "https://github.com/risc0/risc0.git", branch = "release-1.2" }
risc0-build = { git = "https://github.com/risc0/risc0.git", branch = "release-2.0" }
[package.metadata.risc0]
methods = ["guest"]