Skip to main content

runmat_execution/executable/
revision.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{ContractError, Digest};
4use runmat_types::{
5    INTEROP_MANIFEST_SCHEMA_VERSION, PARALLEL_MANIFEST_SCHEMA_VERSION,
6    REGION_CONTRACT_SCHEMA_VERSION,
7};
8
9#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
10#[serde(deny_unknown_fields)]
11pub struct ExecutableComponentRevisions {
12    pub catalog_schema: u16,
13    pub catalog_fingerprint: Digest,
14    pub contract_schema: u16,
15    pub contract_fingerprint: Digest,
16    pub analysis_schema: u16,
17    pub mir_schema: u16,
18    pub bytecode_schema: u16,
19    pub vm_layout_schema: u16,
20    pub function_registry_schema: u16,
21    pub source_map_schema: u16,
22    pub region_schema: u16,
23    pub interop_schema: u16,
24    pub parallel_schema: u16,
25}
26
27impl ExecutableComponentRevisions {
28    pub(crate) fn validate(&self) -> Result<(), ContractError> {
29        for (field, version) in [
30            ("executable.revisions.catalog_schema", self.catalog_schema),
31            ("executable.revisions.contract_schema", self.contract_schema),
32            ("executable.revisions.analysis_schema", self.analysis_schema),
33            ("executable.revisions.mir_schema", self.mir_schema),
34            ("executable.revisions.bytecode_schema", self.bytecode_schema),
35            (
36                "executable.revisions.vm_layout_schema",
37                self.vm_layout_schema,
38            ),
39            (
40                "executable.revisions.function_registry_schema",
41                self.function_registry_schema,
42            ),
43            (
44                "executable.revisions.source_map_schema",
45                self.source_map_schema,
46            ),
47        ] {
48            if version == 0 {
49                return Err(ContractError::invalid(field, "version must be non-zero"));
50            }
51        }
52        for (field, actual, supported) in [
53            (
54                "executable.revisions.region_schema",
55                self.region_schema,
56                REGION_CONTRACT_SCHEMA_VERSION,
57            ),
58            (
59                "executable.revisions.interop_schema",
60                self.interop_schema,
61                INTEROP_MANIFEST_SCHEMA_VERSION,
62            ),
63            (
64                "executable.revisions.parallel_schema",
65                self.parallel_schema,
66                PARALLEL_MANIFEST_SCHEMA_VERSION,
67            ),
68        ] {
69            if actual != supported {
70                return Err(ContractError::invalid(
71                    field,
72                    format!("unsupported version {actual}; expected {supported}"),
73                ));
74            }
75        }
76        Ok(())
77    }
78}