Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: clean deprecated code #593

Merged
merged 52 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
34a4be6
feat: clean deprecated code
cosinlink Aug 27, 2024
73ca43d
feat: clean deprecated code more
cosinlink Aug 27, 2024
e600faa
feat: recover init functions
cosinlink Aug 27, 2024
5cf936a
feat: remove unused code
cosinlink Aug 28, 2024
c6a2f85
feat: remove unused code in stakehub
cosinlink Aug 28, 2024
26663b0
feat: update genesis.json
cosinlink Aug 29, 2024
798904d
feat: remove unused code and add comments
cosinlink Aug 30, 2024
c98ae1d
feat: remove unused code
cosinlink Aug 30, 2024
73d3e7e
feat: remove unused code
cosinlink Aug 30, 2024
c96aec0
feat: add comments
cosinlink Aug 30, 2024
13ea43f
feat: update genesis.json
cosinlink Aug 30, 2024
c1592fb
fix: fix test after code clean up
cosinlink Aug 30, 2024
579bd70
feat: remove unused code
cosinlink Aug 30, 2024
bbc5f23
feat: remove unused code and imports
cosinlink Sep 2, 2024
0e96ece
feat: remove _legacyConsensusAddress and _legacyVoteAddress check
cosinlink Sep 3, 2024
7ed2991
fix: removed deprecated comment
cosinlink Sep 3, 2024
d1a8a56
fix: move events
cosinlink Sep 3, 2024
4db83b8
fix: move events
cosinlink Sep 3, 2024
246a073
feat: deprecate withdrawUnlockToken in TokenHub.sol
cosinlink Sep 3, 2024
23ab1e2
feat: remove unused constants
cosinlink Sep 3, 2024
7f893f5
feat: remove unused code
cosinlink Sep 3, 2024
543f311
feat: remove flattened folder
cosinlink Sep 3, 2024
71bfbc0
fix: fix genesis bytecode generate script and sync genesis.json
cosinlink Sep 3, 2024
f4b5ab3
fix: remove unused code
cosinlink Sep 3, 2024
798651e
feat: sync genesis.json
cosinlink Sep 3, 2024
48e79b2
feat: remove unused tests
cosinlink Sep 4, 2024
7709ada
feat: remove lint ci check
cosinlink Sep 4, 2024
cfd697a
feat: clean unused code in generate.py
pythonberg1997 Sep 5, 2024
0b0e394
feat: lint code and recover ci lint check
cosinlink Sep 5, 2024
348fe40
fix: modify vote slash code to avoid reentry
cosinlink Sep 5, 2024
7d172f2
Revert "fix: modify vote slash code to avoid reentry"
cosinlink Sep 5, 2024
08f7a1f
fix: recover claimMigrationFund in TokenHub
cosinlink Sep 6, 2024
3ad33b1
feat: sync genesis.json
cosinlink Sep 6, 2024
e0346f7
feat: add testnet genesis file
cosinlink Sep 8, 2024
e882dad
feat: add ci check bsc repo bytecode
cosinlink Sep 8, 2024
3cfa57b
chores: modify ci check
cosinlink Sep 8, 2024
64c8f7d
chores: modify ci check
cosinlink Sep 8, 2024
b4591cd
chores: test ci script
cosinlink Sep 8, 2024
8905cf1
chores: test ci script
cosinlink Sep 8, 2024
7e1fa4f
chores: test ci script
cosinlink Sep 8, 2024
0c5637a
chores: test ci script
cosinlink Sep 8, 2024
6cc7f2f
chores: test ci script
cosinlink Sep 8, 2024
5f57952
chores: test ci script
cosinlink Sep 8, 2024
10c1695
chores: test ci script
cosinlink Sep 8, 2024
d8e351f
chores: test ci script
cosinlink Sep 8, 2024
39255e8
chores: test ci script
cosinlink Sep 8, 2024
399bab6
chores: test ci script
cosinlink Sep 8, 2024
031dab5
chores: test ci script
cosinlink Sep 8, 2024
5d82720
chores: test ci script
cosinlink Sep 8, 2024
9132efb
feat: finish ci to check bsc hardfork bytecodes
cosinlink Sep 8, 2024
dd04573
fix: fix check bsc bytecode script
cosinlink Sep 8, 2024
9383bd9
feat: update dev genesis generate command
cosinlink Sep 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ jobs:
forge install --no-git --no-commit foundry-rs/[email protected]
forge --version

- name: Lint Check
run: |
npm run lint:check

- name: Build
run: |
forge build
Expand Down
392 changes: 29 additions & 363 deletions contracts/BSCValidatorSet.sol

Large diffs are not rendered by default.

49 changes: 4 additions & 45 deletions contracts/GovHub.sol
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
pragma solidity 0.6.4;

import "./System.sol";
import "./lib/0.6.x/BytesToTypes.sol";
import "./lib/0.6.x/Memory.sol";
import "./lib/0.6.x/BytesLib.sol";
import "./interface/0.6.x/IParamSubscriber.sol";
import "./interface/0.6.x/IApplication.sol";
import "./lib/0.6.x/RLPDecode.sol";
import "./lib/0.6.x/CmnPkg.sol";

contract GovHub is System, IApplication {
using RLPDecode for *;

uint8 public constant PARAM_UPDATE_MESSAGE_TYPE = 0;

uint32 public constant ERROR_TARGET_NOT_CONTRACT = 101;
uint32 public constant ERROR_TARGET_CONTRACT_FAIL = 102;

event failReasonWithStr(string message);
event failReasonWithBytes(bytes message);
event paramChange(string key, bytes value);
event paramChange(string key, bytes value); // @dev deprecated
unclezoro marked this conversation as resolved.
Show resolved Hide resolved

struct ParamChangePackage {
unclezoro marked this conversation as resolved.
Show resolved Hide resolved
string key;
Expand All @@ -31,26 +22,17 @@ contract GovHub is System, IApplication {
uint8,
bytes calldata msgBytes
) external override onlyCrossChainContract returns (bytes memory responsePayload) {
(ParamChangePackage memory proposal, bool success) = decodeSynPackage(msgBytes);
if (!success) {
return CmnPkg.encodeCommonAckPackage(ERROR_FAIL_DECODE);
}
uint32 resCode = notifyUpdates(proposal);
if (resCode == CODE_OK) {
return new bytes(0);
} else {
return CmnPkg.encodeCommonAckPackage(resCode);
}
revert("deprecated");
}

// should not happen
function handleAckPackage(uint8, bytes calldata) external override onlyCrossChainContract {
require(false, "receive unexpected ack package");
revert("deprecated");
}

// should not happen
function handleFailAckPackage(uint8, bytes calldata) external override onlyCrossChainContract {
require(false, "receive unexpected fail ack package");
revert("deprecated");
}

function updateParam(string calldata key, bytes calldata value, address target) external onlyGovernorTimelock {
Expand All @@ -73,27 +55,4 @@ contract GovHub is System, IApplication {
}
return CODE_OK;
}

//rlp encode & decode function
function decodeSynPackage(bytes memory msgBytes) internal pure returns (ParamChangePackage memory, bool) {
ParamChangePackage memory pkg;

RLPDecode.Iterator memory iter = msgBytes.toRLPItem().iterator();
bool success = false;
uint256 idx = 0;
while (iter.hasNext()) {
if (idx == 0) {
pkg.key = string(iter.next().toBytes());
} else if (idx == 1) {
pkg.value = iter.next().toBytes();
} else if (idx == 2) {
pkg.target = iter.next().toAddress();
success = true;
} else {
break;
}
++idx;
}
return (pkg, success);
}
}
54 changes: 11 additions & 43 deletions contracts/SlashIndicator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import "./interface/0.6.x/ISlashIndicator.sol";
import "./interface/0.6.x/IApplication.sol";
import "./interface/0.6.x/IBSCValidatorSet.sol";
import "./interface/0.6.x/IParamSubscriber.sol";
import "./interface/0.6.x/ICrossChain.sol";
import "./interface/0.6.x/ISystemReward.sol";
import "./interface/0.6.x/IStakeHub.sol";
import "./lib/0.6.x/CmnPkg.sol";
import "./lib/0.6.x/RLPEncode.sol";

contract SlashIndicator is ISlashIndicator, System, IParamSubscriber, IApplication {
Expand Down Expand Up @@ -46,16 +44,15 @@ contract SlashIndicator is ISlashIndicator, System, IParamSubscriber, IApplicati
uint256 public felonySlashScope;

event validatorSlashed(address indexed validator);
event maliciousVoteSlashed(bytes32 indexed voteAddrSlice);
event indicatorCleaned();
event paramChange(string key, bytes value);

event knownResponse(uint32 code);
event unKnownResponse(uint32 code);
event crashResponse();

event failedFelony(address indexed validator, uint256 slashCount, bytes failReason);

event maliciousVoteSlashed(bytes32 indexed voteAddrSlice); // @dev deprecated
event knownResponse(uint32 code); // @dev deprecated
event unKnownResponse(uint32 code); // @dev deprecated
event crashResponse(); // @dev deprecated

struct Indicator {
uint256 height;
uint256 count;
Expand Down Expand Up @@ -94,22 +91,15 @@ contract SlashIndicator is ISlashIndicator, System, IParamSubscriber, IApplicati
uint8,
bytes calldata
) external override onlyCrossChainContract onlyInit returns (bytes memory) {
require(false, "receive unexpected syn package");
revert("deprecated");
}

function handleAckPackage(uint8, bytes calldata msgBytes) external override onlyCrossChainContract onlyInit {
(CmnPkg.CommonAckPackage memory response, bool ok) = CmnPkg.decodeCommonAckPackage(msgBytes);
if (ok) {
emit knownResponse(response.code);
} else {
emit unKnownResponse(response.code);
}
return;
revert("deprecated");
}

function handleFailAckPackage(uint8, bytes calldata) external override onlyCrossChainContract onlyInit {
emit crashResponse();
return;
revert("deprecated");
}

/*----------------- External func -----------------*/
Expand All @@ -134,16 +124,7 @@ contract SlashIndicator is ISlashIndicator, System, IParamSubscriber, IApplicati
if (indicator.count % felonyThreshold == 0) {
indicator.count = 0;
IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).felony(validator);
if (IStakeHub(STAKE_HUB_ADDR).consensusToOperator(validator) != address(0)) {
_downtimeSlash(validator, indicator.count, false);
} else {
// send slash msg to bc if validator is not migrated
try ICrossChain(CROSS_CHAIN_CONTRACT_ADDR).sendSynPackage(
SLASH_CHANNELID, encodeSlashPackage(validator), 0
) { } catch (bytes memory reason) {
emit failedFelony(validator, indicator.count, reason);
}
}
_downtimeSlash(validator, indicator.count, false);
} else if (indicator.count % misdemeanorThreshold == 0) {
IBSCValidatorSet(VALIDATOR_CONTRACT_ADDR).misdemeanor(validator);
}
Expand Down Expand Up @@ -284,17 +265,7 @@ contract SlashIndicator is ISlashIndicator, System, IParamSubscriber, IApplicati
}
}

if (IStakeHub(STAKE_HUB_ADDR).voteToOperator(_evidence.voteAddr) != address(0)) {
IStakeHub(STAKE_HUB_ADDR).maliciousVoteSlash(_evidence.voteAddr);
} else {
// send slash msg to bc if the validator not migrated
ICrossChain(CROSS_CHAIN_CONTRACT_ADDR).sendSynPackage(
SLASH_CHANNELID, encodeVoteSlashPackage(_evidence.voteAddr), 0
);

bytes32 voteAddrSlice = BytesLib.toBytes32(_evidence.voteAddr, 0);
emit maliciousVoteSlashed(voteAddrSlice);
}
IStakeHub(STAKE_HUB_ADDR).maliciousVoteSlash(_evidence.voteAddr);
pythonberg1997 marked this conversation as resolved.
Show resolved Hide resolved
}

function submitDoubleSignEvidence(bytes memory header1, bytes memory header2) public onlyInit {
Expand Down Expand Up @@ -343,10 +314,7 @@ contract SlashIndicator is ISlashIndicator, System, IParamSubscriber, IApplicati
* @param validator Who will be jailed
*/
function sendFelonyPackage(address validator) external override(ISlashIndicator) onlyValidatorContract onlyInit {
try ICrossChain(CROSS_CHAIN_CONTRACT_ADDR).sendSynPackage(SLASH_CHANNELID, encodeSlashPackage(validator), 0) { }
catch (bytes memory reason) {
emit failedFelony(validator, 0, reason);
}
emit failedFelony(validator, 0, "deprecated");
}

function _verifyBLSSignature(VoteData memory vote, bytes memory voteAddr) internal view returns (bool) {
Expand Down
Loading
Loading