Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/infrastructure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ on:
- chi1
- mia2
- mia3
default: 'lax'
default: 'lax1'

permissions:
contents: read
Expand Down
5 changes: 0 additions & 5 deletions contracts-abi/abi/PreconfManager.abi
Original file line number Diff line number Diff line change
Expand Up @@ -617,11 +617,6 @@
"name": "commitmentIndex",
"type": "bytes32",
"internalType": "bytes32"
},
{
"name": "residualBidPercentAfterDecay",
"type": "uint256",
"internalType": "uint256"
}
],
"outputs": [],
Expand Down
18 changes: 1 addition & 17 deletions contracts-abi/abi/ProviderRegistry.abi
Original file line number Diff line number Diff line change
Expand Up @@ -589,11 +589,6 @@
"type": "function",
"name": "slash",
"inputs": [
{
"name": "amt",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "slashAmt",
"type": "uint256",
Expand All @@ -608,11 +603,6 @@
"name": "bidder",
"type": "address",
"internalType": "address payable"
},
{
"name": "residualBidPercentAfterDecay",
"type": "uint256",
"internalType": "uint256"
}
],
"outputs": [],
Expand Down Expand Up @@ -895,20 +885,14 @@
"indexed": false,
"internalType": "uint256"
},
{
"name": "residualAmount",
"type": "uint256",
"indexed": false,
"internalType": "uint256"
},
{
"name": "penaltyFee",
"type": "uint256",
"indexed": false,
"internalType": "uint256"
},
{
"name": "slashAmt",
"name": "bidderPortion",
"type": "uint256",
"indexed": false,
"internalType": "uint256"
Expand Down
26 changes: 13 additions & 13 deletions contracts-abi/clients/PreconfManager/PreconfManager.go

Large diffs are not rendered by default.

49 changes: 24 additions & 25 deletions contracts-abi/clients/ProviderRegistry/ProviderRegistry.go

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions contracts/contracts/core/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ contract Oracle is OracleStorage, IOracle, Ownable2StepUpgradeable, UUPSUpgradea
) private {
if (isSlash) {
_preconfManager.initiateSlash(
commitmentIndex,
residualBidPercentAfterDecay
commitmentIndex
);
} else {
_preconfManager.initiateReward(
Expand Down
8 changes: 2 additions & 6 deletions contracts/contracts/core/PreconfManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,9 @@ contract PreconfManager is
/**
* @dev Initiate a slash for a commitment.
* @param commitmentIndex The hash of the commitment to be slashed.
* @param residualBidPercentAfterDecay The residual bid percent after decay.
*/
function initiateSlash(
bytes32 commitmentIndex,
uint256 residualBidPercentAfterDecay
bytes32 commitmentIndex
) public onlyOracleContract whenNotPaused {
OpenedCommitment storage commitment = openedCommitments[
commitmentIndex
Expand All @@ -390,11 +388,9 @@ contract PreconfManager is
--commitmentsCount[commitment.committer];

providerRegistry.slash(
commitment.bidAmt,
commitment.slashAmt,
commitment.committer,
payable(commitment.bidder),
residualBidPercentAfterDecay
payable(commitment.bidder)
);

bidderRegistry.unlockFunds(commitment.committer, commitment.commitmentDigest);
Expand Down
16 changes: 4 additions & 12 deletions contracts/contracts/core/ProviderRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -99,34 +99,26 @@ contract ProviderRegistry is
* @dev Slash funds from the provider and send the slashed amount to the bidder.
* @dev reenterancy not necessary but still putting here for precaution.
* @dev Note we slash the funds taking into account the residual bid percent after decay.
* @param amt The amount of bid to slash from the provider's stake .
* @param slashAmt The amount to slash from the provider's stake.
* @param provider The address of the provider.
* @param bidder The address to transfer the slashed funds to.
* @param residualBidPercentAfterDecay The residual bid percent after decay.
*/
function slash(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most important change in this PR is here

uint256 amt,
uint256 slashAmt,
address provider,
address payable bidder,
uint256 residualBidPercentAfterDecay
address payable bidder
) external nonReentrant onlyPreconfManager whenNotPaused {
uint256 residualAmt = (amt * residualBidPercentAfterDecay) /
ONE_HUNDRED_PERCENT;

uint256 penaltyFee = (residualAmt * feePercent) / ONE_HUNDRED_PERCENT;
uint256 bidderPortion = residualAmt + slashAmt;
uint256 penaltyFee = (slashAmt * feePercent) / ONE_HUNDRED_PERCENT;
uint256 bidderPortion = slashAmt;
uint256 totalSlash = bidderPortion + penaltyFee;
uint256 providerStake = providerStakes[provider];

if (providerStake < totalSlash) {
emit InsufficientFundsToSlash(
provider,
providerStake,
residualAmt,
penaltyFee,
slashAmt
bidderPortion
);

uint256 leftover = providerStake;
Expand Down
4 changes: 1 addition & 3 deletions contracts/contracts/interfaces/IPreconfManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,9 @@ interface IPreconfManager {
/**
* @dev Initiates a slash for a commitment.
* @param commitmentIndex The hash of the commitment to be slashed.
* @param residualBidPercentAfterDecay The residual bid percent after decay.
*/
function initiateSlash(
bytes32 commitmentIndex,
uint256 residualBidPercentAfterDecay
bytes32 commitmentIndex
) external;

/**
Expand Down
7 changes: 2 additions & 5 deletions contracts/contracts/interfaces/IProviderRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ interface IProviderRegistry {
event InsufficientFundsToSlash(
address indexed provider,
uint256 providerStake,
uint256 residualAmount,
uint256 penaltyFee,
uint256 slashAmt
uint256 bidderPortion
);

/// @dev Event emitted when transfer to bidder fails
Expand Down Expand Up @@ -80,11 +79,9 @@ interface IProviderRegistry {
function stake() external payable;

function slash(
uint256 amt,
uint256 slashAmt,
address provider,
address payable bidder,
uint256 residualBidPercentAfterDecay
address payable bidder
) external;

function addVerifiedBLSKey(bytes calldata blsPublicKey, bytes calldata signature) external;
Expand Down
15 changes: 8 additions & 7 deletions contracts/test/core/OracleTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ contract OracleTest is Test {
memory revertingTxHashes = "0x6d9c53ad81249775f8c082b11ac293b2e19194ff791bd1c4fd37683310e90d12";
uint64 blockNumber = 12;
uint64 bid = 200;
uint256 slashAmt = 0;
uint256 slashAmt = 200;
(address bidder, uint256 bidderPk) = makeAddrAndKey("alice");
(address provider, uint256 providerPk) = makeAddrAndKey("kartik");

Expand Down Expand Up @@ -308,8 +308,8 @@ contract OracleTest is Test {

// Verify the provider’s stake decreased appropriately.
assertEq(
providerRegistry.getProviderStake(provider) + ((bid * 55) / 100),
250 ether
providerRegistry.getProviderStake(provider),
250 ether - slashAmt - slashAmt / 10 // provider loses: slashAmt + 10%*slashAmt, see feePercent above
);
}

Expand All @@ -322,7 +322,7 @@ contract OracleTest is Test {
memory revertingTxHashes = "0x6d9c53ad81249775f8c082b11ac293b2e19194ff791bd1c4fd37683310e90d12";
uint64 blockNumber = 12;
uint64 bid = 100;
uint256 slashAmt = 0;
uint256 slashAmt = 150;
(address bidder, uint256 bidderPk) = makeAddrAndKey("alice");
(address provider, uint256 providerPk) = makeAddrAndKey("kartik");

Expand Down Expand Up @@ -395,7 +395,7 @@ contract OracleTest is Test {

assertEq(
providerRegistry.getProviderStake(provider),
250 ether - ((bid * 110) / 100)
250 ether - slashAmt - slashAmt / 10 // single slash
);
assertEq(
bidderRegistry.getProviderAmount(provider),
Expand All @@ -418,7 +418,7 @@ contract OracleTest is Test {
memory revertingTxHashes = "0x6d9c53ad81249775f8c082b11ac293b2e19194ff791bd1c4fd37683310e90d12";
uint64 blockNumber = 201;
uint64 bid = 5;
uint256 slashAmt = 0;
uint256 slashAmt = 20;
(address bidder, uint256 bidderPk) = makeAddrAndKey("alice");
(address provider, uint256 providerPk) = makeAddrAndKey("kartik");

Expand Down Expand Up @@ -533,9 +533,10 @@ contract OracleTest is Test {
bidderRegistry.ONE_HUNDRED_PERCENT()
);
vm.stopPrank();
uint256 amountLostPerSlash = slashAmt + slashAmt / 10; // slashAmt + 10%*slashAmt, see feePercent above
assertEq(
providerRegistry.getProviderStake(provider),
250 ether - bid * 4
250 ether - amountLostPerSlash * 4
);
assertEq(bidderRegistry.getProviderAmount(provider), 0);
}
Expand Down
9 changes: 4 additions & 5 deletions contracts/test/core/PreconfManagerTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ contract PreconfManagerTest is Test {

_testCommitmentAliceBob = TestCommitment(
2,
0,
3, // slashAmt
2,
"0xkartik",
"0xkartik",
Expand Down Expand Up @@ -819,10 +819,9 @@ contract PreconfManagerTest is Test {
_testCommitmentAliceBob.zkProof,
_testCommitmentAliceBob.bidOptions
);
uint256 oneHundredPercent = providerRegistry.ONE_HUNDRED_PERCENT();

vm.prank(oracleContract);
preconfManager.initiateSlash(index, oneHundredPercent);
preconfManager.initiateSlash(index);

(, isSettled, , , , , , , , , , , , ) = preconfManager
.openedCommitments(index);
Expand All @@ -836,8 +835,8 @@ contract PreconfManagerTest is Test {
assertEq(bidderRegistry.providerAmount(committer), 0 ether);
assertEq(
bidder.balance,
3 ether + _testCommitmentAliceBob.bidAmt + 2
); // +2 is the slashed funds from provider
3 ether + _testCommitmentAliceBob.bidAmt + 3
); // +3 is the slashed funds from provider
}
// commitmentDigest value is internal to contract and not asserted
}
Expand Down
Loading
Loading