Skip to content

Commit

Permalink
Merge branch 'develop' into fix-tss-key-voting-hash-collision
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD authored Sep 13, 2024
2 parents 858fb3d + 19c929c commit b4b1421
Show file tree
Hide file tree
Showing 36 changed files with 2,495 additions and 253 deletions.
5 changes: 4 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* [2788](https://github.com/zeta-chain/node/pull/2788) - add common importable zetacored rpc package
* [2784](https://github.com/zeta-chain/node/pull/2784) - staking precompiled contract
* [2795](https://github.com/zeta-chain/node/pull/2795) - support restricted address in Solana
* [2861](https://github.com/zeta-chain/node/pull/2861) - emit events from staking precompile

### Refactor

Expand All @@ -33,13 +34,15 @@
* [2726](https://github.com/zeta-chain/node/pull/2726) - add e2e tests for deposit and call, deposit and revert
* [2703](https://github.com/zeta-chain/node/pull/2703) - add e2e tests for stateful precompiled contracts
* [2763](https://github.com/zeta-chain/node/pull/2763) - add V2 contracts migration test
* [2830] (https://github.com/zeta-chain/node/pull/2830) - extend staking precompile tests
* [2830](https://github.com/zeta-chain/node/pull/2830) - extend staking precompile tests
* [2867](https://github.com/zeta-chain/node/pull/2867) - skip precompiles test for tss migration

### Fixes

* [2654](https://github.com/zeta-chain/node/pull/2654) - add validation for authorization list in when validating genesis state for authorization module
* [2674](https://github.com/zeta-chain/node/pull/2674) - allow operators to vote on ballots associated with discarded keygen without affecting the status of the current keygen.
* [2672](https://github.com/zeta-chain/node/pull/2672) - check observer set for duplicates when adding a new observer or updating an existing one
* [2735](https://github.com/zeta-chain/node/pull/2735) - fix the outbound tracker blocking confirmation and outbound processing on EVM chains by locally index outbound txs in zetaclient
* [2787](https://github.com/zeta-chain/node/pull/2787) - ask for 3 accounts (signer, pda, system_program) on solana gateway deposit
* [2944](https://github.com/zeta-chain/node/pull/2844) - add tsspubkey to index for tss keygen voting
* [2842](https://github.com/zeta-chain/node/pull/2842) - fix: move interval assignment out of cctx loop in EVM outbound tx scheduler
Expand Down
9 changes: 0 additions & 9 deletions cmd/zetae2e/local/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ import (
"fmt"
"path/filepath"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/spf13/cobra"

"github.com/zeta-chain/node/app"
"github.com/zeta-chain/node/e2e/config"
)

Expand All @@ -25,10 +23,3 @@ func GetConfig(cmd *cobra.Command) (config.Config, error) {

return config.ReadConfig(configFile)
}

// setCosmosConfig set account prefix to zeta
func setCosmosConfig() {
cosmosConf := sdk.GetConfig()
cosmosConf.SetBech32PrefixForAccount(app.Bech32PrefixAccAddr, app.Bech32PrefixAccPub)
cosmosConf.Seal()
}
4 changes: 2 additions & 2 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/spf13/cobra"
"golang.org/x/sync/errgroup"

"github.com/zeta-chain/node/app"
zetae2econfig "github.com/zeta-chain/node/cmd/zetae2e/config"
"github.com/zeta-chain/node/e2e/config"
"github.com/zeta-chain/node/e2e/e2etests"
Expand Down Expand Up @@ -143,8 +144,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
noError(utils.WaitForBlockHeight(ctx, waitForHeight, conf.RPCs.ZetaCoreRPC, logger))
}

// set account prefix to zeta
setCosmosConfig()
app.SetConfig()

zetaTxServer, err := txserver.NewZetaTxServer(
conf.RPCs.ZetaCoreRPC,
Expand Down
2 changes: 1 addition & 1 deletion contrib/localnet/orchestrator/start-zetae2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ if [ "$LOCALNET_MODE" == "tss-migrate" ]; then
echo "waiting 10 seconds for node to restart"
sleep 10

zetae2e local --skip-setup --config deployed.yml --skip-bitcoin-setup --light --skip-header-proof
zetae2e local --skip-setup --config deployed.yml --skip-bitcoin-setup --light --skip-header-proof --skip-precompiles
ZETAE2E_EXIT_CODE=$?
if [ $ZETAE2E_EXIT_CODE -eq 0 ]; then
echo "E2E passed after migration"
Expand Down
81 changes: 81 additions & 0 deletions e2e/contracts/teststaking/TestStaking.abi
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,87 @@
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "staker",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "validatorSrc",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "validatorDst",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "MoveStake",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "staker",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "validator",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "Stake",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "staker",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "validator",
"type": "address"
},
{
"indexed": false,
"internalType": "uint256",
"name": "amount",
"type": "uint256"
}
],
"name": "Unstake",
"type": "event"
},
{
"stateMutability": "payable",
"type": "fallback"
Expand Down
2 changes: 1 addition & 1 deletion e2e/contracts/teststaking/TestStaking.bin

Large diffs are not rendered by default.

475 changes: 473 additions & 2 deletions e2e/contracts/teststaking/TestStaking.go

Large diffs are not rendered by default.

83 changes: 82 additions & 1 deletion e2e/contracts/teststaking/TestStaking.json

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions e2e/contracts/teststaking/TestStaking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@ interface WZETA {

// @dev Purpose of this contract is to call staking precompile
contract TestStaking {
event Stake(
address indexed staker,
address indexed validator,
uint256 amount
);

event Unstake(
address indexed staker,
address indexed validator,
uint256 amount
);

event MoveStake(
address indexed staker,
address indexed validatorSrc,
address indexed validatorDst,
uint256 amount
);

IStaking staking = IStaking(0x0000000000000000000000000000000000000066);
WZETA wzeta;
address owner;
Expand Down
42 changes: 38 additions & 4 deletions e2e/e2etests/test_precompiles_staking_through_contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/node/cmd/zetacored/config"
Expand Down Expand Up @@ -99,7 +100,16 @@ func TestPrecompilesStakingThroughContract(r *runner.E2ERunner, args []string) {
// stake 1 to validator1 using testStaking smart contract without smart contract state update
tx, err = testStaking.Stake(r.ZEVMAuth, testStakingAddr, validators[0].OperatorAddress, big.NewInt(1))
require.NoError(r, err)
utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
receipt := utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)

// check that stake event was emitted
stakeEvent, err := testStaking.ParseStake(*receipt.Logs[0])
require.NoError(r, err)
expectedValAddr, err := sdk.ValAddressFromBech32(validators[0].OperatorAddress)
require.NoError(r, err)
require.Equal(r, big.NewInt(1).Uint64(), stakeEvent.Amount.Uint64())
require.Equal(r, common.BytesToAddress(expectedValAddr.Bytes()), stakeEvent.Validator)
require.Equal(r, testStakingAddr, stakeEvent.Staker)

// check that bank balance is reduced by 1
balanceAfterStake, err := r.BankClient.Balance(r.Ctx, &banktypes.QueryBalanceRequest{
Expand All @@ -117,7 +127,14 @@ func TestPrecompilesStakingThroughContract(r *runner.E2ERunner, args []string) {
big.NewInt(2),
)
require.NoError(r, err)
utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)

// check that stake event was emitted
stakeEvent, err = testStaking.ParseStake(*receipt.Logs[0])
require.NoError(r, err)
require.Equal(r, big.NewInt(2).Uint64(), stakeEvent.Amount.Uint64())
require.Equal(r, common.BytesToAddress(expectedValAddr.Bytes()), stakeEvent.Validator)
require.Equal(r, testStakingAddr, stakeEvent.Staker)

// check that bank balance is reduced by 2 more, 3 in total
balanceAfterStake, err = r.BankClient.Balance(r.Ctx, &banktypes.QueryBalanceRequest{
Expand Down Expand Up @@ -148,7 +165,14 @@ func TestPrecompilesStakingThroughContract(r *runner.E2ERunner, args []string) {
// unstake 1 from validator1
tx, err = testStaking.Unstake(r.ZEVMAuth, testStakingAddr, validators[0].OperatorAddress, big.NewInt(1))
require.NoError(r, err)
utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)

// check that unstake event was emitted
unstakeEvent, err := testStaking.ParseUnstake(*receipt.Logs[0])
require.NoError(r, err)
require.Equal(r, big.NewInt(1).Uint64(), unstakeEvent.Amount.Uint64())
require.Equal(r, common.BytesToAddress(expectedValAddr.Bytes()), unstakeEvent.Validator)
require.Equal(r, testStakingAddr, unstakeEvent.Staker)

// check shares are set to 2
sharesAfterVal1, err = testStaking.GetShares(&bind.CallOpts{}, testStakingAddr, validators[0].OperatorAddress)
Expand All @@ -172,7 +196,17 @@ func TestPrecompilesStakingThroughContract(r *runner.E2ERunner, args []string) {
big.NewInt(1),
)
require.NoError(r, err)
utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)
receipt = utils.MustWaitForTxReceipt(r.Ctx, r.ZEVMClient, tx, r.Logger, r.ReceiptTimeout)

// check that moveStake event was emitted
moveStake, err := testStaking.ParseMoveStake(*receipt.Logs[0])
require.NoError(r, err)
require.Equal(r, big.NewInt(1).Uint64(), moveStake.Amount.Uint64())
expectedValDstAddr, err := sdk.ValAddressFromBech32(validators[1].OperatorAddress)
require.NoError(r, err)
require.Equal(r, common.BytesToAddress(expectedValAddr.Bytes()), moveStake.ValidatorSrc)
require.Equal(r, common.BytesToAddress(expectedValDstAddr.Bytes()), moveStake.ValidatorDst)
require.Equal(r, testStakingAddr, moveStake.Staker)

// check shares for both validator1 and validator2 are 1
sharesAfterVal1, err = testStaking.GetShares(&bind.CallOpts{}, testStakingAddr, validators[0].OperatorAddress)
Expand Down
4 changes: 4 additions & 0 deletions e2e/runner/v2_migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ func (r *E2ERunner) upgradeZRC20s() {
// upgrade BTC ZRC20
r.Logger.Info("Upgrading BTC ZRC20")
r.upgradeZRC20(r.BTCZRC20Addr, r.BTCZRC20, big.NewInt(btcChainID), uint8(coin.CoinType_Gas))

// upgrade Solana ZRC20
r.Logger.Info("Upgrading Solana ZRC20")
r.upgradeZRC20(r.SOLZRC20Addr, r.SOLZRC20, big.NewInt(902), uint8(coin.CoinType_Gas))
}

// zrc20Caller is an interface to call ZRC20 functions
Expand Down
55 changes: 55 additions & 0 deletions precompiles/logs/logs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package logs

import (
"math/big"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
)

// AddLog adds log to stateDB
func AddLog(ctx sdk.Context, precompileAddr common.Address, stateDB vm.StateDB, topics []common.Hash, data []byte) {
stateDB.AddLog(&types.Log{
Address: precompileAddr,
Topics: topics,
Data: data,
BlockNumber: uint64(ctx.BlockHeight()),
})
}

// MakeTopics creates topics for log as wrapper around geth abi.MakeTopics function
func MakeTopics(event abi.Event, query ...[]interface{}) ([]common.Hash, error) {
topics := []common.Hash{event.ID}

topicsRes, err := abi.MakeTopics(
query...,
)
if err != nil {
return nil, err
}

for _, topic := range topicsRes {
topics = append(topics, topic[0])
}

return topics, nil
}

// PackBigInt is a helper function to pack a uint256 amount
func PackBigInt(amount *big.Int) ([]byte, error) {
uint256Type, err := abi.NewType("uint256", "", nil)
if err != nil {
return nil, err
}

arguments := abi.Arguments{
{
Type: uint256Type,
},
}

return arguments.Pack(amount)
}
Loading

0 comments on commit b4b1421

Please sign in to comment.