Skip to content

Commit

Permalink
Using solc to compare bytecode on specific contracts (#461)
Browse files Browse the repository at this point in the history
* comparing bytecode of the contracts that change the AST to make decisions in the format

* throw on compile error

* renaming of variable
  • Loading branch information
Janther authored Apr 16, 2021
1 parent 3cf089b commit 36825d7
Show file tree
Hide file tree
Showing 23 changed files with 10,649 additions and 1,462 deletions.
8,663 changes: 7,217 additions & 1,446 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,26 @@
},
"devDependencies": {
"cross-env": "^7.0.3",
"eslint": "^7.23.0",
"eslint": "^7.24.0",
"eslint-config-airbnb-base": "^14.2.1",
"eslint-config-prettier": "^8.1.0",
"eslint-config-prettier": "^8.2.0",
"eslint-plugin-import": "^2.22.1",
"jest": "^26.6.3",
"jest-mock-now": "^1.3.0",
"jest-snapshot-serializer-ansi": "^1.0.0",
"jest-snapshot-serializer-raw": "^1.1.0",
"jest-watch-typeahead": "^0.6.1",
"outdent": "^0.8.0"
"jest-watch-typeahead": "^0.6.2",
"outdent": "^0.8.0",
"solc": "^0.8.3"
},
"dependencies": {
"@solidity-parser/parser": "^0.12.1",
"dir-to-object": "^2.0.0",
"emoji-regex": "^9.2.1",
"emoji-regex": "^9.2.2",
"escape-string-regexp": "^4.0.0",
"prettier": "^2.2.1",
"semver": "^7.3.5",
"solidity-comments-extractor": "^0.0.6",
"string-width": "^4.2.0"
"string-width": "^4.2.2"
}
}
7 changes: 7 additions & 0 deletions tests/HexLiteral/HexLiteral.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.3;

contract HexLiteral {
bytes8 hex1 = hex'DeadBeef';
bytes8 hex2 = hex"DeadBeef";
}
55 changes: 55 additions & 0 deletions tests/HexLiteral/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`HexLiteral.sol - {"singleQuote":false} format 1`] = `
====================================options=====================================
parsers: ["solidity-parse"]
printWidth: 80
singleQuote: false
| printWidth
=====================================input======================================
// SPDX-License-Identifier: MIT
pragma solidity 0.8.3;
contract HexLiteral {
bytes8 hex1 = hex'DeadBeef';
bytes8 hex2 = hex"DeadBeef";
}
=====================================output=====================================
// SPDX-License-Identifier: MIT
pragma solidity 0.8.3;
contract HexLiteral {
bytes8 hex1 = hex"DeadBeef";
bytes8 hex2 = hex"DeadBeef";
}
================================================================================
`;

exports[`HexLiteral.sol - {"singleQuote":true} format 1`] = `
====================================options=====================================
parsers: ["solidity-parse"]
printWidth: 80
singleQuote: true
| printWidth
=====================================input======================================
// SPDX-License-Identifier: MIT
pragma solidity 0.8.3;
contract HexLiteral {
bytes8 hex1 = hex'DeadBeef';
bytes8 hex2 = hex"DeadBeef";
}
=====================================output=====================================
// SPDX-License-Identifier: MIT
pragma solidity 0.8.3;
contract HexLiteral {
bytes8 hex1 = hex'DeadBeef';
bytes8 hex2 = hex'DeadBeef';
}
================================================================================
`;
2 changes: 2 additions & 0 deletions tests/HexLiteral/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
run_spec(__dirname, ['solidity-parse'], { singleQuote: true });
run_spec(__dirname, ['solidity-parse'], { singleQuote: false });
92 changes: 92 additions & 0 deletions tests/Parentheses/AddNoParentheses.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.3;

contract AddNoParentheses {
function addAdd(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a + b + c;
}

function addSub(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a + b - c;
}

function addMul(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a + b * c;
}

function addDiv(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a + b / c;
}

function addMod(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a + b % c;
}

function addExp(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a + b ** c;
}

function addShiftL(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a + b << c;
}

function addShiftR(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a + b >> c;
}

function addBitAnd(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a + b & c;
}

function addBitOr(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a + b | c;
}

function addBitXor(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a + b ^ c;
}
}
92 changes: 92 additions & 0 deletions tests/Parentheses/BitAndNoParentheses.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.3;

contract BitAndNoParentheses {
function bitAndAdd(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a & b + c;
}

function bitAndSub(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a & b - c;
}

function bitAndMul(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a & b * c;
}

function bitAndDiv(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a & b / c;
}

function bitAndMod(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a & b % c;
}

function bitAndExp(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a & b ** c;
}

function bitAndShiftL(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a & b << c;
}

function bitAndShiftR(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a & b >> c;
}

function bitAndBitAnd(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a & b & c;
}

function bitAndBitOr(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a & b | c;
}

function bitAndBitXor(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a & b ^ c;
}
}
92 changes: 92 additions & 0 deletions tests/Parentheses/BitOrNoParentheses.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.3;

contract BitOrNoParentheses {
function bitOrAdd(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a | b + c;
}

function bitOrSub(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a | b - c;
}

function bitOrMul(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a | b * c;
}

function bitOrDiv(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a | b / c;
}

function bitOrMod(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a | b % c;
}

function bitOrExp(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a | b ** c;
}

function bitOrShiftL(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a | b << c;
}

function bitOrShiftR(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a | b >> c;
}

function bitOrBitAnd(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a | b & c;
}

function bitOrBitOr(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a | b | c;
}

function bitOrBitXor(uint256 a, uint256 b, uint256 c)
public
pure
returns (uint256)
{
return a | b ^ c;
}
}
Loading

0 comments on commit 36825d7

Please sign in to comment.