mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-05-17 05:29:32 +00:00
Merge pull request #52 from vacp2p/Pravdyvy/UTXO-encoded-with-a-tag
UTXO with tags
This commit is contained in:
commit
ea20f0be48
721
Cargo.lock
generated
721
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -4,7 +4,7 @@ use anyhow::Result;
|
|||||||
use k256::AffinePoint;
|
use k256::AffinePoint;
|
||||||
use log::info;
|
use log::info;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use storage::{merkle_tree_public::TreeHashType, nullifier::UTXONullifier};
|
use storage::{merkle_tree_public::TreeHashType, nullifier::UTXONullifier, transaction::Tag};
|
||||||
use utxo::{
|
use utxo::{
|
||||||
utxo_core::{UTXOPayload, UTXO},
|
utxo_core::{UTXOPayload, UTXO},
|
||||||
utxo_tree::UTXOSparseMerkleTree,
|
utxo_tree::UTXOSparseMerkleTree,
|
||||||
@ -122,6 +122,10 @@ impl Account {
|
|||||||
info!("Account address is {:?}", hex::encode(self.address));
|
info!("Account address is {:?}", hex::encode(self.address));
|
||||||
info!("Account balance is {:?}", self.balance);
|
info!("Account balance is {:?}", self.balance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn make_tag(&self) -> Tag {
|
||||||
|
self.address[0]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Account {
|
impl Default for Account {
|
||||||
|
|||||||
@ -10,7 +10,7 @@ serde_json.workspace = true
|
|||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
reqwest.workspace = true
|
reqwest.workspace = true
|
||||||
monotree.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]
|
[dependencies.rpc_primitives]
|
||||||
path = "../rpc_primitives"
|
path = "../rpc_primitives"
|
||||||
|
|||||||
@ -19,7 +19,7 @@ reqwest.workspace = true
|
|||||||
thiserror.workspace = true
|
thiserror.workspace = true
|
||||||
tokio.workspace = true
|
tokio.workspace = true
|
||||||
tempfile.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
|
hex.workspace = true
|
||||||
actix-rt.workspace = true
|
actix-rt.workspace = true
|
||||||
|
|
||||||
|
|||||||
@ -189,6 +189,8 @@ impl NodeCore {
|
|||||||
&serde_json::to_vec(&utxo).unwrap(),
|
&serde_json::to_vec(&utxo).unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let tag = accout.make_tag();
|
||||||
|
|
||||||
let comm = generate_commitments(&vec![utxo]);
|
let comm = generate_commitments(&vec![utxo]);
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
@ -206,7 +208,7 @@ impl NodeCore {
|
|||||||
receipt,
|
receipt,
|
||||||
)
|
)
|
||||||
.unwrap(),
|
.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(),
|
ephemeral_pub_key: eph_pub_key.to_vec(),
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
@ -235,13 +237,16 @@ impl NodeCore {
|
|||||||
let encoded_data = utxos
|
let encoded_data = utxos
|
||||||
.iter()
|
.iter()
|
||||||
.map(|utxo| {
|
.map(|utxo| {
|
||||||
Account::encrypt_data(
|
(
|
||||||
&ephm_key_holder,
|
Account::encrypt_data(
|
||||||
accout.key_holder.viewing_public_key,
|
&ephm_key_holder,
|
||||||
&serde_json::to_vec(&utxo).unwrap(),
|
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();
|
.collect();
|
||||||
|
|
||||||
let comm = generate_commitments(&utxos);
|
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 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()
|
.iter()
|
||||||
.map(|utxo_enc| {
|
.map(|utxo_enc| {
|
||||||
let accout_enc = acc_map_read_guard.acc_map.get(&utxo_enc.owner).unwrap();
|
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(),
|
&serde_json::to_vec(&utxo_enc).unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
(ciphertext, nonce.to_vec())
|
let tag = accout_enc.make_tag();
|
||||||
|
|
||||||
|
(ciphertext, nonce.to_vec(), tag)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@ -387,7 +394,7 @@ impl NodeCore {
|
|||||||
|
|
||||||
let eph_pub_key = ephm_key_holder.generate_ephemeral_public_key().to_bytes();
|
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()
|
.iter()
|
||||||
.map(|utxo_enc| {
|
.map(|utxo_enc| {
|
||||||
let accout_enc = acc_map_read_guard.acc_map.get(&utxo_enc.owner).unwrap();
|
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(),
|
&serde_json::to_vec(&utxo_enc).unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
(ciphertext, nonce.to_vec())
|
let tag = accout_enc.make_tag();
|
||||||
|
|
||||||
|
(ciphertext, nonce.to_vec(), tag)
|
||||||
})
|
})
|
||||||
.collect();
|
.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()
|
.iter()
|
||||||
.map(|utxo_enc| {
|
.map(|utxo_enc| {
|
||||||
let accout_enc = acc_map_read_guard.acc_map.get(&utxo_enc.owner).unwrap();
|
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(),
|
&serde_json::to_vec(&utxo_enc).unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
(ciphertext, nonce.to_vec())
|
let tag = accout_enc.make_tag();
|
||||||
|
|
||||||
|
(ciphertext, nonce.to_vec(), tag)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@ -489,7 +500,7 @@ impl NodeCore {
|
|||||||
|
|
||||||
let eph_pub_key = ephm_key_holder.generate_ephemeral_public_key().to_bytes();
|
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()
|
.iter()
|
||||||
.map(|utxo_enc| {
|
.map(|utxo_enc| {
|
||||||
let accout_enc = acc_map_read_guard.acc_map.get(&utxo_enc.owner).unwrap();
|
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(),
|
&serde_json::to_vec(&utxo_enc).unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
(ciphertext, nonce.to_vec())
|
let tag = accout_enc.make_tag();
|
||||||
|
|
||||||
|
(ciphertext, nonce.to_vec(), tag)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@ -1113,7 +1126,7 @@ impl NodeCore {
|
|||||||
|
|
||||||
let eph_pub_key = ephm_key_holder.generate_ephemeral_public_key().to_bytes();
|
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()
|
.iter()
|
||||||
.map(|utxo_enc| {
|
.map(|utxo_enc| {
|
||||||
let accout_enc = acc_map_read_guard.acc_map.get(&utxo_enc.owner).unwrap();
|
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(),
|
&serde_json::to_vec(&utxo_enc).unwrap(),
|
||||||
);
|
);
|
||||||
|
|
||||||
(ciphertext, nonce.to_vec())
|
let tag = accout_enc.make_tag();
|
||||||
|
|
||||||
|
(ciphertext, nonce.to_vec(), tag)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
|||||||
@ -111,7 +111,7 @@ impl NodeChainStore {
|
|||||||
if ephemeral_public_key_sender.is_some().into() {
|
if ephemeral_public_key_sender.is_some().into() {
|
||||||
let ephemeral_public_key_sender = ephemeral_public_key_sender.unwrap();
|
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 slice = nonce.as_slice();
|
||||||
let nonce =
|
let nonce =
|
||||||
accounts::key_management::constants_types::Nonce::clone_from_slice(
|
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() {
|
for (acc_id, acc) in self.acc_map.iter_mut() {
|
||||||
let decoded_data_curr_acc = acc.decrypt_data(
|
if acc_id[0] == tag {
|
||||||
ephemeral_public_key_sender,
|
let decoded_data_curr_acc = acc.decrypt_data(
|
||||||
ciphertext.clone(),
|
ephemeral_public_key_sender,
|
||||||
nonce,
|
ciphertext.clone(),
|
||||||
);
|
nonce,
|
||||||
|
);
|
||||||
|
|
||||||
if let Ok(decoded_data_curr_acc) = decoded_data_curr_acc {
|
if let Ok(decoded_data_curr_acc) = decoded_data_curr_acc {
|
||||||
let decoded_utxo_try =
|
let decoded_utxo_try =
|
||||||
serde_json::from_slice::<UTXO>(&decoded_data_curr_acc);
|
serde_json::from_slice::<UTXO>(&decoded_data_curr_acc);
|
||||||
|
|
||||||
if let Ok(utxo) = decoded_utxo_try {
|
if let Ok(utxo) = decoded_utxo_try {
|
||||||
if &utxo.owner == acc_id {
|
if &utxo.owner == acc_id {
|
||||||
acc.utxo_tree.insert_item(utxo)?;
|
acc.utxo_tree.insert_item(utxo)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,7 +20,7 @@ light-poseidon.workspace = true
|
|||||||
ark-bn254.workspace = true
|
ark-bn254.workspace = true
|
||||||
ark-ff.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]
|
[dependencies.accounts]
|
||||||
path = "../accounts"
|
path = "../accounts"
|
||||||
|
|||||||
@ -12,6 +12,7 @@ use sha2::digest::typenum::{UInt, UTerm};
|
|||||||
|
|
||||||
pub type CipherText = Vec<u8>;
|
pub type CipherText = Vec<u8>;
|
||||||
pub type Nonce = GenericArray<u8, UInt<UInt<UInt<UInt<UTerm, B1>, B1>, B0>, B0>>;
|
pub type Nonce = GenericArray<u8, UInt<UInt<UInt<UInt<UTerm, B1>, B1>, B0>, B0>>;
|
||||||
|
pub type Tag = u8;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
|
||||||
pub enum TxKind {
|
pub enum TxKind {
|
||||||
@ -39,7 +40,7 @@ pub struct Transaction {
|
|||||||
///Execution proof (private part)
|
///Execution proof (private part)
|
||||||
pub execution_proof_private: String,
|
pub execution_proof_private: String,
|
||||||
///Encoded blobs of data
|
///Encoded blobs of data
|
||||||
pub encoded_data: Vec<(CipherText, Vec<u8>)>,
|
pub encoded_data: Vec<(CipherText, Vec<u8>, Tag)>,
|
||||||
///Transaction senders ephemeral pub key
|
///Transaction senders ephemeral pub key
|
||||||
pub ephemeral_pub_key: Vec<u8>,
|
pub ephemeral_pub_key: Vec<u8>,
|
||||||
}
|
}
|
||||||
@ -61,7 +62,7 @@ pub struct TransactionPayload {
|
|||||||
///Execution proof (private part)
|
///Execution proof (private part)
|
||||||
pub execution_proof_private: String,
|
pub execution_proof_private: String,
|
||||||
///Encoded blobs of data
|
///Encoded blobs of data
|
||||||
pub encoded_data: Vec<(CipherText, Vec<u8>)>,
|
pub encoded_data: Vec<(CipherText, Vec<u8>, Tag)>,
|
||||||
///Transaction senders ephemeral pub key
|
///Transaction senders ephemeral pub key
|
||||||
pub ephemeral_pub_key: Vec<u8>,
|
pub ephemeral_pub_key: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@ log.workspace = true
|
|||||||
serde.workspace = true
|
serde.workspace = true
|
||||||
thiserror.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" }
|
test-methods = { path = "test_methods" }
|
||||||
|
|
||||||
[dependencies.accounts]
|
[dependencies.accounts]
|
||||||
|
|||||||
@ -4,7 +4,7 @@ version = "0.1.0"
|
|||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[build-dependencies]
|
[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]
|
[package.metadata.risc0]
|
||||||
methods = ["guest"]
|
methods = ["guest"]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user