-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.rs
108 lines (99 loc) · 3.63 KB
/
types.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
use crate::hash::hash_trait::HashOutput;
use crate::patricia_merkle_tree::filled_node::{ClassHash, CompiledClassHash, Nonce};
use crate::patricia_merkle_tree::types::TreeHeight;
use crate::storage::storage_trait::{StorageKey, StorageValue};
use crate::types::Felt;
use serde::Deserialize;
use std::collections::HashMap;
type RawFelt = [u8; 32];
#[derive(Debug, PartialEq, Eq, Hash)]
// TODO(Nimrod, 1/6/2024): Swap to starknet-types-core types once implemented.
pub(crate) struct ContractAddress(pub Felt);
#[derive(Debug, PartialEq, Eq, Hash)]
// TODO(Nimrod, 1/6/2024): Swap to starknet-types-core types once implemented.
pub(crate) struct StarknetStorageKey(pub Felt);
#[allow(dead_code)]
#[derive(Debug, Eq, PartialEq)]
pub(crate) struct StarknetStorageValue(pub Felt);
#[derive(Deserialize, Debug)]
#[allow(dead_code)]
/// Input to the committer.
pub(crate) struct RawInput {
/// Storage. Will be casted to HashMap<vec<u8>, Vec<u8>> to simulate DB access.
pub storage: Vec<RawStorageEntry>,
/// All relevant information for the state diff commitment.
pub state_diff: RawStateDiff,
/// The height of the patricia tree.
// TODO(Nimrod,20/4/2024): Strong assumption - all trees have same height. How can I get
// rid of it?
pub tree_height: u8,
}
#[allow(dead_code)]
#[derive(Debug, Eq, PartialEq)]
pub(crate) struct Input {
pub storage: HashMap<StorageKey, StorageValue>,
pub state_diff: StateDiff,
pub tree_height: TreeHeight,
}
#[derive(Deserialize, Debug)]
#[allow(dead_code)]
/// Fact storage entry.
pub(crate) struct RawStorageEntry {
pub key: Vec<u8>,
pub value: Vec<u8>,
}
#[derive(Deserialize, Debug)]
#[allow(dead_code)]
pub(crate) struct RawFeltMapEntry {
pub key: RawFelt,
pub value: RawFelt,
}
#[derive(Deserialize, Debug)]
#[allow(dead_code)]
/// Represents storage updates. Later will be casted to HashMap<Felt, HashMap<Felt,Felt>> entry.
pub(crate) struct RawStorageUpdates {
pub address: RawFelt,
pub storage_updates: Vec<RawFeltMapEntry>,
}
#[derive(Deserialize, Debug)]
#[allow(dead_code)]
/// Represents current state leaf at the contract state tree. Later will be casted to
/// HashMap<Felt, (nonce, class_hash, storage_root_hash)> entry.
pub(crate) struct RawContractStateLeaf {
pub address: RawFelt,
pub nonce: RawFelt,
pub storage_root_hash: RawFelt,
pub class_hash: RawFelt,
}
#[derive(Deserialize, Debug)]
#[allow(dead_code)]
/// Represents state diff.
pub(crate) struct RawStateDiff {
/// Will be casted to HashMap<Felt, Felt>.
pub address_to_class_hash: Vec<RawFeltMapEntry>,
/// Will be casted to HashMap<Felt, Felt>.
pub address_to_nonce: Vec<RawFeltMapEntry>,
/// Will be casted to HashMap<Felt, Felt>.
pub class_hash_to_compiled_class_hash: Vec<RawFeltMapEntry>,
/// Will be casted to HashMap<Felt, HashMap<Felt, Felt>>.
pub storage_updates: Vec<RawStorageUpdates>,
/// Will be casted to HashMap<Felt, ContractState>.
pub current_contract_state_leaves: Vec<RawContractStateLeaf>,
}
#[allow(dead_code)]
#[derive(Debug, Eq, PartialEq)]
pub(crate) struct StateDiff {
pub address_to_class_hash: HashMap<ContractAddress, ClassHash>,
pub address_to_nonce: HashMap<ContractAddress, Nonce>,
pub class_hash_to_compiled_class_hash: HashMap<ClassHash, CompiledClassHash>,
pub current_contract_state_leaves: HashMap<ContractAddress, ContractState>,
pub storage_updates:
HashMap<ContractAddress, HashMap<StarknetStorageKey, StarknetStorageValue>>,
}
#[allow(dead_code)]
#[derive(Debug, Eq, PartialEq)]
pub(crate) struct ContractState {
pub nonce: Nonce,
pub storage_root_hash: HashOutput,
pub class_hash: ClassHash,
}