Skip to content

Commit 36825d7

Browse files
authored
Using solc to compare bytecode on specific contracts (#461)
* comparing bytecode of the contracts that change the AST to make decisions in the format * throw on compile error * renaming of variable
1 parent 3cf089b commit 36825d7

23 files changed

+10649
-1462
lines changed

package-lock.json

Lines changed: 7217 additions & 1446 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,26 @@
6262
},
6363
"devDependencies": {
6464
"cross-env": "^7.0.3",
65-
"eslint": "^7.23.0",
65+
"eslint": "^7.24.0",
6666
"eslint-config-airbnb-base": "^14.2.1",
67-
"eslint-config-prettier": "^8.1.0",
67+
"eslint-config-prettier": "^8.2.0",
6868
"eslint-plugin-import": "^2.22.1",
6969
"jest": "^26.6.3",
7070
"jest-mock-now": "^1.3.0",
7171
"jest-snapshot-serializer-ansi": "^1.0.0",
7272
"jest-snapshot-serializer-raw": "^1.1.0",
73-
"jest-watch-typeahead": "^0.6.1",
74-
"outdent": "^0.8.0"
73+
"jest-watch-typeahead": "^0.6.2",
74+
"outdent": "^0.8.0",
75+
"solc": "^0.8.3"
7576
},
7677
"dependencies": {
7778
"@solidity-parser/parser": "^0.12.1",
7879
"dir-to-object": "^2.0.0",
79-
"emoji-regex": "^9.2.1",
80+
"emoji-regex": "^9.2.2",
8081
"escape-string-regexp": "^4.0.0",
8182
"prettier": "^2.2.1",
8283
"semver": "^7.3.5",
8384
"solidity-comments-extractor": "^0.0.6",
84-
"string-width": "^4.2.0"
85+
"string-width": "^4.2.2"
8586
}
8687
}

tests/HexLiteral/HexLiteral.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.3;
3+
4+
contract HexLiteral {
5+
bytes8 hex1 = hex'DeadBeef';
6+
bytes8 hex2 = hex"DeadBeef";
7+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`HexLiteral.sol - {"singleQuote":false} format 1`] = `
4+
====================================options=====================================
5+
parsers: ["solidity-parse"]
6+
printWidth: 80
7+
singleQuote: false
8+
| printWidth
9+
=====================================input======================================
10+
// SPDX-License-Identifier: MIT
11+
pragma solidity 0.8.3;
12+
13+
contract HexLiteral {
14+
bytes8 hex1 = hex'DeadBeef';
15+
bytes8 hex2 = hex"DeadBeef";
16+
}
17+
18+
=====================================output=====================================
19+
// SPDX-License-Identifier: MIT
20+
pragma solidity 0.8.3;
21+
22+
contract HexLiteral {
23+
bytes8 hex1 = hex"DeadBeef";
24+
bytes8 hex2 = hex"DeadBeef";
25+
}
26+
27+
================================================================================
28+
`;
29+
30+
exports[`HexLiteral.sol - {"singleQuote":true} format 1`] = `
31+
====================================options=====================================
32+
parsers: ["solidity-parse"]
33+
printWidth: 80
34+
singleQuote: true
35+
| printWidth
36+
=====================================input======================================
37+
// SPDX-License-Identifier: MIT
38+
pragma solidity 0.8.3;
39+
40+
contract HexLiteral {
41+
bytes8 hex1 = hex'DeadBeef';
42+
bytes8 hex2 = hex"DeadBeef";
43+
}
44+
45+
=====================================output=====================================
46+
// SPDX-License-Identifier: MIT
47+
pragma solidity 0.8.3;
48+
49+
contract HexLiteral {
50+
bytes8 hex1 = hex'DeadBeef';
51+
bytes8 hex2 = hex'DeadBeef';
52+
}
53+
54+
================================================================================
55+
`;

tests/HexLiteral/jsfmt.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
run_spec(__dirname, ['solidity-parse'], { singleQuote: true });
2+
run_spec(__dirname, ['solidity-parse'], { singleQuote: false });
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.3;
3+
4+
contract AddNoParentheses {
5+
function addAdd(uint256 a, uint256 b, uint256 c)
6+
public
7+
pure
8+
returns (uint256)
9+
{
10+
return a + b + c;
11+
}
12+
13+
function addSub(uint256 a, uint256 b, uint256 c)
14+
public
15+
pure
16+
returns (uint256)
17+
{
18+
return a + b - c;
19+
}
20+
21+
function addMul(uint256 a, uint256 b, uint256 c)
22+
public
23+
pure
24+
returns (uint256)
25+
{
26+
return a + b * c;
27+
}
28+
29+
function addDiv(uint256 a, uint256 b, uint256 c)
30+
public
31+
pure
32+
returns (uint256)
33+
{
34+
return a + b / c;
35+
}
36+
37+
function addMod(uint256 a, uint256 b, uint256 c)
38+
public
39+
pure
40+
returns (uint256)
41+
{
42+
return a + b % c;
43+
}
44+
45+
function addExp(uint256 a, uint256 b, uint256 c)
46+
public
47+
pure
48+
returns (uint256)
49+
{
50+
return a + b ** c;
51+
}
52+
53+
function addShiftL(uint256 a, uint256 b, uint256 c)
54+
public
55+
pure
56+
returns (uint256)
57+
{
58+
return a + b << c;
59+
}
60+
61+
function addShiftR(uint256 a, uint256 b, uint256 c)
62+
public
63+
pure
64+
returns (uint256)
65+
{
66+
return a + b >> c;
67+
}
68+
69+
function addBitAnd(uint256 a, uint256 b, uint256 c)
70+
public
71+
pure
72+
returns (uint256)
73+
{
74+
return a + b & c;
75+
}
76+
77+
function addBitOr(uint256 a, uint256 b, uint256 c)
78+
public
79+
pure
80+
returns (uint256)
81+
{
82+
return a + b | c;
83+
}
84+
85+
function addBitXor(uint256 a, uint256 b, uint256 c)
86+
public
87+
pure
88+
returns (uint256)
89+
{
90+
return a + b ^ c;
91+
}
92+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.3;
3+
4+
contract BitAndNoParentheses {
5+
function bitAndAdd(uint256 a, uint256 b, uint256 c)
6+
public
7+
pure
8+
returns (uint256)
9+
{
10+
return a & b + c;
11+
}
12+
13+
function bitAndSub(uint256 a, uint256 b, uint256 c)
14+
public
15+
pure
16+
returns (uint256)
17+
{
18+
return a & b - c;
19+
}
20+
21+
function bitAndMul(uint256 a, uint256 b, uint256 c)
22+
public
23+
pure
24+
returns (uint256)
25+
{
26+
return a & b * c;
27+
}
28+
29+
function bitAndDiv(uint256 a, uint256 b, uint256 c)
30+
public
31+
pure
32+
returns (uint256)
33+
{
34+
return a & b / c;
35+
}
36+
37+
function bitAndMod(uint256 a, uint256 b, uint256 c)
38+
public
39+
pure
40+
returns (uint256)
41+
{
42+
return a & b % c;
43+
}
44+
45+
function bitAndExp(uint256 a, uint256 b, uint256 c)
46+
public
47+
pure
48+
returns (uint256)
49+
{
50+
return a & b ** c;
51+
}
52+
53+
function bitAndShiftL(uint256 a, uint256 b, uint256 c)
54+
public
55+
pure
56+
returns (uint256)
57+
{
58+
return a & b << c;
59+
}
60+
61+
function bitAndShiftR(uint256 a, uint256 b, uint256 c)
62+
public
63+
pure
64+
returns (uint256)
65+
{
66+
return a & b >> c;
67+
}
68+
69+
function bitAndBitAnd(uint256 a, uint256 b, uint256 c)
70+
public
71+
pure
72+
returns (uint256)
73+
{
74+
return a & b & c;
75+
}
76+
77+
function bitAndBitOr(uint256 a, uint256 b, uint256 c)
78+
public
79+
pure
80+
returns (uint256)
81+
{
82+
return a & b | c;
83+
}
84+
85+
function bitAndBitXor(uint256 a, uint256 b, uint256 c)
86+
public
87+
pure
88+
returns (uint256)
89+
{
90+
return a & b ^ c;
91+
}
92+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity 0.8.3;
3+
4+
contract BitOrNoParentheses {
5+
function bitOrAdd(uint256 a, uint256 b, uint256 c)
6+
public
7+
pure
8+
returns (uint256)
9+
{
10+
return a | b + c;
11+
}
12+
13+
function bitOrSub(uint256 a, uint256 b, uint256 c)
14+
public
15+
pure
16+
returns (uint256)
17+
{
18+
return a | b - c;
19+
}
20+
21+
function bitOrMul(uint256 a, uint256 b, uint256 c)
22+
public
23+
pure
24+
returns (uint256)
25+
{
26+
return a | b * c;
27+
}
28+
29+
function bitOrDiv(uint256 a, uint256 b, uint256 c)
30+
public
31+
pure
32+
returns (uint256)
33+
{
34+
return a | b / c;
35+
}
36+
37+
function bitOrMod(uint256 a, uint256 b, uint256 c)
38+
public
39+
pure
40+
returns (uint256)
41+
{
42+
return a | b % c;
43+
}
44+
45+
function bitOrExp(uint256 a, uint256 b, uint256 c)
46+
public
47+
pure
48+
returns (uint256)
49+
{
50+
return a | b ** c;
51+
}
52+
53+
function bitOrShiftL(uint256 a, uint256 b, uint256 c)
54+
public
55+
pure
56+
returns (uint256)
57+
{
58+
return a | b << c;
59+
}
60+
61+
function bitOrShiftR(uint256 a, uint256 b, uint256 c)
62+
public
63+
pure
64+
returns (uint256)
65+
{
66+
return a | b >> c;
67+
}
68+
69+
function bitOrBitAnd(uint256 a, uint256 b, uint256 c)
70+
public
71+
pure
72+
returns (uint256)
73+
{
74+
return a | b & c;
75+
}
76+
77+
function bitOrBitOr(uint256 a, uint256 b, uint256 c)
78+
public
79+
pure
80+
returns (uint256)
81+
{
82+
return a | b | c;
83+
}
84+
85+
function bitOrBitXor(uint256 a, uint256 b, uint256 c)
86+
public
87+
pure
88+
returns (uint256)
89+
{
90+
return a | b ^ c;
91+
}
92+
}

0 commit comments

Comments
 (0)