Skip to content

Commit

Permalink
fix: update slash logic to avoid malicious slash (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonberg1997 committed Dec 13, 2023
1 parent 5d9b19a commit a964f98
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 138 deletions.
28 changes: 14 additions & 14 deletions abi/slashindicator.abi
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
},
{
"type": "function",
"name": "INIT_MALICIOUS_VOTE_SLASH_SCOPE",
"name": "INIT_FELONY_SLASH_SCOPE",
"inputs": [],
"outputs": [
{
Expand Down Expand Up @@ -479,6 +479,19 @@
],
"stateMutability": "view"
},
{
"type": "function",
"name": "felonySlashScope",
"inputs": [],
"outputs": [
{
"name": "",
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "felonyThreshold",
Expand Down Expand Up @@ -630,19 +643,6 @@
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "maliciousVoteSlashScope",
"inputs": [],
"outputs": [
{
"name": "",
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "misdemeanorThreshold",
Expand Down
143 changes: 102 additions & 41 deletions abi/stakehub.abi
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
},
{
"type": "function",
"name": "BREATH_BLOCK_INTERVAL",
"name": "BREATHE_BLOCK_INTERVAL",
"inputs": [],
"outputs": [
{
Expand Down Expand Up @@ -136,6 +136,44 @@
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "consensusExpiration",
"inputs": [
{
"name": "",
"type": "address",
"internalType": "address"
}
],
"outputs": [
{
"name": "",
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "consensusToOperator",
"inputs": [
{
"name": "",
"type": "address",
"internalType": "address"
}
],
"outputs": [
{
"name": "",
"type": "address",
"internalType": "address"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "createValidator",
Expand Down Expand Up @@ -396,44 +434,6 @@
],
"stateMutability": "view"
},
{
"type": "function",
"name": "getOperatorAddressByConsensusAddress",
"inputs": [
{
"name": "consensusAddress",
"type": "address",
"internalType": "address"
}
],
"outputs": [
{
"name": "",
"type": "address",
"internalType": "address"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "getOperatorAddressByVoteAddress",
"inputs": [
{
"name": "voteAddress",
"type": "bytes",
"internalType": "bytes"
}
],
"outputs": [
{
"name": "",
"type": "address",
"internalType": "address"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "getValidatorBasicInfo",
Expand Down Expand Up @@ -667,7 +667,7 @@
"name": "maliciousVoteSlash",
"inputs": [
{
"name": "_voteAddr",
"name": "voteAddress",
"type": "bytes",
"internalType": "bytes"
}
Expand All @@ -688,6 +688,19 @@
],
"stateMutability": "view"
},
{
"type": "function",
"name": "maxFelonyBetweenBreatheBlock",
"inputs": [],
"outputs": [
{
"name": "",
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "minDelegationBNBChange",
Expand Down Expand Up @@ -888,6 +901,44 @@
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "voteExpiration",
"inputs": [
{
"name": "",
"type": "bytes",
"internalType": "bytes"
}
],
"outputs": [
{
"name": "",
"type": "uint256",
"internalType": "uint256"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "voteToOperator",
"inputs": [
{
"name": "",
"type": "bytes",
"internalType": "bytes"
}
],
"outputs": [
{
"name": "",
"type": "address",
"internalType": "address"
}
],
"stateMutability": "view"
},
{
"type": "event",
"name": "Claimed",
Expand Down Expand Up @@ -1276,6 +1327,11 @@
"name": "AlreadySlashed",
"inputs": []
},
{
"type": "error",
"name": "ConsensusAddressExpired",
"inputs": []
},
{
"type": "error",
"name": "DelegationAmountTooSmall",
Expand Down Expand Up @@ -1344,7 +1400,7 @@
},
{
"type": "error",
"name": "NoMoreFelonyToday",
"name": "NoMoreFelonyAllowed",
"inputs": []
},
{
Expand Down Expand Up @@ -1434,6 +1490,11 @@
"name": "ValidatorNotJailed",
"inputs": []
},
{
"type": "error",
"name": "VoteAddressExpired",
"inputs": []
},
{
"type": "error",
"name": "ZeroShares",
Expand Down
4 changes: 2 additions & 2 deletions contracts/BC_fusion/StakeCredit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ contract StakeCredit is System, Initializable, ReentrancyGuardUpgradeable, ERC20
* @notice only accept BNB from `StakeHub`
*/
receive() external payable onlyStakeHub {
uint256 index = block.timestamp / IStakeHub(STAKE_HUB_ADDR).BREATH_BLOCK_INTERVAL();
uint256 index = block.timestamp / IStakeHub(STAKE_HUB_ADDR).BREATHE_BLOCK_INTERVAL();
totalPooledBNBRecord[index] = totalPooledBNB;
rewardRecord[index] += msg.value;
totalPooledBNB += msg.value;
Expand Down Expand Up @@ -182,7 +182,7 @@ contract StakeCredit is System, Initializable, ReentrancyGuardUpgradeable, ERC20
uint256 _commission = (bnbAmount * uint256(commissionRate)) / COMMISSION_RATE_BASE;
uint256 _reward = bnbAmount - _commission;

uint256 index = block.timestamp / IStakeHub(STAKE_HUB_ADDR).BREATH_BLOCK_INTERVAL();
uint256 index = block.timestamp / IStakeHub(STAKE_HUB_ADDR).BREATHE_BLOCK_INTERVAL();
totalPooledBNBRecord[index] = totalPooledBNB;
rewardRecord[index] += _reward;
totalPooledBNB += _reward;
Expand Down
Loading

0 comments on commit a964f98

Please sign in to comment.