[SMTChecker] Add a new trusted mode which assumes that code that is

available at compile time is trusted.
This commit is contained in:
Leo Alt
2023-02-06 17:02:33 +01:00
parent f2bf23a067
commit 8d91ccf028
135 changed files with 3156 additions and 235 deletions
@@ -1 +1,27 @@
Warning: Requested contract "C" does not exist in source "model_checker_contracts_inexistent_contract/input.sol".
Warning: CHC: Assertion violation happens here.
Counterexample:
x = 0
Transaction trace:
B.constructor()
B.f(0)
--> model_checker_contracts_inexistent_contract/input.sol:5:3:
|
5 | assert(x > 0);
| ^^^^^^^^^^^^^
Warning: CHC: Assertion violation happens here.
Counterexample:
y = 0
Transaction trace:
A.constructor()
A.g(0)
--> model_checker_contracts_inexistent_contract/input.sol:10:3:
|
10 | assert(y > 0);
| ^^^^^^^^^^^^^
@@ -4,7 +4,7 @@ Counterexample:
x = 0
Transaction trace:
A.constructor()
B.constructor()
B.f(0)
--> model_checker_contracts_only_one/input.sol:5:3:
|
@@ -0,0 +1 @@
--model-checker-engine chc --model-checker-ext-calls
@@ -0,0 +1 @@
No input files given. If you wish to use the standard input please specify "-" explicitly.
@@ -0,0 +1 @@
1
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.0;
contract Ext {
function f() public view returns (uint) {
return 42;
}
}
contract test {
function g(Ext e) public view {
uint x = e.f();
assert(x == 42);
}
}
@@ -0,0 +1 @@
--model-checker-engine chc --model-checker-ext-calls trusted
@@ -0,0 +1,5 @@
Warning: Function state mutability can be restricted to pure
--> model_checker_ext_calls_trusted_chc/input.sol:5:2:
|
5 | function f() public view returns (uint) {
| ^ (Relevant source part starts here and spans across multiple lines).
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.0;
contract Ext {
function f() public view returns (uint) {
return 42;
}
}
contract test {
function g(Ext e) public view {
uint x = e.f();
assert(x == 42);
}
}
@@ -0,0 +1 @@
--model-checker-engine chc --model-checker-ext-calls untrusted
@@ -0,0 +1,14 @@
Warning: CHC: Assertion violation happens here.
Counterexample:
e = 0
x = 1
Transaction trace:
test.constructor()
test.g(0)
e.f() -- untrusted external call
--> model_checker_ext_calls_untrusted_chc/input.sol:11:3:
|
11 | assert(x == 0);
| ^^^^^^^^^^^^^^
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.0;
abstract contract Ext {
function f() virtual public view returns (uint);
}
contract test {
function g(Ext e) public view {
uint x = e.f();
assert(x == 0);
}
}
@@ -0,0 +1 @@
--model-checker-engine chc --model-checker-ext-calls what
@@ -0,0 +1 @@
Invalid option for --model-checker-ext-calls: what
@@ -0,0 +1 @@
1
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.0;
contract Ext {
function f() public view returns (uint) {
return 42;
}
}
contract test {
function g(Ext e) public view {
uint x = e.f();
assert(x == 42);
}
}
@@ -10,6 +10,74 @@
"message": "Requested contract \"C\" does not exist in source \"Source\".",
"severity": "warning",
"type": "Warning"
},
{
"component": "general",
"errorCode": "6328",
"formattedMessage": "Warning: CHC: Assertion violation happens here.
Counterexample:
y = 0
Transaction trace:
B.constructor()
B.g(0)
--> Source:5:7:
|
5 | \t\t\t\t\t\tassert(y > 0);
| \t\t\t\t\t\t^^^^^^^^^^^^^
",
"message": "CHC: Assertion violation happens here.
Counterexample:
y = 0
Transaction trace:
B.constructor()
B.g(0)",
"severity": "warning",
"sourceLocation":
{
"end": 137,
"file": "Source",
"start": 124
},
"type": "Warning"
},
{
"component": "general",
"errorCode": "6328",
"formattedMessage": "Warning: CHC: Assertion violation happens here.
Counterexample:
x = 0
Transaction trace:
A.constructor()
A.f(0)
--> Source:10:7:
|
10 | \t\t\t\t\t\tassert(x > 0);
| \t\t\t\t\t\t^^^^^^^^^^^^^
",
"message": "CHC: Assertion violation happens here.
Counterexample:
x = 0
Transaction trace:
A.constructor()
A.f(0)",
"severity": "warning",
"sourceLocation":
{
"end": 231,
"file": "Source",
"start": 218
},
"type": "Warning"
}
],
"sources":
@@ -10,7 +10,7 @@ Counterexample:
y = 0
Transaction trace:
A.constructor()
B.constructor()
B.g(0)
--> Source:5:7:
|
@@ -24,7 +24,7 @@ Counterexample:
y = 0
Transaction trace:
A.constructor()
B.constructor()
B.g(0)",
"severity": "warning",
"sourceLocation":
@@ -10,7 +10,7 @@ Counterexample:
y = 0
Transaction trace:
A.constructor()
B.constructor()
B.g(0)
--> Source:5:7:
|
@@ -24,7 +24,7 @@ Counterexample:
y = 0
Transaction trace:
A.constructor()
B.constructor()
B.g(0)",
"severity": "warning",
"sourceLocation":
@@ -0,0 +1,30 @@
{
"language": "Solidity",
"sources":
{
"A":
{
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.0;
contract Ext {
function f() public view returns (uint) {
return 42;
}
}
contract test {
function g(Ext e) public view {
uint x = e.f();
assert(x == 42);
}
}"
}
},
"settings":
{
"modelChecker":
{
"engine": "chc",
"extCalls": ""
}
}
}
@@ -0,0 +1,12 @@
{
"errors":
[
{
"component": "general",
"formattedMessage": "Invalid model checker extCalls requested.",
"message": "Invalid model checker extCalls requested.",
"severity": "error",
"type": "JSONError"
}
]
}
@@ -0,0 +1,30 @@
{
"language": "Solidity",
"sources":
{
"A":
{
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.0;
contract Ext {
function f() public view returns (uint) {
return 42;
}
}
contract test {
function g(Ext e) public view {
uint x = e.f();
assert(x == 42);
}
}"
}
},
"settings":
{
"modelChecker":
{
"engine": "chc",
"extCalls": "trusted"
}
}
}
@@ -0,0 +1,32 @@
{
"errors":
[
{
"component": "general",
"errorCode": "2018",
"formattedMessage": "Warning: Function state mutability can be restricted to pure
--> A:4:7:
|
4 | \t\t\t\t\t\tfunction f() public view returns (uint) {
| \t\t\t\t\t\t^ (Relevant source part starts here and spans across multiple lines).
",
"message": "Function state mutability can be restricted to pure",
"severity": "warning",
"sourceLocation":
{
"end": 152,
"file": "A",
"start": 85
},
"type": "Warning"
}
],
"sources":
{
"A":
{
"id": 0
}
}
}
@@ -0,0 +1,28 @@
{
"language": "Solidity",
"sources":
{
"A":
{
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.0;
abstract contract Ext {
function f() virtual public view returns (uint);
}
contract test {
function g(Ext e) public view {
uint x = e.f();
assert(x == 0);
}
}"
}
},
"settings":
{
"modelChecker":
{
"engine": "chc",
"extCalls": "untrusted"
}
}
}
@@ -0,0 +1,50 @@
{
"errors":
[
{
"component": "general",
"errorCode": "6328",
"formattedMessage": "Warning: CHC: Assertion violation happens here.
Counterexample:
e = 0
x = 1
Transaction trace:
test.constructor()
test.g(0)
e.f() -- untrusted external call
--> A:10:8:
|
10 | \t\t\t\t\t\t\tassert(x == 0);
| \t\t\t\t\t\t\t^^^^^^^^^^^^^^
",
"message": "CHC: Assertion violation happens here.
Counterexample:
e = 0
x = 1
Transaction trace:
test.constructor()
test.g(0)
e.f() -- untrusted external call",
"severity": "warning",
"sourceLocation":
{
"end": 254,
"file": "A",
"start": 240
},
"type": "Warning"
}
],
"sources":
{
"A":
{
"id": 0
}
}
}
@@ -0,0 +1,30 @@
{
"language": "Solidity",
"sources":
{
"A":
{
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.0;
contract Ext {
function f() public view returns (uint) {
return 42;
}
}
contract test {
function g(Ext e) public view {
uint x = e.f();
assert(x == 42);
}
}"
}
},
"settings":
{
"modelChecker":
{
"engine": "chc",
"extCalls": "what"
}
}
}
@@ -0,0 +1,12 @@
{
"errors":
[
{
"component": "general",
"formattedMessage": "Invalid model checker extCalls requested.",
"message": "Invalid model checker extCalls requested.",
"severity": "error",
"type": "JSONError"
}
]
}
@@ -0,0 +1,30 @@
{
"language": "Solidity",
"sources":
{
"A":
{
"content": "// SPDX-License-Identifier: GPL-3.0\npragma solidity >=0.0;
contract Ext {
function f() public view returns (uint) {
return 42;
}
}
contract test {
function g(Ext e) public view {
uint x = e.f();
assert(x == 42);
}
}"
}
},
"settings":
{
"modelChecker":
{
"engine": "chc",
"extCalls": 2
}
}
}
@@ -0,0 +1,12 @@
{
"errors":
[
{
"component": "general",
"formattedMessage": "settings.modelChecker.extCalls must be a string.",
"message": "settings.modelChecker.extCalls must be a string.",
"severity": "error",
"type": "JSONError"
}
]
}
@@ -3,14 +3,41 @@
{
"smtlib2queries":
{
"0x0ebc730de380833af1e52ed063befb32994bc637929c942b7fd089b7cd3ba64e": "(set-logic HORN)
"0x75b95497d56c30e254a59358d72ddd4e78f9e90db621cfe677e85d05b2252411": "(set-option :produce-models true)
(set-logic ALL)
(declare-fun |x_3_3| () Int)
(declare-fun |error_0| () Int)
(declare-fun |this_0| () Int)
(declare-datatypes ((|bytes_tuple| 0)) (((|bytes_tuple| (|bytes_tuple_accessor_array| (Array Int Int)) (|bytes_tuple_accessor_length| Int)))))
(declare-datatypes ((|tx_type| 0)) (((|tx_type| (|block.basefee| Int) (|block.chainid| Int) (|block.coinbase| Int) (|block.gaslimit| Int) (|block.number| Int) (|block.prevrandao| Int) (|block.timestamp| Int) (|blockhash| (Array Int Int)) (|msg.data| |bytes_tuple|) (|msg.sender| Int) (|msg.sig| Int) (|msg.value| Int) (|tx.gasprice| Int) (|tx.origin| Int)))))
(declare-fun |tx_0| () |tx_type|)
(declare-datatypes ((|ecrecover_input_type| 0)) (((|ecrecover_input_type| (|hash| Int) (|v| Int) (|r| Int) (|s| Int)))))
(declare-datatypes ((|crypto_type| 0)) (((|crypto_type| (|ecrecover| (Array |ecrecover_input_type| Int)) (|keccak256| (Array |bytes_tuple| Int)) (|ripemd160| (Array |bytes_tuple| Int)) (|sha256| (Array |bytes_tuple| Int))))))
(declare-fun |crypto_0| () |crypto_type|)
(declare-datatypes ((|abi_type| 0)) (((|abi_type|))))
(declare-fun |abi_0| () |abi_type|)
(declare-datatypes ((|state_type| 0)) (((|state_type| (|balances| (Array Int Int))))))
(declare-fun |state_0| () |state_type|)
(declare-fun |x_3_4| () Int)
(declare-fun |x_3_0| () Int)
(declare-fun |expr_7_0| () Int)
(declare-fun |expr_8_0| () Int)
(declare-fun |expr_9_1| () Bool)
(assert (and (and (and true true) (and (= expr_9_1 (> expr_7_0 expr_8_0)) (and (=> (and true true) true) (and (= expr_8_0 0) (and (=> (and true true) (and (>= expr_7_0 0) (<= expr_7_0 115792089237316195423570985008687907853269984665640564039457584007913129639935))) (and (= expr_7_0 x_3_0) (and (and (>= x_3_0 0) (<= x_3_0 115792089237316195423570985008687907853269984665640564039457584007913129639935)) (and (and (and (and (and (and (and (and (and (and (and (and (and (> (|block.prevrandao| tx_0) 18446744073709551616) (and (>= (|block.basefee| tx_0) 0) (<= (|block.basefee| tx_0) 115792089237316195423570985008687907853269984665640564039457584007913129639935))) (and (>= (|block.chainid| tx_0) 0) (<= (|block.chainid| tx_0) 115792089237316195423570985008687907853269984665640564039457584007913129639935))) (and (>= (|block.coinbase| tx_0) 0) (<= (|block.coinbase| tx_0) 1461501637330902918203684832716283019655932542975))) (and (>= (|block.prevrandao| tx_0) 0) (<= (|block.prevrandao| tx_0) 115792089237316195423570985008687907853269984665640564039457584007913129639935))) (and (>= (|block.gaslimit| tx_0) 0) (<= (|block.gaslimit| tx_0) 115792089237316195423570985008687907853269984665640564039457584007913129639935))) (and (>= (|block.number| tx_0) 0) (<= (|block.number| tx_0) 115792089237316195423570985008687907853269984665640564039457584007913129639935))) (and (>= (|block.timestamp| tx_0) 0) (<= (|block.timestamp| tx_0) 115792089237316195423570985008687907853269984665640564039457584007913129639935))) (and (>= (|msg.sender| tx_0) 0) (<= (|msg.sender| tx_0) 1461501637330902918203684832716283019655932542975))) (and (>= (|msg.value| tx_0) 0) (<= (|msg.value| tx_0) 115792089237316195423570985008687907853269984665640564039457584007913129639935))) (and (>= (|tx.origin| tx_0) 0) (<= (|tx.origin| tx_0) 1461501637330902918203684832716283019655932542975))) (and (>= (|tx.gasprice| tx_0) 0) (<= (|tx.gasprice| tx_0) 115792089237316195423570985008687907853269984665640564039457584007913129639935))) (and (and (and (and (and (and (= (|msg.value| tx_0) 0) (= (|msg.sig| tx_0) 3017696395)) (= (select (|bytes_tuple_accessor_array| (|msg.data| tx_0)) 0) 179)) (= (select (|bytes_tuple_accessor_array| (|msg.data| tx_0)) 1) 222)) (= (select (|bytes_tuple_accessor_array| (|msg.data| tx_0)) 2) 100)) (= (select (|bytes_tuple_accessor_array| (|msg.data| tx_0)) 3) 139)) (>= (|bytes_tuple_accessor_length| (|msg.data| tx_0)) 4))) true)))))))) (not expr_9_1)))
(declare-const |EVALEXPR_0| Int)
(assert (= |EVALEXPR_0| x_3_0))
(check-sat)
(get-value (|EVALEXPR_0| ))
",
"0xfb06d3f02a20bd362abded9ab80638bdc9dd43ccbf644517f3006206c0c47f67": "(set-logic HORN)
(declare-datatypes ((|bytes_tuple| 0)) (((|bytes_tuple| (|bytes_tuple_accessor_array| (Array Int Int)) (|bytes_tuple_accessor_length| Int)))))
(declare-datatypes ((|tx_type| 0)) (((|tx_type| (|block.basefee| Int) (|block.chainid| Int) (|block.coinbase| Int) (|block.gaslimit| Int) (|block.number| Int) (|block.prevrandao| Int) (|block.timestamp| Int) (|blockhash| (Array Int Int)) (|msg.data| |bytes_tuple|) (|msg.sender| Int) (|msg.sig| Int) (|msg.value| Int) (|tx.gasprice| Int) (|tx.origin| Int)))))
(declare-datatypes ((|ecrecover_input_type| 0)) (((|ecrecover_input_type| (|hash| Int) (|v| Int) (|r| Int) (|s| Int)))))
(declare-datatypes ((|crypto_type| 0)) (((|crypto_type| (|ecrecover| (Array |ecrecover_input_type| Int)) (|keccak256| (Array |bytes_tuple| Int)) (|ripemd160| (Array |bytes_tuple| Int)) (|sha256| (Array |bytes_tuple| Int))))))
(declare-datatypes ((|abi_type| 0)) (((|abi_type|))))
(declare-datatypes ((|state_type| 0)) (((|state_type| (|balances| (Array Int Int))))))
(declare-fun |interface_0_C_14_0| (Int |abi_type| |crypto_type| |state_type| ) Bool)
(declare-fun |nondet_interface_1_C_14_0| (Int Int |abi_type| |crypto_type| |state_type| |state_type| ) Bool)
(declare-fun |summary_constructor_2_C_14_0| (Int Int |abi_type| |crypto_type| |tx_type| |state_type| |state_type| ) Bool)
@@ -97,7 +124,7 @@
(declare-fun |implicit_constructor_entry_13_C_14_0| (Int Int |abi_type| |crypto_type| |tx_type| |state_type| |state_type| ) Bool)
(assert
(forall ( (abi_0 |abi_type|) (crypto_0 |crypto_type|) (error_0 Int) (error_1 Int) (expr_7_0 Int) (expr_8_0 Int) (expr_9_1 Bool) (funds_2_0 Int) (state_0 |state_type|) (state_1 |state_type|) (state_2 |state_type|) (state_3 |state_type|) (this_0 Int) (tx_0 |tx_type|) (x_3_0 Int) (x_3_1 Int) (x_3_2 Int))
(=> (and (and (and (and (= state_1 state_0) (= error_0 0)) true) true) (>= (select (|balances| state_1) this_0) (|msg.value| tx_0))) (implicit_constructor_entry_13_C_14_0 error_0 this_0 abi_0 crypto_0 tx_0 state_0 state_1))))
(=> (and (and (and (and (and (= state_1 state_0) (= error_0 0)) true) true) true) (>= (select (|balances| state_1) this_0) (|msg.value| tx_0))) (implicit_constructor_entry_13_C_14_0 error_0 this_0 abi_0 crypto_0 tx_0 state_0 state_1))))
(assert
@@ -124,34 +151,7 @@
(assert
(forall ( (abi_0 |abi_type|) (crypto_0 |crypto_type|) (error_0 Int) (error_1 Int) (expr_7_0 Int) (expr_8_0 Int) (expr_9_1 Bool) (funds_2_0 Int) (state_0 |state_type|) (state_1 |state_type|) (state_2 |state_type|) (state_3 |state_type|) (this_0 Int) (tx_0 |tx_type|) (x_3_0 Int) (x_3_1 Int) (x_3_2 Int))
(=> error_target_3_0 false)))
(check-sat)",
"0xcb822e6220a39244d26887a0fa6f62b06718359056555679fb06dd7dff18bb86": "(set-option :produce-models true)
(set-logic ALL)
(declare-fun |x_3_3| () Int)
(declare-fun |error_0| () Int)
(declare-fun |this_0| () Int)
(declare-datatypes ((|state_type| 0)) (((|state_type| (|balances| (Array Int Int))))))
(declare-fun |state_0| () |state_type|)
(declare-datatypes ((|bytes_tuple| 0)) (((|bytes_tuple| (|bytes_tuple_accessor_array| (Array Int Int)) (|bytes_tuple_accessor_length| Int)))))
(declare-datatypes ((|tx_type| 0)) (((|tx_type| (|block.basefee| Int) (|block.chainid| Int) (|block.coinbase| Int) (|block.gaslimit| Int) (|block.number| Int) (|block.prevrandao| Int) (|block.timestamp| Int) (|blockhash| (Array Int Int)) (|msg.data| |bytes_tuple|) (|msg.sender| Int) (|msg.sig| Int) (|msg.value| Int) (|tx.gasprice| Int) (|tx.origin| Int)))))
(declare-fun |tx_0| () |tx_type|)
(declare-datatypes ((|ecrecover_input_type| 0)) (((|ecrecover_input_type| (|hash| Int) (|v| Int) (|r| Int) (|s| Int)))))
(declare-datatypes ((|crypto_type| 0)) (((|crypto_type| (|ecrecover| (Array |ecrecover_input_type| Int)) (|keccak256| (Array |bytes_tuple| Int)) (|ripemd160| (Array |bytes_tuple| Int)) (|sha256| (Array |bytes_tuple| Int))))))
(declare-fun |crypto_0| () |crypto_type|)
(declare-datatypes ((|abi_type| 0)) (((|abi_type|))))
(declare-fun |abi_0| () |abi_type|)
(declare-fun |x_3_4| () Int)
(declare-fun |x_3_0| () Int)
(declare-fun |expr_7_0| () Int)
(declare-fun |expr_8_0| () Int)
(declare-fun |expr_9_1| () Bool)
(assert (and (and (and true true) (and (= expr_9_1 (> expr_7_0 expr_8_0)) (and (=> (and true true) true) (and (= expr_8_0 0) (and (=> (and true true) (and (>= expr_7_0 0) (<= expr_7_0 115792089237316195423570985008687907853269984665640564039457584007913129639935))) (and (= expr_7_0 x_3_0) (and (and (>= x_3_0 0) (<= x_3_0 115792089237316195423570985008687907853269984665640564039457584007913129639935)) (and (and (and (and (and (and (and (and (and (and (and (and (and (> (|block.prevrandao| tx_0) 18446744073709551616) (and (>= (|block.basefee| tx_0) 0) (<= (|block.basefee| tx_0) 115792089237316195423570985008687907853269984665640564039457584007913129639935))) (and (>= (|block.chainid| tx_0) 0) (<= (|block.chainid| tx_0) 115792089237316195423570985008687907853269984665640564039457584007913129639935))) (and (>= (|block.coinbase| tx_0) 0) (<= (|block.coinbase| tx_0) 1461501637330902918203684832716283019655932542975))) (and (>= (|block.prevrandao| tx_0) 0) (<= (|block.prevrandao| tx_0) 115792089237316195423570985008687907853269984665640564039457584007913129639935))) (and (>= (|block.gaslimit| tx_0) 0) (<= (|block.gaslimit| tx_0) 115792089237316195423570985008687907853269984665640564039457584007913129639935))) (and (>= (|block.number| tx_0) 0) (<= (|block.number| tx_0) 115792089237316195423570985008687907853269984665640564039457584007913129639935))) (and (>= (|block.timestamp| tx_0) 0) (<= (|block.timestamp| tx_0) 115792089237316195423570985008687907853269984665640564039457584007913129639935))) (and (>= (|msg.sender| tx_0) 0) (<= (|msg.sender| tx_0) 1461501637330902918203684832716283019655932542975))) (and (>= (|msg.value| tx_0) 0) (<= (|msg.value| tx_0) 115792089237316195423570985008687907853269984665640564039457584007913129639935))) (and (>= (|tx.origin| tx_0) 0) (<= (|tx.origin| tx_0) 1461501637330902918203684832716283019655932542975))) (and (>= (|tx.gasprice| tx_0) 0) (<= (|tx.gasprice| tx_0) 115792089237316195423570985008687907853269984665640564039457584007913129639935))) (and (and (and (and (and (and (= (|msg.value| tx_0) 0) (= (|msg.sig| tx_0) 3017696395)) (= (select (|bytes_tuple_accessor_array| (|msg.data| tx_0)) 0) 179)) (= (select (|bytes_tuple_accessor_array| (|msg.data| tx_0)) 1) 222)) (= (select (|bytes_tuple_accessor_array| (|msg.data| tx_0)) 2) 100)) (= (select (|bytes_tuple_accessor_array| (|msg.data| tx_0)) 3) 139)) (>= (|bytes_tuple_accessor_length| (|msg.data| tx_0)) 4))) true)))))))) (not expr_9_1)))
(declare-const |EVALEXPR_0| Int)
(assert (= |EVALEXPR_0| x_3_0))
(check-sat)
(get-value (|EVALEXPR_0| ))
"
(check-sat)"
}
},
"errors":