Skip to content

Commit

Permalink
Utilize multifile compiling (#164)
Browse files Browse the repository at this point in the history
* Tweaked Scribble executable to utilize multifile compiling from solc-typed-ast. Removed source unit merging logic. Updated affected test samples.
  • Loading branch information
blitz-1306 committed Apr 4, 2022
1 parent ad4ca9c commit 93e6c0d
Show file tree
Hide file tree
Showing 15 changed files with 211 additions and 627 deletions.
324 changes: 150 additions & 174 deletions src/bin/scribble.ts

Large diffs are not rendered by default.

395 changes: 0 additions & 395 deletions src/rewriter/merge.ts

This file was deleted.

3 changes: 3 additions & 0 deletions test/integration/scribble/run/invalid.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { scribble } from "../../utils";

describe(`Command "scribble <filename>" is failing as expected`, () => {
const cases: Array<[string[], RegExp | string]> = [
[[""], /^Path is empty/g],
[["missing.sol"], /^Path not found: missing\.sol/g],
[["test/"], /^Target is not a file: test\//g],
[
["test/samples/invalid/missing_terminator_semicolon.invalid.sol"],
/^test\/samples\/invalid\/missing_terminator_semicolon.invalid.sol:12:8 SyntaxError: Expected .* but .* found/m
Expand Down
4 changes: 2 additions & 2 deletions test/integration/scribble/run/valid.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ describe(`Command "scribble <filename>" is working properly`, () => {
});

it("STDOUT is correct", () => {
const instrSource = fse.readFileSync(instrFileName, { encoding: "utf-8" });

// Uncomment next line to update instrumented sources
// fse.writeFileSync(instrFileName, output, { encoding: "utf-8" });

const instrSource = fse.readFileSync(instrFileName, { encoding: "utf-8" });

expect(output).toEqual(instrSource);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,4 @@ contract Token is __scribble_ReentrancyUtils, ERC20 {
__scribble_Token_check_state_invariants_internal();
__scribble_ERC20_check_state_invariants_internal();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract Base {
uint256_to_uint256.S internal a;
string_to_int16.S c0;
string internal sS;
string_to_uint8_to_int8_S_481.S internal d;
string_to_uint8_to_int8_S_488.S internal d;
uint256_to_uint256_arr.S internal e;
mapping(uint => uint)[] internal f;
uint256_to_uint256.S[] internal g;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ contract Foo is __scribble_ReentrancyUtils, Base {
for (_v.i3 = 1; _v.i3 < d.keys.length; _v.i3++) {
_v.s1 = d.keys[_v.i3];
_v.forall_4 = true;
for (_v.i4 = 1; _v.i4 < string_to_uint8_to_int8_S_481.get(d, _v.s1).keys.length; _v.i4++) {
_v.k2 = string_to_uint8_to_int8_S_481.get(d, _v.s1).keys[_v.i4];
_v.forall_4 = uint8_to_int8.get(string_to_uint8_to_int8_S_481.get(d, _v.s1), _v.k2) > 0;
for (_v.i4 = 1; _v.i4 < string_to_uint8_to_int8_S_488.get(d, _v.s1).keys.length; _v.i4++) {
_v.k2 = string_to_uint8_to_int8_S_488.get(d, _v.s1).keys[_v.i4];
_v.forall_4 = uint8_to_int8.get(string_to_uint8_to_int8_S_488.get(d, _v.s1), _v.k2) > 0;
if (!_v.forall_4) break;
}
_v.forall_3 = _v.forall_4;
Expand All @@ -163,7 +163,7 @@ contract Foo is __scribble_ReentrancyUtils, Base {
}

function _original_Foo_setD(string memory s, uint8 k, int8 v) private {
uint8_to_int8.set(string_to_uint8_to_int8_S_481.get_lhs(d, s), k, v);
uint8_to_int8.set(string_to_uint8_to_int8_S_488.get_lhs(d, s), k, v);
}

function setE(uint k, uint[] memory v) public {
Expand Down
12 changes: 6 additions & 6 deletions test/multifile_samples/forall_maps/flat.sol.expected
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ contract Base {
uint256_to_uint256.S internal a;
string_to_int16.S c0;
string internal sS;
string_to_uint8_to_int8_S_481.S internal d;
string_to_uint8_to_int8_S_488.S internal d;
uint256_to_uint256_arr.S internal e;
mapping(uint => uint)[] internal f;
uint256_to_uint256.S[] internal g;
Expand Down Expand Up @@ -226,7 +226,7 @@ library string_to_int16 {
}
}

library string_to_uint8_to_int8_S_481 {
library string_to_uint8_to_int8_S_488 {
struct S {
mapping(string => uint8_to_int8.S) innerM;
string[] keys;
Expand Down Expand Up @@ -489,9 +489,9 @@ contract Foo is __scribble_ReentrancyUtils, Base {
for (_v.i3 = 1; _v.i3 < d.keys.length; _v.i3++) {
_v.s1 = d.keys[_v.i3];
_v.forall_4 = true;
for (_v.i4 = 1; _v.i4 < string_to_uint8_to_int8_S_481.get(d, _v.s1).keys.length; _v.i4++) {
_v.k2 = string_to_uint8_to_int8_S_481.get(d, _v.s1).keys[_v.i4];
_v.forall_4 = uint8_to_int8.get(string_to_uint8_to_int8_S_481.get(d, _v.s1), _v.k2) > 0;
for (_v.i4 = 1; _v.i4 < string_to_uint8_to_int8_S_488.get(d, _v.s1).keys.length; _v.i4++) {
_v.k2 = string_to_uint8_to_int8_S_488.get(d, _v.s1).keys[_v.i4];
_v.forall_4 = uint8_to_int8.get(string_to_uint8_to_int8_S_488.get(d, _v.s1), _v.k2) > 0;
if (!_v.forall_4) break;
}
_v.forall_3 = _v.forall_4;
Expand All @@ -505,7 +505,7 @@ contract Foo is __scribble_ReentrancyUtils, Base {
}

function _original_Foo_setD(string memory s, uint8 k, int8 v) private {
uint8_to_int8.set(string_to_uint8_to_int8_S_481.get_lhs(d, s), k, v);
uint8_to_int8.set(string_to_uint8_to_int8_S_488.get_lhs(d, s), k, v);
}

function setE(uint k, uint[] memory v) public {
Expand Down
4 changes: 2 additions & 2 deletions test/samples/calldata_paramteres.instrumented.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ contract Test is __scribble_ReentrancyUtils {

function _original_Test_moo() private {
bytes memory m = "abc";
bytes memory n = _callsite_27(this, m);
bytes memory n = _callsite_26(this, m);
assert(n[0] == "a");
assert(n[1] == "b");
assert(n[2] == "c");
Expand All @@ -64,7 +64,7 @@ contract Test is __scribble_ReentrancyUtils {
__scribble_out_of_contract = true;
}

function _callsite_27(Test receiver, bytes memory arg0) private returns (bytes memory ret0) {
function _callsite_26(Test receiver, bytes memory arg0) private returns (bytes memory ret0) {
__scribble_check_state_invariants();
__scribble_out_of_contract = true;
(ret0) = receiver.foo(arg0);
Expand Down
20 changes: 10 additions & 10 deletions test/samples/contract_decorated_ext_call.instrumented.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ contract Foo is __scribble_ReentrancyUtils {

function fail_int() internal {
x = 0;
_callsite_23(this, 0);
_callsite_26(this, 0);
x = 0;
_callsite_34(this, 10000);
_callsite_39(this, 10000);
x = 0;
_callsite_45(this, 0, 10000);
_callsite_55(this, 0, 10000);
x = 0;
_callsite_59(this, 0, 10000);
_callsite_67(this, 0, 10000);
}

function fail() public {
Expand All @@ -74,7 +74,7 @@ contract Foo is __scribble_ReentrancyUtils {
}

function _original_Foo_withdraw(uint _amount) private {
(bool success, bytes memory retval) = _callsite_83(msg.sender, _amount, "");
(bool success, bytes memory retval) = _callsite_93(msg.sender, _amount, "");
require(success);
}

Expand All @@ -97,35 +97,35 @@ contract Foo is __scribble_ReentrancyUtils {
__scribble_out_of_contract = true;
}

function _callsite_23(Foo receiver, uint256 _value) private {
function _callsite_26(Foo receiver, uint256 _value) private {
__scribble_check_state_invariants();
__scribble_out_of_contract = true;
receiver.inc{value: _value}();
__scribble_out_of_contract = false;
}

function _callsite_34(Foo receiver, uint256 _gas) private {
function _callsite_39(Foo receiver, uint256 _gas) private {
__scribble_check_state_invariants();
__scribble_out_of_contract = true;
receiver.inc{gas: _gas}();
__scribble_out_of_contract = false;
}

function _callsite_45(Foo receiver, uint256 _value, uint256 _gas) private {
function _callsite_55(Foo receiver, uint256 _value, uint256 _gas) private {
__scribble_check_state_invariants();
__scribble_out_of_contract = true;
receiver.inc{gas: _gas, value: _value}();
__scribble_out_of_contract = false;
}

function _callsite_59(Foo receiver, uint256 _value, uint256 _gas) private {
function _callsite_67(Foo receiver, uint256 _value, uint256 _gas) private {
__scribble_check_state_invariants();
__scribble_out_of_contract = true;
receiver.inc{gas: _gas, value: _value}();
__scribble_out_of_contract = false;
}

function _callsite_83(address payable receiver, uint256 _value, bytes memory arg0) private returns (bool ret0, bytes memory ret1) {
function _callsite_93(address payable receiver, uint256 _value, bytes memory arg0) private returns (bool ret0, bytes memory ret1) {
__scribble_check_state_invariants();
__scribble_out_of_contract = true;
(ret0, ret1) = receiver.call{value: _value}(arg0);
Expand Down
16 changes: 8 additions & 8 deletions test/samples/contract_decorated_ext_callv05.instrumented.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ contract Foo is __scribble_ReentrancyUtils {

function fail_int() internal {
x = 0;
_callsite_23(this, 0);
_callsite_25(this, 0);
x = 0;
_callsite_34(this, 10000);
_callsite_38(this, 10000);
x = 0;
_callsite_45(this, 0, 10000);
_callsite_54(this, 0, 10000);
}

function fail() public {
Expand All @@ -72,7 +72,7 @@ contract Foo is __scribble_ReentrancyUtils {
}

function _original_Foo_withdraw(uint _amount) private {
(bool success, bytes memory retval) = _callsite_72(msg.sender, _amount, "");
(bool success, bytes memory retval) = _callsite_80(msg.sender, _amount, "");
require(success);
}

Expand All @@ -95,28 +95,28 @@ contract Foo is __scribble_ReentrancyUtils {
__scribble_out_of_contract = true;
}

function _callsite_23(Foo receiver, uint256 _value) private {
function _callsite_25(Foo receiver, uint256 _value) private {
__scribble_check_state_invariants();
__scribble_out_of_contract = true;
receiver.inc.value(_value)();
__scribble_out_of_contract = false;
}

function _callsite_34(Foo receiver, uint256 _gas) private {
function _callsite_38(Foo receiver, uint256 _gas) private {
__scribble_check_state_invariants();
__scribble_out_of_contract = true;
receiver.inc.gas(_gas)();
__scribble_out_of_contract = false;
}

function _callsite_45(Foo receiver, uint256 _value, uint256 _gas) private {
function _callsite_54(Foo receiver, uint256 _value, uint256 _gas) private {
__scribble_check_state_invariants();
__scribble_out_of_contract = true;
receiver.inc.gas(_gas).value(_value)();
__scribble_out_of_contract = false;
}

function _callsite_72(address payable receiver, uint256 _value, bytes memory arg0) private returns (bool ret0, bytes memory ret1) {
function _callsite_80(address payable receiver, uint256 _value, bytes memory arg0) private returns (bool ret0, bytes memory ret1) {
__scribble_check_state_invariants();
__scribble_out_of_contract = true;
(ret0, ret1) = receiver.call.value(_value)(arg0);
Expand Down
4 changes: 2 additions & 2 deletions test/samples/contract_pos_ext_call_fail.instrumented.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ contract Foo is __scribble_ReentrancyUtils {

function fail_int() internal {
x = 0;
_callsite_23(this);
_callsite_22(this);
}

function fail() public {
Expand Down Expand Up @@ -73,7 +73,7 @@ contract Foo is __scribble_ReentrancyUtils {
__scribble_out_of_contract = true;
}

function _callsite_23(Foo receiver) private {
function _callsite_22(Foo receiver) private {
__scribble_check_state_invariants();
__scribble_out_of_contract = true;
receiver.inc();
Expand Down
12 changes: 6 additions & 6 deletions test/samples/forall_maps.instrumented.sol
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ library string_to_int16 {
}
}

library string_to_uint8_to_int8_S_514 {
library string_to_uint8_to_int8_S_522 {
struct S {
mapping(string => uint8_to_int8.S) innerM;
string[] keys;
Expand Down Expand Up @@ -411,7 +411,7 @@ contract Foo is __scribble_ReentrancyUtils {
uint256_to_uint256.S internal a;
string_to_int16.S c0;
string internal sS;
string_to_uint8_to_int8_S_514.S internal d;
string_to_uint8_to_int8_S_522.S internal d;
uint256_to_uint256_arr.S internal e;
mapping(uint => uint)[] internal f;
uint256_to_uint256.S[] internal g;
Expand Down Expand Up @@ -491,9 +491,9 @@ contract Foo is __scribble_ReentrancyUtils {
for (_v.i3 = 1; _v.i3 < d.keys.length; _v.i3++) {
_v.s1 = d.keys[_v.i3];
_v.forall_4 = true;
for (_v.i4 = 1; _v.i4 < string_to_uint8_to_int8_S_514.get(d, _v.s1).keys.length; _v.i4++) {
_v.k2 = string_to_uint8_to_int8_S_514.get(d, _v.s1).keys[_v.i4];
_v.forall_4 = uint8_to_int8.get(string_to_uint8_to_int8_S_514.get(d, _v.s1), _v.k2) > 0;
for (_v.i4 = 1; _v.i4 < string_to_uint8_to_int8_S_522.get(d, _v.s1).keys.length; _v.i4++) {
_v.k2 = string_to_uint8_to_int8_S_522.get(d, _v.s1).keys[_v.i4];
_v.forall_4 = uint8_to_int8.get(string_to_uint8_to_int8_S_522.get(d, _v.s1), _v.k2) > 0;
if (!_v.forall_4) break;
}
_v.forall_3 = _v.forall_4;
Expand All @@ -507,7 +507,7 @@ contract Foo is __scribble_ReentrancyUtils {
}

function _original_Foo_setD(string memory s, uint8 k, int8 v) private {
uint8_to_int8.set(string_to_uint8_to_int8_S_514.get_lhs(d, s), k, v);
uint8_to_int8.set(string_to_uint8_to_int8_S_522.get_lhs(d, s), k, v);
}

function setE(uint k, uint[] memory v) public {
Expand Down
16 changes: 8 additions & 8 deletions test/samples/maps_sum.instrumented.sol
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ library uint256_to_int8 {
}
}

library string_to_uint256_to_int16_S_244 {
library string_to_uint256_to_int16_S_245 {
struct S {
mapping(string => uint256_to_int16.S) innerM;
string[] keys;
Expand Down Expand Up @@ -244,7 +244,7 @@ contract Foo is __scribble_ReentrancyUtils {

uint256_to_uint256.S internal a;
uint256_to_int8.S internal b;
string_to_uint256_to_int16_S_244.S internal c;
string_to_uint256_to_int16_S_245.S internal c;

constructor() {
uint256_to_uint256.set(a, 0, 10);
Expand Down Expand Up @@ -366,7 +366,7 @@ contract Foo is __scribble_ReentrancyUtils {
_v.forall_0 = true;
for (_v.i0 = 1; _v.i0 < c.keys.length; _v.i0++) {
_v.x0 = c.keys[_v.i0];
_v.forall_0 = string_to_uint256_to_int16_S_244.get(c, _v.x0).sum > 0;
_v.forall_0 = string_to_uint256_to_int16_S_245.get(c, _v.x0).sum > 0;
if (!_v.forall_0) break;
}
if (!(_v.forall_0)) {
Expand All @@ -377,7 +377,7 @@ contract Foo is __scribble_ReentrancyUtils {
}

function _original_Foo_setC(string memory k1, uint k2, int16 v) private {
uint256_to_int16.set(string_to_uint256_to_int16_S_244.get_lhs(c, k1), k2, v);
uint256_to_int16.set(string_to_uint256_to_int16_S_245.get_lhs(c, k1), k2, v);
}

function decC(string memory k1, uint k2) public {
Expand All @@ -387,7 +387,7 @@ contract Foo is __scribble_ReentrancyUtils {
_v.forall_1 = true;
for (_v.i1 = 1; _v.i1 < c.keys.length; _v.i1++) {
_v.x1 = c.keys[_v.i1];
_v.forall_1 = string_to_uint256_to_int16_S_244.get(c, _v.x1).sum > 0;
_v.forall_1 = string_to_uint256_to_int16_S_245.get(c, _v.x1).sum > 0;
if (!_v.forall_1) break;
}
if (!(_v.forall_1)) {
Expand All @@ -399,7 +399,7 @@ contract Foo is __scribble_ReentrancyUtils {

function _original_Foo_decC(string memory k1, uint k2) private {
unchecked {
uint256_to_int16.dec_unch(string_to_uint256_to_int16_S_244.get_lhs(c, k1), k2);
uint256_to_int16.dec_unch(string_to_uint256_to_int16_S_245.get_lhs(c, k1), k2);
}
}

Expand All @@ -410,7 +410,7 @@ contract Foo is __scribble_ReentrancyUtils {
_v.forall_2 = true;
for (_v.i2 = 1; _v.i2 < c.keys.length; _v.i2++) {
_v.x2 = c.keys[_v.i2];
_v.forall_2 = string_to_uint256_to_int16_S_244.get(c, _v.x2).sum > 0;
_v.forall_2 = string_to_uint256_to_int16_S_245.get(c, _v.x2).sum > 0;
if (!_v.forall_2) break;
}
if (!(_v.forall_2)) {
Expand All @@ -422,7 +422,7 @@ contract Foo is __scribble_ReentrancyUtils {

function _original_Foo_incC(string memory k1, uint k2) private {
unchecked {
uint256_to_int16.inc_unch(string_to_uint256_to_int16_S_244.get_lhs(c, k1), k2);
uint256_to_int16.inc_unch(string_to_uint256_to_int16_S_245.get_lhs(c, k1), k2);
}
}
}
Loading

0 comments on commit 93e6c0d

Please sign in to comment.