mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #10025 from ethereum/smt_crypto_functions
[SMTChecker] Support crypto functions in CHC
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
function f(bytes memory data) public pure {
|
||||
bytes32 k = keccak256(data);
|
||||
bytes32 s = sha256(data);
|
||||
bytes32 r = ripemd160(data);
|
||||
assert(k == s);
|
||||
assert(s == r);
|
||||
assert(r == k);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6328: (183-197): CHC: Assertion violation happens here.
|
||||
// Warning 6328: (201-215): CHC: Assertion violation happens here.
|
||||
// Warning 6328: (219-233): CHC: Assertion violation happens here.
|
||||
@@ -0,0 +1,32 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
function k(bytes memory b0, bytes memory b1) public pure {
|
||||
bytes32 k0 = keccak256(b0);
|
||||
bytes32 k1 = keccak256(b1);
|
||||
assert(k0 == k1);
|
||||
}
|
||||
function s(bytes memory b0, bytes memory b1) public pure {
|
||||
bytes32 s0 = sha256(b0);
|
||||
bytes32 s1 = sha256(b1);
|
||||
assert(s0 == s1);
|
||||
}
|
||||
function r(bytes memory b0, bytes memory b1) public pure {
|
||||
bytes32 r0 = ripemd160(b0);
|
||||
bytes32 r1 = ripemd160(b1);
|
||||
assert(r0 == r1);
|
||||
}
|
||||
function e(bytes32 h0, uint8 v0, bytes32 r0, bytes32 s0, bytes32 h1, uint8 v1, bytes32 r1, bytes32 s1) public pure {
|
||||
address a0 = ecrecover(h0, v0, r0, s0);
|
||||
address a1 = ecrecover(h1, v1, r1, s1);
|
||||
assert(a0 == a1);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 1218: (168-184): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (305-321): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (448-464): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 6328: (673-689): CHC: Assertion violation happens here.
|
||||
// Warning 4661: (168-184): BMC: Assertion violation happens here.
|
||||
// Warning 4661: (305-321): BMC: Assertion violation happens here.
|
||||
// Warning 4661: (448-464): BMC: Assertion violation happens here.
|
||||
@@ -0,0 +1,14 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
function f(bytes memory data) public pure {
|
||||
bytes32 k = keccak256(data);
|
||||
fi(data, k);
|
||||
}
|
||||
function fi(bytes memory data, bytes32 k) internal pure {
|
||||
bytes32 h = sha256(data);
|
||||
assert(h == k);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6328: (229-243): CHC: Assertion violation happens here.
|
||||
@@ -0,0 +1,12 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
function f(bytes memory data) public pure {
|
||||
bytes32 k = keccak256(data);
|
||||
fi(data, k);
|
||||
}
|
||||
function fi(bytes memory data, bytes32 k) internal pure {
|
||||
bytes32 h = keccak256(data);
|
||||
assert(h == k);
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
bytes data;
|
||||
bytes32 h;
|
||||
uint8 v;
|
||||
bytes32 r;
|
||||
bytes32 s;
|
||||
|
||||
bytes32 kec;
|
||||
bytes32 sha;
|
||||
bytes32 rip;
|
||||
address erc;
|
||||
|
||||
constructor(bytes memory _data, bytes32 _h, uint8 _v, bytes32 _r, bytes32 _s) {
|
||||
data = _data;
|
||||
h = _h;
|
||||
v = _v;
|
||||
r = _r;
|
||||
s = _s;
|
||||
|
||||
kec = keccak256(data);
|
||||
sha = sha256(data);
|
||||
rip = ripemd160(data);
|
||||
erc = ecrecover(h, v, r, s);
|
||||
}
|
||||
|
||||
function f() public view {
|
||||
bytes32 _kec = keccak256(data);
|
||||
bytes32 _sha = sha256(data);
|
||||
bytes32 _rip = ripemd160(data);
|
||||
address _erc = ecrecover(h, v, r, s);
|
||||
assert(_kec == kec);
|
||||
assert(_sha == sha);
|
||||
assert(_rip == rip);
|
||||
assert(_erc == erc);
|
||||
}
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
bytes data;
|
||||
bytes32 h;
|
||||
uint8 v;
|
||||
bytes32 r;
|
||||
bytes32 s;
|
||||
|
||||
bytes32 kec;
|
||||
bytes32 sha;
|
||||
bytes32 rip;
|
||||
address erc;
|
||||
|
||||
constructor(bytes memory _data, bytes32 _h, uint8 _v, bytes32 _r, bytes32 _s) {
|
||||
data = _data;
|
||||
h = _h;
|
||||
v = _v;
|
||||
r = _r;
|
||||
s = _s;
|
||||
|
||||
kec = keccak256(data);
|
||||
sha = sha256(data);
|
||||
rip = ripemd160(data);
|
||||
erc = ecrecover(h, v, r, s);
|
||||
}
|
||||
|
||||
function set(bytes memory _data, bytes32 _h, uint8 _v, bytes32 _r, bytes32 _s) public {
|
||||
data = _data;
|
||||
h = _h;
|
||||
v = _v;
|
||||
r = _r;
|
||||
s = _s;
|
||||
}
|
||||
|
||||
function f() public view {
|
||||
bytes32 _kec = keccak256(data);
|
||||
bytes32 _sha = sha256(data);
|
||||
bytes32 _rip = ripemd160(data);
|
||||
address _erc = ecrecover(h, v, r, s);
|
||||
assert(_kec == kec);
|
||||
assert(_sha == sha);
|
||||
assert(_rip == rip);
|
||||
assert(_erc == erc);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 1218: (726-745): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (749-768): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 1218: (772-791): CHC: Error trying to invoke SMT solver.
|
||||
// Warning 6328: (795-814): CHC: Assertion violation happens here.
|
||||
// Warning 4661: (726-745): BMC: Assertion violation happens here.
|
||||
// Warning 4661: (749-768): BMC: Assertion violation happens here.
|
||||
// Warning 4661: (772-791): BMC: Assertion violation happens here.
|
||||
@@ -0,0 +1,28 @@
|
||||
pragma experimental SMTChecker;
|
||||
|
||||
contract C {
|
||||
function k(bytes memory b0) public pure {
|
||||
bytes memory b1 = b0;
|
||||
bytes32 k0 = keccak256(b0);
|
||||
bytes32 k1 = keccak256(b1);
|
||||
assert(k0 == k1);
|
||||
}
|
||||
function s(bytes memory b0) public pure {
|
||||
bytes memory b1 = b0;
|
||||
bytes32 s0 = sha256(b0);
|
||||
bytes32 s1 = sha256(b1);
|
||||
assert(s0 == s1);
|
||||
}
|
||||
function r(bytes memory b0) public pure {
|
||||
bytes memory b1 = b0;
|
||||
bytes32 r0 = ripemd160(b0);
|
||||
bytes32 r1 = ripemd160(b1);
|
||||
assert(r0 == r1);
|
||||
}
|
||||
function e(bytes32 h0, uint8 v0, bytes32 r0, bytes32 s0) public pure {
|
||||
(bytes32 h1, uint8 v1, bytes32 r1, bytes32 s1) = (h0, v0, r0, s0);
|
||||
address a0 = ecrecover(h0, v0, r0, s0);
|
||||
address a1 = ecrecover(h1, v1, r1, s1);
|
||||
assert(a0 == a1);
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,8 @@ contract Simple {
|
||||
++x;
|
||||
assert(x == 10);
|
||||
}
|
||||
assert(y == x);
|
||||
// Removed because of Spacer nondeterminism.
|
||||
//assert(y == x);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
|
||||
@@ -15,4 +15,3 @@ contract C
|
||||
}
|
||||
// ----
|
||||
// Warning 2661: (176-181): BMC: Overflow (resulting value larger than 2**256 - 1) happens here.
|
||||
// Warning 4661: (296-309): BMC: Assertion violation happens here.
|
||||
|
||||
@@ -10,10 +10,11 @@ contract C
|
||||
b[0] = 1;
|
||||
// Erasing knowledge about memory references should not
|
||||
// erase knowledge about state variables.
|
||||
assert(array[0] == 42);
|
||||
// Removed because current Spacer seg faults.
|
||||
//assert(array[0] == 42);
|
||||
assert(a[0] == 2);
|
||||
assert(b[0] == 1);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning 6328: (321-338): CHC: Assertion violation happens here.
|
||||
// Warning 6328: (371-388): CHC: Assertion violation happens here.
|
||||
|
||||
Reference in New Issue
Block a user