Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved test cases and implementation
- Loading branch information
1 parent
1292516
commit 92d3b79
Showing
5 changed files
with
120 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
243 changes: 68 additions & 175 deletions
243
test/fixtures/security/contracts-with-free-functions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,176 +1,69 @@ | ||
// all contracts are made with two func-visibility errors | ||
const CONTRACTS_FREE_FUNCTIONS_ERRORS_2 = ` | ||
function freeAa() returns(bool) { | ||
return true; | ||
} | ||
contract A { | ||
// error here | ||
function functionPublicViewA() returns (uint256) { | ||
return 1; | ||
} | ||
} | ||
module.exports = [ | ||
` | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.4.4; | ||
import "hardhat/console.sol"; | ||
interface fufu { | ||
function intFunction() returns(bool); | ||
function intFunction() returns(uint256); | ||
} | ||
function freeAa() returns(bool) { | ||
return true; | ||
} | ||
contract A { | ||
uint256 public a; | ||
constructor() { | ||
a = 2; | ||
} | ||
function functionPublicViewA() returns (uint256) { | ||
if (freeAa()) return a; | ||
else return a+1; | ||
} | ||
function functionPublicPureA() public pure returns (bool) { | ||
return freeAa(); | ||
} | ||
} | ||
function freeBb() returns(bool) { | ||
return true; | ||
} | ||
contract B { | ||
uint256 public a; | ||
constructor() { | ||
a = 2; | ||
} | ||
function functionPublicViewB() returns (uint256) { | ||
if (freeBb()) return a; | ||
else return a+1; | ||
} | ||
function functionPublicPureB() public pure returns (bool) { | ||
return freeCc(); | ||
} | ||
} | ||
function freeCc() returns(bool) { | ||
return true; | ||
} | ||
`, | ||
` | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.4; | ||
import "hardhat/console.sol"; | ||
function freeAa() returns(bool) { | ||
return true; | ||
} | ||
function freeBb() returns(bool) { | ||
return true; | ||
} | ||
interface fufu { | ||
function intFunction() returns(bool); | ||
function intFunction() returns(uint256); | ||
} | ||
contract A { | ||
uint256 public a; | ||
constructor() { | ||
a = 2; | ||
} | ||
function functionPublicViewA() returns (uint256) { | ||
if (freeAa()) return a; | ||
else return a+1; | ||
} | ||
function functionPublicPureA() public pure returns (bool) { | ||
return freeBb(); | ||
} | ||
} | ||
function freeCc() returns(bool) { | ||
return true; | ||
} | ||
contract B { | ||
uint256 public a; | ||
constructor() { | ||
a = 2; | ||
} | ||
function functionPublicViewB() returns (uint256) { | ||
if (freeAa()) return a; | ||
else return a+1; | ||
} | ||
function functionPublicPureB() public pure returns (bool) { | ||
return freeCc(); | ||
} | ||
} | ||
`, | ||
` | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.4; | ||
function freeCc() returns(bool) { | ||
return true; | ||
} | ||
contract A { | ||
uint256 public a; | ||
constructor() { | ||
a = 2; | ||
} | ||
function functionExternal() returns (uint256) { | ||
if (freeCc()) return a; | ||
else return a+1; | ||
} | ||
function functionPublicViewA() returns (uint256) { | ||
if (freeCc()) return a; | ||
else return a+1; | ||
} | ||
function functionPublicPureA() public pure returns (bool) { | ||
return freeCc(); | ||
} | ||
} | ||
`, | ||
` | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.4; | ||
contract A { | ||
uint256 public a; | ||
constructor() { | ||
a = 2; | ||
} | ||
function functionExternal() returns (uint256) { | ||
if (freeCc()) return a; | ||
else return a+1; | ||
} | ||
function functionPublicViewA() returns (uint256) { | ||
if (freeCc()) return a; | ||
else return a+1; | ||
} | ||
function functionPublicPureA() public pure returns (bool) { | ||
return freeCc(); | ||
} | ||
} | ||
function freeCc() returns(bool) { | ||
return true; | ||
} | ||
`, | ||
] | ||
function freeBb() returns(bool) { | ||
return true; | ||
} | ||
contract B { | ||
// error here | ||
function functionPublicViewA() returns (uint256) { | ||
return 1; | ||
} | ||
function functionPublicPureB() internal pure returns (bool) { | ||
return true; | ||
} | ||
} | ||
` | ||
|
||
const CONTRACT_FREE_FUNCTIONS_ERRORS_1 = ` | ||
contract A { | ||
constructor() {} | ||
// error here | ||
function functionPublicViewA() returns (uint256) { | ||
return 1; | ||
} | ||
} | ||
function freeBb() returns(bool) { | ||
return true; | ||
} | ||
` | ||
|
||
const NOCONTRACT_FREE_FUNCTION_ERRORS_0 = ` | ||
// NO error here | ||
function functionPublicViewA() returns (uint256) { | ||
return 1; | ||
} | ||
` | ||
|
||
const CONTRACT_FREE_FUNCTIONS_ERRORS_0 = ` | ||
function freeBb() returns(bool) { | ||
return true; | ||
} | ||
contract A { | ||
constructor() {} | ||
// NO error here | ||
function functionPublicViewA() external returns (uint256) { | ||
return 1; | ||
} | ||
} | ||
` | ||
|
||
module.exports = { | ||
CONTRACTS_FREE_FUNCTIONS_ERRORS_2, | ||
CONTRACT_FREE_FUNCTIONS_ERRORS_1, | ||
NOCONTRACT_FREE_FUNCTION_ERRORS_0, | ||
CONTRACT_FREE_FUNCTIONS_ERRORS_0, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters