diff --git a/test/libsolidity/smtCheckerTests/types/type_typehash_different_scopes.sol b/test/libsolidity/smtCheckerTests/types/type_typehash_different_scopes.sol new file mode 100644 index 000000000..b9d7685c8 --- /dev/null +++ b/test/libsolidity/smtCheckerTests/types/type_typehash_different_scopes.sol @@ -0,0 +1,25 @@ +library A { + struct S1 { + uint256 x; + } + + bytes32 internal constant a = type(S1).typehash; +} + +library B { + struct S1 { + uint256 x; + } + + bytes32 internal constant b = type(S1).typehash; +} + +contract C { + function f() public pure { + assert(A.a == B.b); + } +} +// ==== +// SMTEngine: all +// ---- +// Info 1391: CHC: 1 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them. diff --git a/test/libsolidity/smtCheckerTests/types/type_typehash_inheritence.sol b/test/libsolidity/smtCheckerTests/types/type_typehash_inheritence.sol new file mode 100644 index 000000000..cb95d25b9 --- /dev/null +++ b/test/libsolidity/smtCheckerTests/types/type_typehash_inheritence.sol @@ -0,0 +1,19 @@ +contract A { + struct S { + string x; + } +} + +contract B { + struct S { + bool y; + } +} + +contract C is A, B { + function f() public pure { + assert(type(A.S).typehash != type(B.S).typehash); + } +} +// ---- +// DeclarationError 9097: (72-104): Identifier already declared. diff --git a/test/libsolidity/smtCheckerTests/types/type_typehash_shadow.sol b/test/libsolidity/smtCheckerTests/types/type_typehash_shadow.sol new file mode 100644 index 000000000..13addbec1 --- /dev/null +++ b/test/libsolidity/smtCheckerTests/types/type_typehash_shadow.sol @@ -0,0 +1,27 @@ +struct S { + uint256 x; +} + +bytes32 constant TYPE_HASH_FILE_LEVEL = type(S).typehash; + +contract A { + function f() public pure { + // TYPE_HASH_FILE_LEVEL == keccak256("S(uint256 x)") + assert(TYPE_HASH_FILE_LEVEL == 0x2a7af8c10b1d48ad8e0a6aad976d8385e84377b5bd03b59e2c445dc430ac2ca2); + } +} + +contract C { + struct S { + uint256 y; + } + + function f() public pure { + // type(S).typehash == keccak256("S(uint256 y)") and not the shadowed file-level struct S + assert(type(S).typehash == 0xea24952476a382c98f2d2e42112ff8a673d8ed19d22ffc89ee9fe2f415bf6c35); + assert(type(S).typehash != TYPE_HASH_FILE_LEVEL); + } +} +// ---- +// Warning 2519: (327-362): This declaration shadows an existing declaration. +// Info 1391: CHC: 3 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them. diff --git a/test/libsolidity/smtCheckerTests/types/type_typehash_super.sol b/test/libsolidity/smtCheckerTests/types/type_typehash_super.sol new file mode 100644 index 000000000..6c7e6d29b --- /dev/null +++ b/test/libsolidity/smtCheckerTests/types/type_typehash_super.sol @@ -0,0 +1,15 @@ +contract A { + struct S { + string x; + bool[10][] y; + } +} + +contract C is A { + function f() public pure { + // keccak256("S(string x,bool[10][] y)") + assert(type(S).typehash == 0xb4abec9b1d4b9d4724891b27b275d7d5e1692fe69fe6ff78379f613500046c11); + } +} +// ---- +// Info 1391: CHC: 1 verification condition(s) proved safe! Enable the model checker option "show proved safe" to see all of them. diff --git a/test/libsolidity/syntaxTests/types/struct/typehash_immutable.sol b/test/libsolidity/syntaxTests/types/struct/typehash_immutable.sol new file mode 100644 index 000000000..a2adbf737 --- /dev/null +++ b/test/libsolidity/syntaxTests/types/struct/typehash_immutable.sol @@ -0,0 +1,11 @@ +contract C { + struct S { + uint256[][10][] x; + } + + bytes32 immutable h; + + constructor() { + h = type(S).typehash; + } +} \ No newline at end of file