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(contracts): add withdraw account to validator #343

Merged
merged 7 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
35 changes: 33 additions & 2 deletions kroma-bindings/bindings/validatormanager.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion kroma-bindings/bindings/validatormanager_more.go

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion kroma-validator/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func main() {
app.Commands = cli.Commands{
{
Name: "deposit",
Usage: "Deposit ETH into ValidatorPool to be used as bond",
Usage: "DepositV1 ETH into ValidatorPool to be used as bond",
seolaoh marked this conversation as resolved.
Show resolved Hide resolved
Description: "This command will be deprecated in a future release of validator system V2. Please use the 'register' command to register as a validator.",
Flags: []cli.Flag{cmd.EthAmountFlag},
Action: cmd.Deposit,
Expand Down Expand Up @@ -64,6 +64,7 @@ func main() {
cmd.TokenAmountFlag,
cmd.CommissionRateFlag,
cmd.CommissionMaxChangeRateFlag,
cmd.WithdrawAccountFlag,
},
Action: cmd.Register,
},
Expand Down
3 changes: 2 additions & 1 deletion kroma-validator/cmd/validator/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,14 @@ func Register(ctx *cli.Context) error {

commissionRate := uint8(ctx.Uint64("commission-rate"))
commissionMaxChangeRate := uint8(ctx.Uint64("commission-max-change-rate"))
withdrawAccount := common.HexToAddress(ctx.String("withdraw-account"))
seolaoh marked this conversation as resolved.
Show resolved Hide resolved

valMgrAbi, err := bindings.ValidatorManagerMetaData.GetAbi()
if err != nil {
return fmt.Errorf("failed to get ValidatorPool ABI: %w", err)
seolaoh marked this conversation as resolved.
Show resolved Hide resolved
}

txData, err := valMgrAbi.Pack("registerValidator", assets, commissionRate, commissionMaxChangeRate)
txData, err := valMgrAbi.Pack("registerValidator", assets, commissionRate, commissionMaxChangeRate, withdrawAccount)
if err != nil {
return fmt.Errorf("failed to create register validator transaction data: %w", err)
}
Expand Down
6 changes: 6 additions & 0 deletions kroma-validator/cmd/validator/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ var CommissionMaxChangeRateFlag = &cli.Uint64Flag{
Usage: "The maximum changeable commission rate at once (in percentage). Maximum 100.",
Required: true,
}

var WithdrawAccountFlag = &cli.StringFlag{
Name: "withdraw-account",
Usage: "Address to withdraw deposited KRO",
seolaoh marked this conversation as resolved.
Show resolved Hide resolved
Required: true,
}
112 changes: 56 additions & 56 deletions packages/contracts/.gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
AssetManagerTest:test_constructor_largeSlashingRate_reverts() (gas: 56130)
AssetManagerTest:test_constructor_succeeds() (gas: 35234)
AssetManagerTest:test_delegateKghBatch_succeeds() (gas: 1020604)
AssetManagerTest:test_delegateKgh_succeeds() (gas: 432537)
AssetManagerTest:test_delegateKghBatch_succeeds() (gas: 1020627)
AssetManagerTest:test_delegateKgh_succeeds() (gas: 432560)
AssetManagerTest:test_delegateKgh_withoutValidatorDelegation_reverts() (gas: 81093)
AssetManagerTest:test_delegate_succeeds() (gas: 349644)
AssetManagerTest:test_delegate_succeeds() (gas: 349667)
AssetManagerTest:test_delegate_withoutValidatorDelegation_reverts() (gas: 26463)
AssetManagerTest:test_finalizeClaimValidatorReward_succeeds() (gas: 624862)
AssetManagerTest:test_finalizeClaimValidatorReward_succeeds() (gas: 624863)
AssetManagerTest:test_finalizeUndelegateKgh_noReward_succeeds() (gas: 532380)
AssetManagerTest:test_finalizeUndelegateKgh_rewardExists_succeeds() (gas: 757160)
AssetManagerTest:test_finalizeUndelegateKgh_rewardExists_succeeds() (gas: 757142)
AssetManagerTest:test_finalizeUndelegateKgh_undelegationPeriodNotElapsed_reverts() (gas: 511697)
AssetManagerTest:test_finalizeUndelegate_succeeds() (gas: 661058)
AssetManagerTest:test_finalizeUndelegate_undelegationPeriodNotElapsed_reverts() (gas: 697402)
AssetManagerTest:test_finalizeUndelegate_succeeds() (gas: 661077)
AssetManagerTest:test_finalizeUndelegate_undelegationPeriodNotElapsed_reverts() (gas: 697426)
AssetManagerTest:test_finalizeUndelegate_withNoPendingShares_reverts() (gas: 17874)
AssetManagerTest:test_finalizeUndelegate_zeroRequest_reverts() (gas: 701298)
AssetManagerTest:test_initClaimValidatorReward_succeeds() (gas: 647300)
AssetManagerTest:test_finalizeUndelegate_zeroRequest_reverts() (gas: 701322)
AssetManagerTest:test_initClaimValidatorReward_succeeds() (gas: 647301)
AssetManagerTest:test_initUndelegateKghBatch_noShares_reverts() (gas: 19046)
AssetManagerTest:test_initUndelegateKghBatch_succeeds() (gas: 9572845)
AssetManagerTest:test_initUndelegateKghBatch_succeeds() (gas: 9572864)
AssetManagerTest:test_initUndelegateKgh_noShares_reverts() (gas: 18002)
AssetManagerTest:test_initUndelegateKgh_succeeds() (gas: 804224)
AssetManagerTest:test_initUndelegate_exactAmount_succeeds() (gas: 751953)
AssetManagerTest:test_initUndelegate_exceedsMaxAmount_reverts() (gas: 526328)
AssetManagerTest:test_initUndelegateKgh_succeeds() (gas: 804248)
AssetManagerTest:test_initUndelegate_exactAmount_succeeds() (gas: 751931)
AssetManagerTest:test_initUndelegate_exceedsMaxAmount_reverts() (gas: 526306)
AssetManagerTest:test_initUndelegate_removedFromValidatorTree_succeeds() (gas: 518401)
AssetManagerTest:test_initUndelegate_self_succeeds() (gas: 639936)
AssetManagerTest:test_initUndelegate_succeeds() (gas: 693692)
AssetManagerTest:test_initUndelegate_self_succeeds() (gas: 639973)
AssetManagerTest:test_initUndelegate_succeeds() (gas: 693716)
ColosseumTest:test_bisect_cancelChallenge_senderNotChallenger_reverts() (gas: 2926854)
ColosseumTest:test_bisect_cancelChallenge_succeeds() (gas: 2711230)
ColosseumTest:test_bisect_finalizedOutput_reverts() (gas: 462505)
Expand Down Expand Up @@ -63,12 +63,12 @@ ColosseumTest:test_isInCreationPeriod_succeeds() (gas: 43125)
ColosseumTest:test_proveFault_cancelChallenge_succeeds() (gas: 2884832)
ColosseumTest:test_proveFault_finalizedOutput_reverts() (gas: 654060)
ColosseumTest:test_proveFault_succeeds() (gas: 2434097)
Colosseum_ValidatorSystemUpgrade_Test:test_challengerTimeout_callValidatorManager_succeeds() (gas: 506912)
Colosseum_ValidatorSystemUpgrade_Test:test_challengerTimeout_callValidatorManager_succeeds() (gas: 506895)
Colosseum_ValidatorSystemUpgrade_Test:test_createChallenge_callValidatorManager_succeeds() (gas: 428356)
Colosseum_ValidatorSystemUpgrade_Test:test_createChallenge_notSatisfyCondition_reverts() (gas: 92151)
Colosseum_ValidatorSystemUpgrade_Test:test_dismissChallenge_callValidatorManager_succeeds() (gas: 2528815)
Colosseum_ValidatorSystemUpgrade_Test:test_forceDeleteOutput_callValidatorManager_succeeds() (gas: 695017)
Colosseum_ValidatorSystemUpgrade_Test:test_proveFault_callValidatorManager_succeeds() (gas: 2512133)
Colosseum_ValidatorSystemUpgrade_Test:test_dismissChallenge_callValidatorManager_succeeds() (gas: 2528793)
Colosseum_ValidatorSystemUpgrade_Test:test_forceDeleteOutput_callValidatorManager_succeeds() (gas: 694995)
Colosseum_ValidatorSystemUpgrade_Test:test_proveFault_callValidatorManager_succeeds() (gas: 2512111)
CrossDomainMessenger_BaseGas_Test:test_baseGas_succeeds() (gas: 11763)
CrossDomainOwnable2_Test:test_onlyOwner_notMessenger_reverts() (gas: 8496)
CrossDomainOwnable2_Test:test_onlyOwner_notOwner2_reverts() (gas: 57515)
Expand Down Expand Up @@ -306,7 +306,7 @@ L2OutputOracleUpgradeable_Test:test_initializeProxy_alreadyInitialized_reverts()
L2OutputOracleUpgradeable_Test:test_upgrading_succeeds() (gas: 180651)
L2OutputOracle_ValidatorSystemUpgrade_Test:test_setNextFinalizeOutputIndex_succeeds() (gas: 41542)
L2OutputOracle_ValidatorSystemUpgrade_Test:test_setNextFinalizeOutputIndex_wrongCaller_reverts() (gas: 41164)
L2OutputOracle_ValidatorSystemUpgrade_Test:test_submitL2Output_upgradeValidatorSystem_succeeds() (gas: 380121)
L2OutputOracle_ValidatorSystemUpgrade_Test:test_submitL2Output_upgradeValidatorSystem_succeeds() (gas: 380099)
L2StandardBridge_BridgeERC20To_Test:test_bridgeERC20To_succeeds() (gas: 380870)
L2StandardBridge_BridgeERC20_Test:test_bridgeERC20_succeeds() (gas: 376942)
L2StandardBridge_Bridge_Test:test_finalizeBridgeERC20_succeeds() (gas: 83247)
Expand Down Expand Up @@ -418,50 +418,50 @@ UpgradeGovernorTest:test_queueProposal_succeeds() (gas: 280037)
UpgradeGovernorTest:test_voteProposal_overPeriod_reverts() (gas: 152674)
UpgradeGovernorTest:test_voteProposal_succeeds() (gas: 198054)
ValidatorManagerTest:test_activateValidator_alreadyActivated_reverts() (gas: 296937)
ValidatorManagerTest:test_activateValidator_exited_reverts() (gas: 349989)
ValidatorManagerTest:test_activateValidator_inJail_reverts() (gas: 1093776)
ValidatorManagerTest:test_activateValidator_exited_reverts() (gas: 350024)
ValidatorManagerTest:test_activateValidator_inJail_reverts() (gas: 1093909)
ValidatorManagerTest:test_activateValidator_notValidator_reverts() (gas: 19928)
ValidatorManagerTest:test_activateValidator_registered_reverts() (gas: 203893)
ValidatorManagerTest:test_activateValidator_succeeds() (gas: 384925)
ValidatorManagerTest:test_activatedValidatorTotalWeight_succeeds() (gas: 599866)
ValidatorManagerTest:test_afterSubmitL2Output_distributeReward_succeeds() (gas: 7368457)
ValidatorManagerTest:test_afterSubmitL2Output_resetNoSubmissionCount_succeeds() (gas: 799418)
ValidatorManagerTest:test_afterSubmitL2Output_senderNotL2OO_reverts() (gas: 15912)
ValidatorManagerTest:test_afterSubmitL2Output_tryJail_succeeds() (gas: 923135)
ValidatorManagerTest:test_afterSubmitL2Output_updatePriorityValidator_succeeds() (gas: 960719)
ValidatorManagerTest:test_changeCommissionRate_exited_reverts() (gas: 352020)
ValidatorManagerTest:test_changeCommissionRate_inJail_reverts() (gas: 933446)
ValidatorManagerTest:test_changeCommissionRate_largeChangeRate_reverts() (gas: 309260)
ValidatorManagerTest:test_changeCommissionRate_largeCommissionRate_reverts() (gas: 305198)
ValidatorManagerTest:test_changeCommissionRate_minChangeSecNotElapsed_reverts() (gas: 299616)
ValidatorManagerTest:test_changeCommissionRate_sameCommissionRate_reverts() (gas: 307061)
ValidatorManagerTest:test_changeCommissionRate_succeeds() (gas: 314950)
ValidatorManagerTest:test_changeCommissionRate_twice_succeeds() (gas: 334636)
ValidatorManagerTest:test_checkSubmissionEligibility_inJail_reverts() (gas: 937989)
ValidatorManagerTest:test_checkSubmissionEligibility_notSatisfyCondition_reverts() (gas: 22011)
ValidatorManagerTest:test_checkSubmissionEligibility_notSelected_reverts() (gas: 66714)
ValidatorManagerTest:test_checkSubmissionEligibility_priorityRound_succeeds() (gas: 300338)
ValidatorManagerTest:test_checkSubmissionEligibility_publicRound_inJail_reverts() (gas: 941252)
ValidatorManagerTest:test_checkSubmissionEligibility_publicRound_notSatisfyCondition_reverts() (gas: 71095)
ValidatorManagerTest:test_checkSubmissionEligibility_publicRound_succeeds() (gas: 349639)
ValidatorManagerTest:test_checkSubmissionEligibility_senderNotL2OO_reverts() (gas: 15584)
ValidatorManagerTest:test_constructor_smallMinActivateAmount_reverts() (gas: 62023)
ValidatorManagerTest:test_constructor_succeeds() (gas: 41675)
ValidatorManagerTest:test_activatedValidatorTotalWeight_succeeds() (gas: 600026)
ValidatorManagerTest:test_afterSubmitL2Output_distributeReward_succeeds() (gas: 7368492)
ValidatorManagerTest:test_afterSubmitL2Output_resetNoSubmissionCount_succeeds() (gas: 799528)
ValidatorManagerTest:test_afterSubmitL2Output_senderNotL2OO_reverts() (gas: 15890)
ValidatorManagerTest:test_afterSubmitL2Output_tryJail_succeeds() (gas: 923180)
ValidatorManagerTest:test_afterSubmitL2Output_updatePriorityValidator_succeeds() (gas: 960848)
ValidatorManagerTest:test_changeCommissionRate_exited_reverts() (gas: 352038)
ValidatorManagerTest:test_changeCommissionRate_inJail_reverts() (gas: 933469)
ValidatorManagerTest:test_changeCommissionRate_largeChangeRate_reverts() (gas: 309259)
ValidatorManagerTest:test_changeCommissionRate_largeCommissionRate_reverts() (gas: 305154)
ValidatorManagerTest:test_changeCommissionRate_minChangeSecNotElapsed_reverts() (gas: 299594)
ValidatorManagerTest:test_changeCommissionRate_sameCommissionRate_reverts() (gas: 307017)
ValidatorManagerTest:test_changeCommissionRate_succeeds() (gas: 314949)
ValidatorManagerTest:test_changeCommissionRate_twice_succeeds() (gas: 334634)
ValidatorManagerTest:test_checkSubmissionEligibility_inJail_reverts() (gas: 938122)
ValidatorManagerTest:test_checkSubmissionEligibility_notSatisfyCondition_reverts() (gas: 22076)
ValidatorManagerTest:test_checkSubmissionEligibility_notSelected_reverts() (gas: 66802)
ValidatorManagerTest:test_checkSubmissionEligibility_priorityRound_succeeds() (gas: 300403)
ValidatorManagerTest:test_checkSubmissionEligibility_publicRound_inJail_reverts() (gas: 941385)
ValidatorManagerTest:test_checkSubmissionEligibility_publicRound_notSatisfyCondition_reverts() (gas: 71183)
ValidatorManagerTest:test_checkSubmissionEligibility_publicRound_succeeds() (gas: 349727)
ValidatorManagerTest:test_checkSubmissionEligibility_senderNotL2OO_reverts() (gas: 15649)
ValidatorManagerTest:test_constructor_smallMinActivateAmount_reverts() (gas: 62041)
ValidatorManagerTest:test_constructor_succeeds() (gas: 41721)
ValidatorManagerTest:test_getStatus_registered_succeeds() (gas: 375788)
ValidatorManagerTest:test_registerValidator_active_succeeds() (gas: 318470)
ValidatorManagerTest:test_registerValidator_active_succeeds() (gas: 320438)
ValidatorManagerTest:test_registerValidator_alreadyInitiated_reverts() (gas: 320670)
ValidatorManagerTest:test_registerValidator_largeCommissionMaxChangeRate_reverts() (gas: 54630)
ValidatorManagerTest:test_registerValidator_largeCommissionRate_reverts() (gas: 54596)
ValidatorManagerTest:test_registerValidator_registered_succeeds() (gas: 215435)
ValidatorManagerTest:test_registerValidator_registered_succeeds() (gas: 215413)
ValidatorManagerTest:test_registerValidator_smallAsset_reverts() (gas: 54706)
ValidatorManagerTest:test_registerValidator_withdrawZeroAddr_reverts() (gas: 52581)
ValidatorManagerTest:test_slash_notColosseum_reverts() (gas: 26393)
ValidatorManagerTest:test_slash_succeeds() (gas: 14521374)
ValidatorManagerTest:test_tryUnjail_force_senderNotColosseum_reverts() (gas: 926995)
ValidatorManagerTest:test_tryUnjail_notInJail_reverts() (gas: 18397)
ValidatorManagerTest:test_tryUnjail_periodNotElapsed_reverts() (gas: 926040)
ValidatorManagerTest:test_tryUnjail_senderNotSelf_reverts() (gas: 925847)
ValidatorManagerTest:test_tryUnjail_succeeds() (gas: 1013114)
ValidatorManagerTest:test_slash_notColosseum_reverts() (gas: 26416)
ValidatorManagerTest:test_slash_succeeds() (gas: 14521532)
ValidatorManagerTest:test_tryUnjail_force_senderNotColosseum_reverts() (gas: 927018)
ValidatorManagerTest:test_tryUnjail_notInJail_reverts() (gas: 18375)
ValidatorManagerTest:test_tryUnjail_periodNotElapsed_reverts() (gas: 926063)
ValidatorManagerTest:test_tryUnjail_senderNotSelf_reverts() (gas: 925870)
ValidatorManagerTest:test_tryUnjail_succeeds() (gas: 1013093)
ValidatorPoolTest:test_addPendingBond_insufficientBalances_reverts() (gas: 301266)
ValidatorPoolTest:test_addPendingBond_noBond_reverts() (gas: 29957)
ValidatorPoolTest:test_addPendingBond_succeeds() (gas: 371202)
Expand Down Expand Up @@ -514,4 +514,4 @@ ZKMerkleTrie_Test:test_verifyInclustionProof_valid_2() (gas: 347207)
ZKMerkleTrie_Test:test_verifyInclustionProof_valid_3() (gas: 289078)
ZKMerkleTrie_Test:test_verifyInclustionProof_valid_4() (gas: 519350)
ZKMerkleTrie_Test:test_verifyInclustionProof_valid_5() (gas: 450449)
ZKMerkleTrie_Test:test_verifyInclustionProof_valid_6() (gas: 312798)
ZKMerkleTrie_Test:test_verifyInclustionProof_valid_6() (gas: 312798)
13 changes: 12 additions & 1 deletion packages/contracts/contracts/L1/ValidatorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ contract ValidatorManager is ISemver, IValidatorManager {
if (commissionMaxChangeRate > COMMISSION_RATE_DENOM)
revert MaxCommissionChangeRateExceeded();

if (withdrawAccount == address(0)) revert NotZeroAddress();
if (withdrawAccount == address(0)) revert ZeroAddress();

Validator storage validatorInfo = _validatorInfo[msg.sender];
validatorInfo.isInitiated = true;
Expand Down Expand Up @@ -358,6 +358,17 @@ contract ValidatorManager is ISemver, IValidatorManager {
return _validatorInfo[validator].commissionMaxChangeRate;
}

/**
* @notice Returns the address of withdraw account of given validator.
*
* @param validator Address of the validator.
*
* @return The address of withdraw account of given validator.
*/
function getWithdrawAccount(address validator) external view returns (address) {
return _validatorInfo[validator].withdrawAccount;
}

/**
* @notice Returns the number of activated validators.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ interface IValidatorManager {
/**
* @notice Reverts when the address is zero address.
*/
error NotZeroAddress();
error ZeroAddress();

/**
* @notice Reverts when try to change commission rate with same value as previous.
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/contracts/test/CommonTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ contract L2OutputOracle_Initializer is UpgradeGovernor_Initializer {
// Test data
address internal asserter = 0x000000000000000000000000000000000000aAaB;
address internal challenger = 0x000000000000000000000000000000000000AAaC;
address internal withdrawAcc = 0x000000000000000000000000000000000000AaaD;
address internal withdrawAcc = 0x000000000000000000000000000000000000AAaE;
uint256 initL1Time;

event OutputSubmitted(
Expand Down
3 changes: 2 additions & 1 deletion packages/contracts/contracts/test/ValidatorManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ contract ValidatorManagerTest is ValidatorSystemUpgrade_Initializer {
assertEq(assetMgr.totalKroAssets(trusted), assets);
assertEq(valMgr.getCommissionRate(trusted), commissionRate);
assertEq(valMgr.getCommissionMaxChangeRate(trusted), commissionMaxChangeRate);
assertEq(valMgr.getWithdrawAccount(trusted), withdrawAcc);
assertEq(mockValMgr.commissionRateChangedAt(trusted), block.timestamp);

assertTrue(valMgr.getStatus(trusted) == IValidatorManager.ValidatorStatus.ACTIVE);
Expand Down Expand Up @@ -286,7 +287,7 @@ contract ValidatorManagerTest is ValidatorSystemUpgrade_Initializer {

vm.startPrank(trusted);
assetToken.approve(address(assetMgr), uint256(assets));
vm.expectRevert(IValidatorManager.NotZeroAddress.selector);
vm.expectRevert(IValidatorManager.ZeroAddress.selector);
valMgr.registerValidator(assets, 10, 5, address(0));
}

Expand Down
Loading