@@ -29,6 +29,112 @@ use ledger_block::{Execution, Input, Output, Transition};
29
29
use indexmap:: IndexMap ;
30
30
31
31
#[ derive( Clone , PartialEq , Eq ) ]
32
+ /// A registry of program execution restrictions for the Aleo network.
33
+ ///
34
+ /// The `Restrictions` struct maintains lists of programs, functions, and arguments that are
35
+ /// restricted from execution on the network, either permanently or within specific block height ranges.
36
+ ///
37
+ /// # Structure
38
+ /// - **Programs**: Entire programs can be restricted by their program ID.
39
+ /// - **Functions**: Specific functions within programs can be restricted by their locator (program ID + function name).
40
+ /// - **Arguments**: Specific argument values to functions can be restricted based on input/output values.
41
+ ///
42
+ /// # Block Ranges
43
+ /// All restrictions are associated with block ranges that define when the restriction is active:
44
+ /// - `..` - All blocks (permanent restriction).
45
+ /// - `10..` - From block 10 onwards.
46
+ /// - `..10` - Up to block 10.
47
+ /// - `10..20` - From block 10 to block 20.
48
+ ///
49
+ /// # How to update the restrictions list and snarkVM
50
+ /// 1. Identify your favorite ${NETWORK}.
51
+ /// 2. Update the content of `fn test_restrictions_list_comparison` to reflect the restrictions list.
52
+ /// 3. Run `cd synthesizer/src/restrictions && cargo test test_restrictions_list_comparison`.
53
+ /// 4. Update the restrictions.json in `parameters/src/${NETWORK}/resources/restrictions.json`.
54
+ /// 5. Run `cargo test test_restrictions_list_comparison`.
55
+ /// 6. Update the restrictions id printed by the test in the test and in `parameters/src/${NETWORK}/resources/restrictions.json`.
56
+ /// 7. Run `cargo test test_restrictions_list_comparison` again to verify.
57
+ ///
58
+ /// # Example: Restricting a program
59
+ ///
60
+ /// ## In the `test_restrictions_list_comparison` function of `synthesizer/src/restrictions/mod.rs`:
61
+ /// ```rust
62
+ /// // Set the network.
63
+ /// type Network = console::network::MainnetV0;
64
+ /// // Initialize the restrictions.
65
+ /// let mut restrictions = Restrictions::<Network>::new_blank().unwrap();
66
+ /// // Add a program ID.
67
+ /// restrictions.restrictions_id =
68
+ /// Field::from_str("5990626497004338480795078796922903812962674412239021866159347614258503263942field")
69
+ /// .unwrap();
70
+ /// let program_id = ProgramID::from_str("hello.aleo").unwrap();
71
+ /// let range = BlockRange::RangeFrom(10..);
72
+ /// restrictions.programs.insert(program_id, range);
73
+ /// // Check the restrictions.
74
+ /// check_restrictions!(restrictions, Network);
75
+ /// ```
76
+ ///
77
+ /// ## In `parameters/src/mainnet/resources/restrictions.json`:
78
+ /// ```json
79
+ /// {
80
+ /// "restrictions_id": "5990626497004338480795078796922903812962674412239021866159347614258503263942field",
81
+ /// "programs": {
82
+ /// "hello.aleo": {
83
+ /// "RangeFrom": 10
84
+ /// }
85
+ /// },
86
+ /// "functions": {},
87
+ /// "arguments": {}
88
+ /// }
89
+ /// ```
90
+ ///
91
+ /// # Example: Restricting an address
92
+ ///
93
+ /// ## In the import section of the tests of `synthesizer/src/restrictions/mod.rs`:
94
+ /// Make sure to import `console::types::Address`, e.g., by replacing `use console::types::I8;` with `use console::types::{Address, I8};`.
95
+ ///
96
+ /// ## In the `test_restrictions_list_comparison function` of `synthesizer/src/restrictions/mod.rs`:
97
+ /// ```rust
98
+ /// // Set the network.
99
+ /// type Network = console::network::MainnetV0;
100
+ /// // Initialize the restrictions.
101
+ /// let mut restrictions = Restrictions::<Network>::new_blank().unwrap();
102
+ /// // Add a program ID.
103
+ /// restrictions.restrictions_id =
104
+ /// Field::from_str("565692246249929386853861250603407577977410496268514614186112026084930301564field")
105
+ /// .unwrap();
106
+ /// let program_id = ProgramID::from_str("credits.aleo").unwrap();
107
+ /// let function_id = Identifier::from_str("transfer_public").unwrap();
108
+ /// let literal = Literal::Address(
109
+ /// Address::from_str("aleo10unn23a4z4jh2ea4g2n9fa7vz5mxzd2jf5nxpmv7f2f2sh3ur5rstqnpcg").unwrap(),
110
+ /// );
111
+ /// let index = 0;
112
+ /// let range = BlockRange::RangeFrom(150..);
113
+ /// restrictions.arguments.insert(
114
+ /// Locator::new(program_id, function_id),
115
+ /// indexmap!( ArgumentLocator::new(true, index) => indexmap!( literal.clone() => range )),
116
+ /// );
117
+ /// // Check the restrictions.
118
+ /// check_restrictions!(restrictions, Network);
119
+ /// ```
120
+ ///
121
+ /// ## In `parameters/src/mainnet/resources/restrictions.json`:
122
+ /// ```json
123
+ /// {
124
+ /// "restrictions_id": "565692246249929386853861250603407577977410496268514614186112026084930301564field",
125
+ /// "programs": {},
126
+ /// "functions": {},
127
+ /// "arguments": {
128
+ /// "credits.aleo/transfer_public": {
129
+ /// "true/0": {
130
+ /// "aleo10unn23a4z4jh2ea4g2n9fa7vz5mxzd2jf5nxpmv7f2f2sh3ur5rstqnpcg": {
131
+ /// "RangeFrom": 150
132
+ /// }
133
+ /// }
134
+ /// }
135
+ /// }
136
+ /// }
137
+ /// ```
32
138
pub struct Restrictions < N : Network > {
33
139
/// The restrictions ID, for the current state of the `Restrictions` list.
34
140
restrictions_id : Field < N > ,
0 commit comments