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
use super::{
super::{ToElements, WORD_SIZE},
ByteReader, ByteWriter, Deserializable, DeserializationError, Digest, Felt, Kernel, Program,
Serializable, Vec,
};
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct ProgramInfo {
program_hash: Digest,
kernel: Kernel,
}
impl ProgramInfo {
pub const fn new(program_hash: Digest, kernel: Kernel) -> Self {
Self {
program_hash,
kernel,
}
}
pub const fn program_hash(&self) -> &Digest {
&self.program_hash
}
pub const fn kernel(&self) -> &Kernel {
&self.kernel
}
pub fn kernel_procedures(&self) -> &[Digest] {
self.kernel.proc_hashes()
}
}
impl From<Program> for ProgramInfo {
fn from(program: Program) -> Self {
let Program { root, kernel, .. } = program;
let program_hash = root.hash();
Self {
program_hash,
kernel,
}
}
}
impl Serializable for ProgramInfo {
fn write_into<W: ByteWriter>(&self, target: &mut W) {
self.program_hash.write_into(target);
<Kernel as Serializable>::write_into(&self.kernel, target);
}
}
impl Deserializable for ProgramInfo {
fn read_from<R: ByteReader>(source: &mut R) -> Result<Self, DeserializationError> {
let program_hash = source.read()?;
let kernel = source.read()?;
Ok(Self {
program_hash,
kernel,
})
}
}
impl ToElements<Felt> for ProgramInfo {
fn to_elements(&self) -> Vec<Felt> {
let num_kernel_proc_elements = self.kernel.proc_hashes().len() * WORD_SIZE;
let mut result = Vec::with_capacity(WORD_SIZE + num_kernel_proc_elements);
result.extend_from_slice(self.program_hash.as_elements());
for proc_hash in self.kernel.proc_hashes() {
result.extend_from_slice(proc_hash.as_elements());
}
result
}
}