Skip to content

Commit 473188a

Browse files
authored
Merge branch 'staging' into staging
2 parents 2914723 + bcded2d commit 473188a

File tree

19 files changed

+319
-22
lines changed

19 files changed

+319
-22
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ We recommend installing Rust using [rustup](https://www.rustup.rs/). You can ins
4646
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
4747
```
4848

49+
For macOS users, you will need to subsequently install the following packages:
50+
```bash
51+
brew install pkgconf
52+
brew install openssl
53+
```
54+
4955
- Windows (64-bit):
5056

5157
Download the [Windows 64-bit executable](https://win.rustup.rs/x86_64) or

console/network/src/consensus_heights.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub enum ConsensusVersion {
4545
V10 = 10,
4646
/// V11: Expand array size limit to 512 and introduce ECDSA signature verification opcodes.
4747
V11 = 11,
48-
/// V12: Prevent connection to forked nodes.
48+
/// V12: Prevent connection to forked nodes, disable StringType.
4949
V12 = 12,
5050
}
5151

console/program/src/data_types/array_type/mod.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,29 @@ impl<N: Network> ArrayType<N> {
3737
matches!(self.next_element_type(), PlaintextType::Literal(LiteralType::Boolean))
3838
}
3939

40-
/// Returns `true` if the record contains an array type with a size that exceeds the given maximum.
40+
/// Returns `true` if the `ArrayType` contains a string type.
41+
pub fn contains_string_type(&self) -> bool {
42+
// Initialize depth counter and current array type.
43+
let mut array_type = self;
44+
45+
// Check nested array types up to the maximum data depth.
46+
for _ in 0..=N::MAX_DATA_DEPTH {
47+
// Check if the current element type is a string type.
48+
if array_type.next_element_type().contains_string_type() {
49+
return true;
50+
}
51+
// If the next element is an array, continue to the next depth. Otherwise, we can stop checking.
52+
if let PlaintextType::Array(next) = array_type.next_element_type() {
53+
array_type = next;
54+
} else {
55+
return false;
56+
}
57+
}
58+
// If we reach here, it means we've exceeded the maximum depth without finding a non-array type.
59+
true
60+
}
61+
62+
/// Returns `true` if the `ArrayType` contains an array type with a size that exceeds the given maximum.
4163
pub fn exceeds_max_array_size(&self, max_array_size: u32) -> bool {
4264
// Initialize depth counter and current array type.
4365
let mut array_type = self;
@@ -48,7 +70,7 @@ impl<N: Network> ArrayType<N> {
4870
if **array_type.length() > max_array_size {
4971
return true;
5072
}
51-
// If the next eleemtn is an array, continue to the next depth. Otherwise, we can stop checking.
73+
// If the next element is an array, continue to the next depth. Otherwise, we can stop checking.
5274
if let PlaintextType::Array(next) = array_type.next_element_type() {
5375
array_type = next;
5476
} else {

console/program/src/data_types/plaintext_type/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,16 @@ impl<N: Network> PlaintextType<N> {
6464
/// Prefix bits for (de)serializing the `Struct` variant.
6565
pub const STRUCT_PREFIX_BITS: [bool; 2] = [false, true];
6666

67-
/// Returns `true` if the plaintext type is an array and the size exceeds the given maximum.
67+
/// Returns `true` if the `PlaintextType` contains a string type.
68+
pub fn contains_string_type(&self) -> bool {
69+
match self {
70+
Self::Literal(LiteralType::String) => true,
71+
Self::Array(array_type) => array_type.contains_string_type(),
72+
_ => false, // Structs are checked in their definition.
73+
}
74+
}
75+
76+
/// Returns `true` if the `PlaintextType` is an array and the size exceeds the given maximum.
6877
pub fn exceeds_max_array_size(&self, max_array_size: u32) -> bool {
6978
match self {
7079
Self::Literal(_) | Self::Struct(_) => false,

console/program/src/data_types/record_type/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ impl<N: Network> RecordType<N> {
5656
&self.entries
5757
}
5858

59+
/// Returns `true` if the record contains a string type.
60+
pub fn contains_string_type(&self) -> bool {
61+
self.entries.values().any(|entry_type| entry_type.plaintext_type().contains_string_type())
62+
}
63+
5964
/// Returns `true` if the record contains an array type with a size that exceeds the given maximum.
6065
pub fn exceeds_max_array_size(&self, max_array_size: u32) -> bool {
6166
self.entries.values().any(|entry_type| entry_type.plaintext_type().exceeds_max_array_size(max_array_size))

console/program/src/data_types/register_type/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ impl<N: Network> From<FinalizeType<N>> for RegisterType<N> {
6767
}
6868

6969
impl<N: Network> RegisterType<N> {
70+
/// Returns `true` if the register type contains a string type.
71+
pub fn contains_string_type(&self) -> bool {
72+
match self {
73+
Self::Plaintext(plaintext_type) => plaintext_type.contains_string_type(),
74+
_ => false, // Record, external record, and future types are checked elsewhere.
75+
}
76+
}
77+
7078
/// Returns `true` if the register type is an array and the size exceeds the given maximum.
7179
pub fn exceeds_max_array_size(&self, max_array_size: u32) -> bool {
7280
match self {

console/program/src/data_types/struct_type/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ impl<N: Network> StructType<N> {
4343
&self.members
4444
}
4545

46+
/// Returns `true` if the struct contains a string type.
47+
pub fn contains_string_type(&self) -> bool {
48+
self.members.values().any(|plaintext_type| plaintext_type.contains_string_type())
49+
}
50+
4651
/// Returns `true` if the struct contains an array type with a size that exceeds the given maximum.
4752
pub fn exceeds_max_array_size(&self, max_array_size: u32) -> bool {
4853
self.members.values().any(|plaintext_type| plaintext_type.exceeds_max_array_size(max_array_size))

console/program/src/data_types/value_type/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ impl<N: Network> From<EntryType<N>> for ValueType<N> {
6565
}
6666

6767
impl<N: Network> ValueType<N> {
68+
/// Returns `true` if the value type contains a string type.
69+
/// Record, external record, and future types are checked elsewhere.
70+
pub fn contains_string_type(&self) -> bool {
71+
use ValueType::*;
72+
matches!(
73+
self,
74+
Constant(plaintext) | Public(plaintext) | Private(plaintext) if plaintext.contains_string_type()
75+
)
76+
}
77+
6878
/// Returns `true` if the value type is an array and the size exceeds the given maximum.
6979
pub fn exceeds_max_array_size(&self, max_array_size: u32) -> bool {
7080
use ValueType::*;

synthesizer/program/src/closure/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ impl<N: Network> ClosureCore<N> {
7070
&self.outputs
7171
}
7272

73+
/// Returns `true` if the closure instructions contain a string type.
74+
/// Note that input and output types don't have to be checked if we are sure the broader function doesn't contain a string type.
75+
pub fn contains_string_type(&self) -> bool {
76+
self.instructions.iter().any(|instruction| instruction.contains_string_type())
77+
}
78+
7379
/// Returns `true` if the closure contains an array type with a size that exceeds the given maximum.
7480
pub fn exceeds_max_array_size(&self, max_array_size: u32) -> bool {
7581
self.inputs.iter().any(|input| input.register_type().exceeds_max_array_size(max_array_size))

synthesizer/program/src/constructor/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ impl<N: Network> ConstructorCore<N> {
5151
&self.positions
5252
}
5353

54+
/// Returns `true` if the constructor commands contain a string type.
55+
pub fn contains_string_type(&self) -> bool {
56+
self.commands.iter().any(|command| command.contains_string_type())
57+
}
58+
5459
/// Returns `true` if the constructor contains an array type with a size that exceeds the given maximum.
5560
pub fn exceeds_max_array_size(&self, max_array_size: u32) -> bool {
56-
self.commands.iter().any(|command| {
57-
matches!(
58-
command,
59-
Command::Instruction(instruction) if instruction.exceeds_max_array_size(max_array_size)
60-
)
61-
})
61+
self.commands.iter().any(|command| command.exceeds_max_array_size(max_array_size))
6262
}
6363
}
6464

0 commit comments

Comments
 (0)