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

chore(precompiles): disable stake, unstake and moveStake #3010

Merged
merged 7 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
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,
fbac marked this conversation as resolved.
Show resolved Hide resolved
"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
Loading