Skip to content

Commit 15407b9

Browse files
authored
Fix solhint warnings (#76)
1 parent 7be31ee commit 15407b9

16 files changed

+326
-292
lines changed

.prettierrc

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
{
88
"files": "*.sol",
99
"options": {
10-
"singleQuote": false,
11-
"quoteProps": "consistent"
10+
"singleQuote": false
1211
}
1312
}
1413
],

.solhint.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"extends": "solhint:recommended",
33
"rules": {
4-
"max-line-length": "off"
4+
"func-visibility": ["warn", {"ignoreConstructors": true}],
5+
"max-states-count": ["off"],
6+
"no-inline-assembly": "off"
57
}
68
}

.solhintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
contracts/test

contracts/interfaces/IEVMWriter.sol

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.9;
3+
4+
interface IEvmWriter {
5+
function setBalance(address acc, uint256 value) external;
6+
7+
function copyCode(address acc, address from) external;
8+
9+
function swapCode(address acc, address where) external;
10+
11+
function setStorage(address acc, bytes32 key, bytes32 value) external;
12+
13+
function incNonce(address acc, uint256 diff) external;
14+
}

contracts/sfc/Migrations.sol

+14-7
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,30 @@ pragma solidity ^0.8.9;
33

44
contract Migrations {
55
address public owner;
6-
uint public last_completed_migration;
6+
uint256 public lastCompletedMigration;
7+
8+
/**
9+
* @dev The caller is not the owner.
10+
*/
11+
error NotOwner();
712

813
constructor(address contractOwner) {
914
owner = contractOwner;
1015
}
1116

1217
modifier restricted() {
13-
require(msg.sender == owner, "Not the contract owner");
18+
if (msg.sender != owner) {
19+
revert NotOwner();
20+
}
1421
_;
1522
}
1623

17-
function setCompleted(uint completed) public restricted {
18-
last_completed_migration = completed;
24+
function setCompleted(uint256 completed) public restricted {
25+
lastCompletedMigration = completed;
1926
}
2027

21-
function upgrade(address new_address) public restricted {
22-
Migrations upgraded = Migrations(new_address);
23-
upgraded.setCompleted(last_completed_migration);
28+
function upgrade(address newAddress) public restricted {
29+
Migrations upgraded = Migrations(newAddress);
30+
upgraded.setCompleted(lastCompletedMigration);
2431
}
2532
}

contracts/sfc/NetworkInitializer.sol

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.9;
33

4-
import "./SFCI.sol";
5-
import "./NodeDriver.sol";
6-
import "./SFCLib.sol";
7-
import "./ConstantsManager.sol";
4+
import {SFCI} from "./SFCI.sol";
5+
import {NodeDriver, NodeDriverAuth} from "./NodeDriver.sol";
6+
import {ConstantsManager} from "./ConstantsManager.sol";
7+
import {Decimal} from "../common/Decimal.sol";
88

99
contract NetworkInitializer {
1010
// Initialize NodeDriverAuth, NodeDriver and SFC in one call to allow fewer genesis transactions

contracts/sfc/NodeDriver.sol

+5-239
Original file line numberDiff line numberDiff line change
@@ -1,235 +1,13 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity ^0.8.9;
33

4-
import "../common/Initializable.sol";
5-
import "../ownership/Ownable.sol";
6-
import "./SFCI.sol";
7-
8-
interface NodeDriverExecutable {
9-
function execute() external;
10-
}
11-
12-
contract NodeDriverAuth is Initializable, Ownable {
13-
SFCI internal sfc;
14-
NodeDriver internal driver;
15-
16-
// Initialize NodeDriverAuth, NodeDriver and SFC in one call to allow fewer genesis transactions
17-
function initialize(address payable _sfc, address _driver, address _owner) external initializer {
18-
Ownable.initialize(_owner);
19-
driver = NodeDriver(_driver);
20-
sfc = SFCI(_sfc);
21-
}
22-
23-
modifier onlySFC() {
24-
require(msg.sender == address(sfc), "caller is not the SFC contract");
25-
_;
26-
}
27-
28-
modifier onlyDriver() {
29-
require(msg.sender == address(driver), "caller is not the NodeDriver contract");
30-
_;
31-
}
32-
33-
function migrateTo(address newDriverAuth) external onlyOwner {
34-
driver.setBackend(newDriverAuth);
35-
}
36-
37-
function _execute(address executable, address newOwner, bytes32 selfCodeHash, bytes32 driverCodeHash) internal {
38-
_transferOwnership(executable);
39-
NodeDriverExecutable(executable).execute();
40-
_transferOwnership(newOwner);
41-
//require(driver.backend() == address(this), "ownership of driver is lost");
42-
require(_getCodeHash(address(this)) == selfCodeHash, "self code hash doesn't match");
43-
require(_getCodeHash(address(driver)) == driverCodeHash, "driver code hash doesn't match");
44-
}
45-
46-
function execute(address executable) external onlyOwner {
47-
_execute(executable, owner(), _getCodeHash(address(this)), _getCodeHash(address(driver)));
48-
}
49-
50-
function mutExecute(
51-
address executable,
52-
address newOwner,
53-
bytes32 selfCodeHash,
54-
bytes32 driverCodeHash
55-
) external onlyOwner {
56-
_execute(executable, newOwner, selfCodeHash, driverCodeHash);
57-
}
58-
59-
function incBalance(address acc, uint256 diff) external onlySFC {
60-
require(acc == address(sfc), "recipient is not the SFC contract");
61-
driver.setBalance(acc, address(acc).balance + diff);
62-
}
63-
64-
function upgradeCode(address acc, address from) external onlyOwner {
65-
require(isContract(acc) && isContract(from), "not a contract");
66-
driver.copyCode(acc, from);
67-
}
68-
69-
function copyCode(address acc, address from) external onlyOwner {
70-
driver.copyCode(acc, from);
71-
}
72-
73-
function incNonce(address acc, uint256 diff) external onlyOwner {
74-
driver.incNonce(acc, diff);
75-
}
76-
77-
function updateNetworkRules(bytes calldata diff) external onlyOwner {
78-
driver.updateNetworkRules(diff);
79-
}
80-
81-
function updateMinGasPrice(uint256 minGasPrice) external onlySFC {
82-
// prettier-ignore
83-
driver.updateNetworkRules(bytes(strConcat("{\"Economy\":{\"MinGasPrice\":", uint256ToStr(minGasPrice), "}}")));
84-
}
85-
86-
function updateNetworkVersion(uint256 version) external onlyOwner {
87-
driver.updateNetworkVersion(version);
88-
}
89-
90-
function advanceEpochs(uint256 num) external onlyOwner {
91-
driver.advanceEpochs(num);
92-
}
93-
94-
function updateValidatorWeight(uint256 validatorID, uint256 value) external onlySFC {
95-
driver.updateValidatorWeight(validatorID, value);
96-
}
97-
98-
function updateValidatorPubkey(uint256 validatorID, bytes calldata pubkey) external onlySFC {
99-
driver.updateValidatorPubkey(validatorID, pubkey);
100-
}
101-
102-
function setGenesisValidator(
103-
address _auth,
104-
uint256 validatorID,
105-
bytes calldata pubkey,
106-
uint256 status,
107-
uint256 createdEpoch,
108-
uint256 createdTime,
109-
uint256 deactivatedEpoch,
110-
uint256 deactivatedTime
111-
) external onlyDriver {
112-
sfc.setGenesisValidator(
113-
_auth,
114-
validatorID,
115-
pubkey,
116-
status,
117-
createdEpoch,
118-
createdTime,
119-
deactivatedEpoch,
120-
deactivatedTime
121-
);
122-
}
123-
124-
function setGenesisDelegation(
125-
address delegator,
126-
uint256 toValidatorID,
127-
uint256 stake,
128-
uint256 lockedStake,
129-
uint256 lockupFromEpoch,
130-
uint256 lockupEndTime,
131-
uint256 lockupDuration,
132-
uint256 earlyUnlockPenalty,
133-
uint256 rewards
134-
) external onlyDriver {
135-
sfc.setGenesisDelegation(
136-
delegator,
137-
toValidatorID,
138-
stake,
139-
lockedStake,
140-
lockupFromEpoch,
141-
lockupEndTime,
142-
lockupDuration,
143-
earlyUnlockPenalty,
144-
rewards
145-
);
146-
}
147-
148-
function deactivateValidator(uint256 validatorID, uint256 status) external onlyDriver {
149-
sfc.deactivateValidator(validatorID, status);
150-
}
151-
152-
function sealEpochValidators(uint256[] calldata nextValidatorIDs) external onlyDriver {
153-
sfc.sealEpochValidators(nextValidatorIDs);
154-
}
155-
156-
function sealEpoch(
157-
uint256[] calldata offlineTimes,
158-
uint256[] calldata offlineBlocks,
159-
uint256[] calldata uptimes,
160-
uint256[] calldata originatedTxsFee,
161-
uint256 usedGas
162-
) external onlyDriver {
163-
sfc.sealEpoch(offlineTimes, offlineBlocks, uptimes, originatedTxsFee, usedGas);
164-
}
165-
166-
function isContract(address account) internal view returns (bool) {
167-
uint256 size;
168-
// solhint-disable-next-line no-inline-assembly
169-
assembly {
170-
size := extcodesize(account)
171-
}
172-
return size > 0;
173-
}
174-
175-
function decimalsNum(uint256 num) internal pure returns (uint256) {
176-
uint decimals;
177-
while (num != 0) {
178-
decimals++;
179-
num /= 10;
180-
}
181-
return decimals;
182-
}
183-
184-
function uint256ToStr(uint256 num) internal pure returns (string memory) {
185-
if (num == 0) {
186-
return "0";
187-
}
188-
uint decimals = decimalsNum(num);
189-
bytes memory bstr = new bytes(decimals);
190-
uint strIdx = decimals - 1;
191-
while (num != 0) {
192-
bstr[strIdx] = bytes1(uint8(48 + (num % 10)));
193-
num /= 10;
194-
if (strIdx > 0) {
195-
strIdx--;
196-
}
197-
}
198-
return string(bstr);
199-
}
200-
201-
function strConcat(string memory _a, string memory _b, string memory _c) internal pure returns (string memory) {
202-
bytes memory _ba = bytes(_a);
203-
bytes memory _bb = bytes(_b);
204-
bytes memory _bc = bytes(_c);
205-
string memory abc = new string(_ba.length + _bb.length + _bc.length);
206-
bytes memory babc = bytes(abc);
207-
uint k = 0;
208-
uint i = 0;
209-
for (i = 0; i < _ba.length; i++) {
210-
babc[k++] = _ba[i];
211-
}
212-
for (i = 0; i < _bb.length; i++) {
213-
babc[k++] = _bb[i];
214-
}
215-
for (i = 0; i < _bc.length; i++) {
216-
babc[k++] = _bc[i];
217-
}
218-
return string(babc);
219-
}
220-
221-
function _getCodeHash(address addr) internal view returns (bytes32) {
222-
bytes32 codeHash;
223-
assembly {
224-
codeHash := extcodehash(addr)
225-
}
226-
return codeHash;
227-
}
228-
}
4+
import {Initializable} from "../common/Initializable.sol";
5+
import {NodeDriverAuth} from "./NodeDriverAuth.sol";
6+
import {IEvmWriter} from "../interfaces/IEVMWriter.sol";
2297

2308
contract NodeDriver is Initializable {
2319
NodeDriverAuth internal backend;
232-
EVMWriter internal evmWriter;
10+
IEvmWriter internal evmWriter;
23311

23412
event UpdatedBackend(address indexed backend);
23513

@@ -253,7 +31,7 @@ contract NodeDriver is Initializable {
25331
function initialize(address _backend, address _evmWriterAddress) external initializer {
25432
backend = NodeDriverAuth(_backend);
25533
emit UpdatedBackend(_backend);
256-
evmWriter = EVMWriter(_evmWriterAddress);
34+
evmWriter = IEvmWriter(_evmWriterAddress);
25735
}
25836

25937
function setBalance(address acc, uint256 value) external onlyBackend {
@@ -376,15 +154,3 @@ contract NodeDriver is Initializable {
376154
backend.sealEpoch(offlineTimes, offlineBlocks, uptimes, originatedTxsFee, usedGas);
377155
}
378156
}
379-
380-
interface EVMWriter {
381-
function setBalance(address acc, uint256 value) external;
382-
383-
function copyCode(address acc, address from) external;
384-
385-
function swapCode(address acc, address where) external;
386-
387-
function setStorage(address acc, bytes32 key, bytes32 value) external;
388-
389-
function incNonce(address acc, uint256 diff) external;
390-
}

0 commit comments

Comments
 (0)