fix: public context structure added

This commit is contained in:
Oleksandr Pravdyvyi 2025-04-04 12:11:54 +03:00
parent d84a134904
commit 0b1df5b3d5
5 changed files with 72 additions and 2 deletions

14
Cargo.lock generated
View File

@ -1565,6 +1565,7 @@ dependencies = [
"digest 0.10.7",
"elliptic-curve",
"rfc6979",
"serdect",
"signature",
"spki",
]
@ -1608,6 +1609,7 @@ dependencies = [
"pkcs8",
"rand_core 0.6.4",
"sec1",
"serdect",
"subtle 2.6.1",
"zeroize",
]
@ -2636,6 +2638,7 @@ dependencies = [
"ecdsa",
"elliptic-curve",
"once_cell",
"serdect",
"sha2 0.10.8",
"signature",
]
@ -4590,6 +4593,7 @@ dependencies = [
"der",
"generic-array 0.14.7",
"pkcs8",
"serdect",
"subtle 2.6.1",
"zeroize",
]
@ -4784,6 +4788,16 @@ dependencies = [
"serde",
]
[[package]]
name = "serdect"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a84f14a19e9a014bb9f4512488d9829a68e04ecabffb0f9904cd1ace94598177"
dependencies = [
"base16ct",
"serde",
]
[[package]]
name = "sha1"
version = "0.10.6"

View File

@ -58,7 +58,7 @@ features = ["std", "std_rng", "getrandom"]
version = "0.8.5"
[workspace.dependencies.k256]
features = ["ecdsa-core", "arithmetic", "expose-field"]
features = ["ecdsa-core", "arithmetic", "expose-field", "serde"]
version = "0.13.4"
[workspace.dependencies.elliptic-curve]

View File

@ -26,6 +26,16 @@ pub struct Account {
pub utxo_tree: UTXOSparseMerkleTree,
}
///A strucure, which represents all the visible(public) information
///
/// known to each node about account `address`
pub struct AccountPublicMask {
pub nullifier_public_key: AffinePoint,
pub viewing_public_key: AffinePoint,
pub address: AccountAddress,
pub balance: u64,
}
impl Account {
pub fn new() -> Self {
let key_holder = AddressKeyHolder::new_os_random();
@ -126,6 +136,16 @@ impl Account {
pub fn make_tag(&self) -> Tag {
self.address[0]
}
///Produce account public mask
pub fn make_account_public_mask(&self) -> AccountPublicMask {
AccountPublicMask {
nullifier_public_key: self.key_holder.nullifer_public_key,
viewing_public_key: self.key_holder.viewing_public_key,
address: self.address,
balance: self.balance,
}
}
}
impl Default for Account {

View File

@ -1,10 +1,14 @@
use std::{collections::HashMap, path::Path};
use std::{
collections::{BTreeMap, HashMap},
path::Path,
};
use accounts::account_core::{Account, AccountAddress};
use anyhow::Result;
use block_store::NodeBlockStore;
use elliptic_curve::group::GroupEncoding;
use k256::AffinePoint;
use public_context::PublicSCContext;
use storage::{
block::Block,
merkle_tree_public::merkle_tree::{PublicTransactionMerkleTree, UTXOCommitmentsMerkleTree},
@ -18,6 +22,7 @@ use crate::ActionData;
pub mod accounts_store;
pub mod block_store;
pub mod public_context;
pub struct NodeChainStore {
pub acc_map: HashMap<AccountAddress, Account>,
@ -149,4 +154,21 @@ impl NodeChainStore {
Ok(())
}
pub fn produce_context(&self, caller: AccountAddress) -> PublicSCContext {
let mut account_masks = BTreeMap::new();
for (acc_addr, acc) in &self.acc_map {
account_masks.insert(*acc_addr, acc.make_account_public_mask());
}
PublicSCContext {
caller_address: caller,
caller_balance: self.acc_map.get(&caller).unwrap().balance,
account_masks,
nullifier_store_root: self.nullifier_store.curr_root.unwrap_or([0; 32]),
comitment_store_root: self.utxo_commitments_store.get_root().unwrap_or([0; 32]),
pub_tx_store_root: self.pub_tx_store.get_root().unwrap_or([0; 32]),
}
}
}

View File

@ -0,0 +1,14 @@
use std::collections::BTreeMap;
use accounts::account_core::{AccountAddress, AccountPublicMask};
use storage::{merkle_tree_public::TreeHashType, AccountId};
///Strucutre, representing context, given to a smart contract on a call
pub struct PublicSCContext {
pub caller_address: AccountAddress,
pub caller_balance: u64,
pub account_masks: BTreeMap<AccountAddress, AccountPublicMask>,
pub nullifier_store_root: TreeHashType,
pub comitment_store_root: TreeHashType,
pub pub_tx_store_root: TreeHashType,
}