Skip to content

Commit

Permalink
update protected zone (#6568)
Browse files Browse the repository at this point in the history
  • Loading branch information
dean-starkware authored Nov 3, 2024
1 parent 03cf46e commit 5761e45
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 26 deletions.
8 changes: 2 additions & 6 deletions corelib/src/sha256.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ extern fn sha256_state_handle_init(state: Box<[u32; 8]>) -> Sha256StateHandle no
/// returns the state of a SHA-256 hash.
extern fn sha256_state_handle_digest(state: Sha256StateHandle) -> Box<[u32; 8]> nopanic;

const SHA256_INITIAL_STATE: [
u32
; 8] = [
const SHA256_INITIAL_STATE: [u32; 8] = [
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
];

Expand All @@ -23,9 +21,7 @@ const SHA256_INITIAL_STATE: [
/// return the SHA-256 hash of the `input array` + `last_input_word` as big endian.
pub fn compute_sha256_u32_array(
mut input: Array<u32>, last_input_word: u32, last_input_num_bytes: u32
) -> [
u32
; 8] {
) -> [u32; 8] {
add_sha256_padding(ref input, last_input_word, last_input_num_bytes);

let mut input = input.span();
Expand Down
3 changes: 2 additions & 1 deletion corelib/src/test/byte_array_test.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,8 @@ fn test_serde() {
0x4c6f6e6720737472696e672c206d6f7265207468616e203331206368617261, // data
0x63746572732e, // pending_word
6 // pending_word_len
].span()
]
.span()
);
}

Expand Down
29 changes: 28 additions & 1 deletion crates/cairo-lang-formatter/src/node_properties.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,31 @@ impl SyntaxNodeFormat for SyntaxNode {
SyntaxKind::TypeClause => Some(12),
_ => None,
},
Some(SyntaxKind::ItemConstant) => match self.kind(db) {
SyntaxKind::ExprBinary
| SyntaxKind::ExprBlock
| SyntaxKind::ExprErrorPropagate
| SyntaxKind::ExprFieldInitShorthand
| SyntaxKind::ExprFunctionCall
| SyntaxKind::ExprIf
| SyntaxKind::ExprList
| SyntaxKind::ExprMatch
| SyntaxKind::ExprMissing
| SyntaxKind::ExprParenthesized
| SyntaxKind::ExprPath
| SyntaxKind::ExprStructCtorCall
| SyntaxKind::ExprListParenthesized
| SyntaxKind::ArgListBraced
| SyntaxKind::ArgListBracketed
| SyntaxKind::ExprUnary => Some(1),
SyntaxKind::TerminalEq => Some(10),
SyntaxKind::PatternEnum
| SyntaxKind::PatternTuple
| SyntaxKind::PatternStruct
| SyntaxKind::PatternFixedSizeArray => Some(11),
SyntaxKind::TypeClause => Some(12),
_ => None,
},
_ => match self.kind(db) {
SyntaxKind::ExprParenthesized
| SyntaxKind::ExprList
Expand Down Expand Up @@ -378,7 +403,9 @@ impl SyntaxNodeFormat for SyntaxNode {
| SyntaxKind::TraitItemList
| SyntaxKind::ImplItemList
| SyntaxKind::UsePathMulti
| SyntaxKind::ItemEnum => Some(5),
| SyntaxKind::ItemEnum
| SyntaxKind::PatternFixedSizeArray
| SyntaxKind::ExprFixedSizeArray => Some(5),
_ => None,
},
}
Expand Down
7 changes: 3 additions & 4 deletions crates/cairo-lang-lowering/src/test_data/constant
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ enum MyEnum {
B,
}

const MY_CONST: MyStruct =
MyStruct {
felt_val: 1234, bool_val: true, my_enum_val1: MyEnum::A(5678), my_enum_val2: MyEnum::B,
};
const MY_CONST: MyStruct = MyStruct {
felt_val: 1234, bool_val: true, my_enum_val1: MyEnum::A(5678), my_enum_val2: MyEnum::B,
};

//! > semantic_diagnostics

Expand Down
9 changes: 5 additions & 4 deletions crates/cairo-lang-semantic/src/expr/test_data/constant
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,11 @@ struct ComplexStruct {
e: bool,
}

const COMPLEX_STRUCT: ComplexStruct =
ComplexStruct { a: 1, b: {
const COMPLEX_STRUCT: ComplexStruct = ComplexStruct {
a: 1, b: {
IN_RANGE_NEGATIVE1
}, c: OUT_OF_RANGE_NEGATIVE2, d: 0, e: true, };
}, c: OUT_OF_RANGE_NEGATIVE2, d: 0, e: true,
};

const CONST_MEMBER: u8 = COMPLEX_STRUCT.a;

Expand Down Expand Up @@ -309,7 +310,7 @@ const CALCULATION_WITH_DIVISION: u8 = 120 / 0;

error: The value does not fit within the range of type core::zeroable::NonZero::<core::integer::u8>.
--> lib.cairo:31:38
}, c: OUT_OF_RANGE_NEGATIVE2, d: 0, e: true, };
}, c: OUT_OF_RANGE_NEGATIVE2, d: 0, e: true,
^

//! > ==========================================================================
Expand Down
12 changes: 5 additions & 7 deletions crates/cairo-lang-semantic/src/items/tests/trait_impl
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,8 @@ fn complex(
MyTrait::Impl1::InputType,
Option<
@Result<
[
Option<MyTrait::Impl2::InputType>
; 3], (@MyTrait::Impl1::Impl::InputType, MyTrait::Impl2::Impl::InputType)
[Option<MyTrait::Impl2::InputType>; 3],
(@MyTrait::Impl1::Impl::InputType, MyTrait::Impl2::Impl::InputType)
>
>
)
Expand Down Expand Up @@ -636,9 +635,8 @@ fn complex(
MyTrait::Impl1::InputType,
Option<
@Result<
[
Option<MyTrait::Impl2::InputType>
; 3], (@MyTrait::Impl1::Impl::InputType, MyTrait::Impl2::Impl::InputType)
[Option<MyTrait::Impl2::InputType>; 3],
(@MyTrait::Impl1::Impl::InputType, MyTrait::Impl2::Impl::InputType)
>
>
)
Expand All @@ -648,7 +646,7 @@ fn complex(

//! > expected_diagnostics
error: Unexpected return type. Expected: "@(core::integer::u32, core::option::Option::<@core::result::Result::<[core::option::Option::<core::integer::u32>; 3], (@core::integer::u32, core::integer::u32)>>)", found: "@(core::integer::u16, core::option::Option::<@core::result::Result::<[core::option::Option::<core::integer::u16>; 3], (@core::integer::u16, core::integer::u16)>>)".
--> lib.cairo:45:61
--> lib.cairo:44:61
) -> @(u32, Option<@Result<[Option<u32>; 3], (@u32, u32)>>) {
^

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ fn test_validate_gas_cost() {
selector: 0x219209e083275171774dab1df80982e9df2096516f06319c5c6d71ae0a8480c,
calldata: [
0x7a6f98c03379b9513ca84cca1373ff452a7462a3b61598f0af5bb27ad7f76d1, 0x4db5d32, 0x0
].span()
]
.span()
},
Call {
to: contract_address,
Expand All @@ -97,9 +98,11 @@ fn test_validate_gas_cost() {
0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7,
0x54767f773cc172172c3afc5265bd0a76089c24cdef409635d27ac1a1fa96ca8,
0x65586264
].span()
]
.span()
},
].span();
]
.span();
let post_call_building_gas = withdraw_and_get_available_gas();

let serialized_args = serialized(calls);
Expand Down

0 comments on commit 5761e45

Please sign in to comment.