@@ -759,6 +759,32 @@ impl<let NumBytes: u32, let NumPackedFields: u32, let MaxNumTokens: u32, let Max
759
759
let index_valid : Field = range_valid [i ] as Field ;
760
760
// 1 gate
761
761
let entry = TranscriptEntry ::to_field (TranscriptEntry { token , index , length });
762
+
763
+ if token == LITERAL_TOKEN as Field {
764
+ let index_as_u32 = index as u32 ;
765
+ index .assert_max_bit_size ::<8 >();
766
+ if length == 5 {
767
+ let is_false = (self .json [index_as_u32 ] == 102 ) // 'f'
768
+ & (self .json [index_as_u32 + 1 ] == 97 ) // 'a'
769
+ & (self .json [index_as_u32 + 2 ] == 108 ) // 'l'
770
+ & (self .json [index_as_u32 + 3 ] == 115 ) // 's'
771
+ & (self .json [index_as_u32 + 4 ] == 101 ); // 'e'
772
+ assert (is_false , "invalid literal" );
773
+ } else if length == 4 {
774
+ let is_true = (self .json [index_as_u32 ] == 116 ) // 't'
775
+ & (self .json [index_as_u32 + 1 ] == 114 ) // 'r'
776
+ & (self .json [index_as_u32 + 2 ] == 117 ) // 'u'
777
+ & (self .json [index_as_u32 + 3 ] == 101 ); // 'e'
778
+
779
+ let is_null = (self .json [index_as_u32 ] == 110 ) // 'n'
780
+ & (self .json [index_as_u32 + 1 ] == 117 ) // 'u'
781
+ & (self .json [index_as_u32 + 2 ] == 108 ) // 'l'
782
+ & (self .json [index_as_u32 + 3 ] == 108 ); // 'l'
783
+ assert (is_null | is_true , "invalid literal" );
784
+ } else {
785
+ assert (false , "invalid literal" );
786
+ }
787
+ }
762
788
// 2 gates
763
789
let diff = updated_transcript [cast_num_to_u32 (transcript_ptr )] - entry ;
764
790
std:: as_witness (diff );
@@ -1075,13 +1101,6 @@ fn test_json_char_outside_of_string_fails() {
1075
1101
let _ : JSON <26 , 10 , 20 , 20 , 2 > = JSON ::parse_json_from_string (text );
1076
1102
}
1077
1103
1078
- #[test(should_fail_with = "ValidationFlags: grammar error")]
1079
- fn test_json_char_outside_of_string_fails_2 () {
1080
- // n could be the start of the literal "null", so this passes the ScanData check but fails ValidationFlags
1081
- let text = "{ \" hello \" , \" world\" n}" ;
1082
- let _ : JSON <26 , 10 , 20 , 20 , 2 > = JSON ::parse_json_from_string (text );
1083
- }
1084
-
1085
1104
#[test(should_fail_with = "ValidationFlags: grammar error")]
1086
1105
fn test_json_array_with_invalid_tokens_fails () {
1087
1106
// n could be the start of the literal "null", so this passes the ScanData check but fails ValidationFlags
@@ -1133,3 +1152,27 @@ fn key_is_not_a_key() {
1133
1152
let json_string = "{1\n :0}" ;
1134
1153
let _ : JSON <26 , 10 , 20 , 20 , 2 > = JSON ::parse_json_from_string (json_string );
1135
1154
}
1155
+
1156
+ #[test(should_fail_with = "invalid literal")]
1157
+ fn test_invalid_literal () {
1158
+ let text = "{ \" name\" :fal }" ;
1159
+ let _ : JSON <153 , 10 , 60 , 60 , 2 > = JSON ::parse_json_from_string (text );
1160
+ }
1161
+
1162
+ #[test(should_fail_with = "invalid literal")]
1163
+ fn test_invalid_literal_2 () {
1164
+ let text = "{ \" name\" :treu}" ;
1165
+ let _ : JSON <153 , 10 , 60 , 60 , 2 > = JSON ::parse_json_from_string (text );
1166
+ }
1167
+
1168
+ #[test(should_fail_with = "invalid literal")]
1169
+ fn test_invalid_literal_3 () {
1170
+ let text = "{ \" name\" :truea }" ;
1171
+ let _ : JSON <153 , 10 , 60 , 60 , 2 > = JSON ::parse_json_from_string (text );
1172
+ }
1173
+
1174
+ #[test(should_fail_with = "invalid literal")]
1175
+ fn test_invalid_literal_4 () {
1176
+ let text = "{ \" hello \" , \" world\" n}" ;
1177
+ let _ : JSON <26 , 10 , 20 , 20 , 2 > = JSON ::parse_json_from_string (text );
1178
+ }
0 commit comments