Skip to content

Commit

Permalink
chore(precompiles): disable stake, unstake and moveStake (#3010)
Browse files Browse the repository at this point in the history
* GH3005: disable stake, unstake and moveStake

* explicitly check for failed tx when staking

* fix lint govet

* rebase

* fix duplicated import
  • Loading branch information
Francisco de Borja Aranda Castillejo authored Oct 17, 2024
1 parent 920779b commit 05c0769
Show file tree
Hide file tree
Showing 6 changed files with 1,055 additions and 859 deletions.
3 changes: 2 additions & 1 deletion cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
e2etests.TestPrecompilesPrototypeName,
e2etests.TestPrecompilesPrototypeThroughContractName,
e2etests.TestPrecompilesStakingName,
e2etests.TestPrecompilesStakingThroughContractName,
// Disabled until further notice, check https://github.com/zeta-chain/node/issues/3005.
// e2etests.TestPrecompilesStakingThroughContractName,
e2etests.TestPrecompilesBankName,
e2etests.TestPrecompilesBankFailName,
e2etests.TestPrecompilesBankThroughContractName,
Expand Down
2 changes: 1 addition & 1 deletion e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,7 @@ var AllE2ETests = []runner.E2ETest{
TestPrecompilesStakingName,
"test stateful precompiled contracts staking",
[]runner.ArgDefinition{},
TestPrecompilesStaking,
TestPrecompilesStakingIsDisabled,
),
runner.NewE2ETest(
TestPrecompilesStakingThroughContractName,
Expand Down
52 changes: 52 additions & 0 deletions e2e/e2etests/test_precompiles_staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,58 @@ import (
"github.com/zeta-chain/node/precompiles/staking"
)

func TestPrecompilesStakingIsDisabled(r *runner.E2ERunner, args []string) {
require.Len(r, args, 0, "No arguments expected")

stakingContract, err := staking.NewIStaking(staking.ContractAddress, r.ZEVMClient)
require.NoError(r, err, "Failed to create staking contract caller")

previousGasLimit := r.ZEVMAuth.GasLimit
r.ZEVMAuth.GasLimit = 10000000
defer func() {
r.ZEVMAuth.GasLimit = previousGasLimit
}()

validators, err := stakingContract.GetAllValidators(&bind.CallOpts{})
require.NoError(r, err)
require.GreaterOrEqual(r, len(validators), 2)

CleanValidatorDelegations(r, stakingContract, validators)

// shares are 0 for both validators at the start
sharesBeforeVal1, err := stakingContract.GetShares(&bind.CallOpts{}, r.ZEVMAuth.From, validators[0].OperatorAddress)
require.NoError(r, err)
require.Equal(r, int64(0), sharesBeforeVal1.Int64())

sharesBeforeVal2, err := stakingContract.GetShares(&bind.CallOpts{}, r.ZEVMAuth.From, validators[1].OperatorAddress)
require.NoError(r, err)
require.Equal(r, int64(0), sharesBeforeVal2.Int64())

// stake 3 to validator1
tx, err := stakingContract.Stake(r.ZEVMAuth, r.ZEVMAuth.From, validators[0].OperatorAddress, big.NewInt(3))
require.NoError(r, err)
receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
utils.RequiredTxFailed(r, receipt)

// unstake 1 from validator1
tx, err = stakingContract.Unstake(r.ZEVMAuth, r.ZEVMAuth.From, validators[0].OperatorAddress, big.NewInt(1))
require.NoError(r, err)
receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
utils.RequiredTxFailed(r, receipt)

// move 1 stake from validator1 to validator2
tx, err = stakingContract.MoveStake(
r.ZEVMAuth,
r.ZEVMAuth.From,
validators[0].OperatorAddress,
validators[1].OperatorAddress,
big.NewInt(1),
)
require.NoError(r, err)
receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
utils.RequiredTxFailed(r, receipt)
}

func TestPrecompilesStaking(r *runner.E2ERunner, args []string) {
require.Len(r, args, 0, "No arguments expected")

Expand Down
18 changes: 18 additions & 0 deletions precompiles/staking/staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,12 @@ func (c *Contract) Run(evm *vm.EVM, contract *vm.Contract, readOnly bool) ([]byt
}
return res, nil
case StakeMethodName:
// Disabled until further notice, check https://github.com/zeta-chain/node/issues/3005.
return nil, ptypes.ErrDisabledMethod{
Method: method.Name,
}

//nolint:govet
if readOnly {
return nil, ptypes.ErrWriteMethod{
Method: method.Name,
Expand All @@ -431,6 +437,12 @@ func (c *Contract) Run(evm *vm.EVM, contract *vm.Contract, readOnly bool) ([]byt
}
return res, nil
case UnstakeMethodName:
// Disabled until further notice, check https://github.com/zeta-chain/node/issues/3005.
return nil, ptypes.ErrDisabledMethod{
Method: method.Name,
}

//nolint:govet
if readOnly {
return nil, ptypes.ErrWriteMethod{
Method: method.Name,
Expand All @@ -447,6 +459,12 @@ func (c *Contract) Run(evm *vm.EVM, contract *vm.Contract, readOnly bool) ([]byt
}
return res, nil
case MoveStakeMethodName:
// Disabled until further notice, check https://github.com/zeta-chain/node/issues/3005.
return nil, ptypes.ErrDisabledMethod{
Method: method.Name,
}

//nolint:govet
if readOnly {
return nil, ptypes.ErrWriteMethod{
Method: method.Name,
Expand Down
Loading

0 comments on commit 05c0769

Please sign in to comment.