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

Change owner address from SC cross shard #5667

Merged
merged 7 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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: 3 additions & 0 deletions cmd/node/config/enableEpochs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@
# NFTStopCreateEnableEpoch represents the epoch when NFT stop create feature is enabled
NFTStopCreateEnableEpoch = 3

# ChangeOwnerAddressCrossShardThroughSCEnableEpoch represents the epoch when the change owner address built in function will work also through a smart contract call cross shard
ChangeOwnerAddressCrossShardThroughSCEnableEpoch = 3

# BLSMultiSignerEnableEpoch represents the activation epoch for different types of BLS multi-signers
BLSMultiSignerEnableEpoch = [
{ EnableEpoch = 0, Type = "no-KOSK" },
Expand Down
1 change: 1 addition & 0 deletions common/enablers/enableEpochsHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func (handler *enableEpochsHandler) EpochConfirmed(epoch uint32, _ uint64) {
handler.setFlagValue(epoch >= handler.enableEpochsConfig.SCProcessorV2EnableEpoch, handler.scProcessorV2Flag, "scProcessorV2Flag", epoch, handler.enableEpochsConfig.SCProcessorV2EnableEpoch)
handler.setFlagValue(epoch >= handler.enableEpochsConfig.DynamicGasCostForDataTrieStorageLoadEnableEpoch, handler.dynamicGasCostForDataTrieStorageLoadFlag, "dynamicGasCostForDataTrieStorageLoadFlag", epoch, handler.enableEpochsConfig.DynamicGasCostForDataTrieStorageLoadEnableEpoch)
handler.setFlagValue(epoch >= handler.enableEpochsConfig.NFTStopCreateEnableEpoch, handler.nftStopCreateFlag, "nftStopCreateFlag", epoch, handler.enableEpochsConfig.NFTStopCreateEnableEpoch)
handler.setFlagValue(epoch >= handler.enableEpochsConfig.ChangeOwnerAddressCrossShardThroughSCEnableEpoch, handler.changeOwnerAddressCrossShardThroughSCFlag, "changeOwnerAddressCrossShardThroughSCFlag", epoch, handler.enableEpochsConfig.ChangeOwnerAddressCrossShardThroughSCEnableEpoch)
}

func (handler *enableEpochsHandler) setFlagValue(value bool, flag *atomic.Flag, flagName string, epoch uint32, flagEpoch uint32) {
Expand Down
7 changes: 7 additions & 0 deletions common/enablers/epochFlags.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ type epochFlagsHolder struct {
fixDelegationChangeOwnerOnAccountFlag *atomic.Flag
dynamicGasCostForDataTrieStorageLoadFlag *atomic.Flag
nftStopCreateFlag *atomic.Flag
changeOwnerAddressCrossShardThroughSCFlag *atomic.Flag
Copy link
Contributor

Choose a reason for hiding this comment

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

missing tests in config/tomlConfig_test.go ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

func newEpochFlagsHolder() *epochFlagsHolder {
Expand Down Expand Up @@ -205,6 +206,7 @@ func newEpochFlagsHolder() *epochFlagsHolder {
fixDelegationChangeOwnerOnAccountFlag: &atomic.Flag{},
dynamicGasCostForDataTrieStorageLoadFlag: &atomic.Flag{},
nftStopCreateFlag: &atomic.Flag{},
changeOwnerAddressCrossShardThroughSCFlag: &atomic.Flag{},
}
}

Expand Down Expand Up @@ -750,3 +752,8 @@ func (holder *epochFlagsHolder) IsDynamicGasCostForDataTrieStorageLoadEnabled()
func (holder *epochFlagsHolder) NFTStopCreateEnabled() bool {
return holder.nftStopCreateFlag.IsSet()
}

// IsChangeOwnerAddressCrossShardThroughSCEnabled return true if the changeOwnerAddressCrossShardThroughSCFlag is enabled
func (holder *epochFlagsHolder) IsChangeOwnerAddressCrossShardThroughSCEnabled() bool {
return holder.changeOwnerAddressCrossShardThroughSCFlag.IsSet()
}
1 change: 1 addition & 0 deletions common/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ type EnableEpochsHandler interface {
IsDynamicGasCostForDataTrieStorageLoadEnabled() bool
FixDelegationChangeOwnerOnAccountEnabled() bool
NFTStopCreateEnabled() bool
IsChangeOwnerAddressCrossShardThroughSCEnabled() bool

IsInterfaceNil() bool
}
Expand Down
1 change: 1 addition & 0 deletions config/epochConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ type EnableEpochs struct {
FixDelegationChangeOwnerOnAccountEnableEpoch uint32
DynamicGasCostForDataTrieStorageLoadEnableEpoch uint32
NFTStopCreateEnableEpoch uint32
ChangeOwnerAddressCrossShardThroughSCEnableEpoch uint32
BLSMultiSignerEnableEpoch []MultiSignerConfig
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ require (
github.com/multiversx/mx-chain-logger-go v1.0.13
github.com/multiversx/mx-chain-scenario-go v1.2.1
github.com/multiversx/mx-chain-storage-go v1.0.13
github.com/multiversx/mx-chain-vm-common-go v1.5.5
github.com/multiversx/mx-chain-vm-go v1.5.16
github.com/multiversx/mx-chain-vm-common-go v1.5.6-0.20231025104250-d24edf1e19ae
Copy link
Contributor

Choose a reason for hiding this comment

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

let's not forget about proper release

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will add proper tags after system test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

github.com/multiversx/mx-chain-vm-go v1.5.17-0.20231025114923-cc9dde7ff309
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.61
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.62
github.com/multiversx/mx-chain-vm-v1_4-go v1.4.88
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -398,10 +398,10 @@ github.com/multiversx/mx-chain-scenario-go v1.2.1 h1:9eC6VcOEAKRRKZ7EbSWPLzCdNIM
github.com/multiversx/mx-chain-scenario-go v1.2.1/go.mod h1:EuZY7DpNFHVNSxJR8dKE1z2I8gBYfEFFPSwNUOXptqE=
github.com/multiversx/mx-chain-storage-go v1.0.13 h1:i41VPDJZ0pn5gf18zTXrac5xeiolUOztNuzL3wEXRuI=
github.com/multiversx/mx-chain-storage-go v1.0.13/go.mod h1:sJ2q49tgjxNpMpsHysjABqCAB0FLBmDblbjBkQ8XfmA=
github.com/multiversx/mx-chain-vm-common-go v1.5.5 h1:NoG73lvcHSeUcoFlYybG8ceGuJ6KptD3QJjUNEnGDVk=
github.com/multiversx/mx-chain-vm-common-go v1.5.5/go.mod h1:sqkKMCnwkWl8DURdb9q7pctK8IANghdHY1KJLE0ox2c=
github.com/multiversx/mx-chain-vm-go v1.5.16 h1:vBahY/aRe03yRlBPUu/hV+cNTx3MiVLYF+q9Uca+dfU=
github.com/multiversx/mx-chain-vm-go v1.5.16/go.mod h1:F5OoQjCuYNr1hYWvwZKCcWYQir3+r2QVBxQux/eo0Ak=
github.com/multiversx/mx-chain-vm-common-go v1.5.6-0.20231025104250-d24edf1e19ae h1:+W8kDrGgdeuuS9l8a0PZ7HMbdNnH5zkQ5KE1XAryiSc=
github.com/multiversx/mx-chain-vm-common-go v1.5.6-0.20231025104250-d24edf1e19ae/go.mod h1:sqkKMCnwkWl8DURdb9q7pctK8IANghdHY1KJLE0ox2c=
github.com/multiversx/mx-chain-vm-go v1.5.17-0.20231025114923-cc9dde7ff309 h1:NWhUD87WqZtUbEqocvbBrqMMlfAirzMu56YuLJH5sJ4=
github.com/multiversx/mx-chain-vm-go v1.5.17-0.20231025114923-cc9dde7ff309/go.mod h1:pSLANhxTDnEoclJ8FQh5EzKiyT/W2vPogkScaNcNmng=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.61 h1:7c3VRhr5JDu7qs3AkmKQu7DzWGGIoiHfSIMrzw3x5Ao=
github.com/multiversx/mx-chain-vm-v1_2-go v1.2.61/go.mod h1:bQFh+KuUIEBmCfKJ0qVN2+DbRRbAqW0huKfHpiTbyEE=
github.com/multiversx/mx-chain-vm-v1_3-go v1.3.62 h1:rQaWRbrQwrEhSN0ZEQQ0JAbttgi+OrMf/CLziWpRUCA=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package multiShard

import (
"encoding/hex"
"math/big"
"strings"
"testing"

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/integrationTests"
"github.com/multiversx/mx-chain-go/integrationTests/vm"
"github.com/multiversx/mx-chain-go/integrationTests/vm/txsFee/utils"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
"github.com/stretchr/testify/require"
)

func TestDoChangeOwnerCrossShardFromAContract(t *testing.T) {
if testing.Short() {
t.Skip("cannot run with -race -short; requires Wasm VM fix")
}

enableEpochs := config.EnableEpochs{
DynamicGasCostForDataTrieStorageLoadEnableEpoch: integrationTests.UnreachableEpoch,
ChangeOwnerAddressCrossShardThroughSCEnableEpoch: 0,
}

testContextSource, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(0, enableEpochs)
require.Nil(t, err)
defer testContextSource.Close()

// STEP 1
// deploy first contract (this contract has a function that will call the `ChangeOwnerAddress` built-in function)
// on shard 0
pathToContract := "../testdata/changeOwner/contract.wasm"
firstContract, firstOwner := utils.DoDeployWithCustomParams(t, testContextSource, pathToContract, big.NewInt(100000000000), 15000, nil)

utils.CleanAccumulatedIntermediateTransactions(t, testContextSource)
testContextSource.TxFeeHandler.CreateBlockStarted(getZeroGasAndFees())
testContextSource.TxsLogsProcessor.Clean()

require.Equal(t, uint32(0), testContextSource.ShardCoordinator.ComputeId(firstContract))
require.Equal(t, uint32(0), testContextSource.ShardCoordinator.ComputeId(firstOwner))

testContextSecondContract, err := vm.CreatePreparedTxProcessorWithVMsMultiShard(1, enableEpochs)
require.Nil(t, err)
defer testContextSecondContract.Close()

// STEP 2
// deploy the second contract on shard 1
pathToContract = "../testdata/first/output/first.wasm"
secondSCAddress, deployer := utils.DoDeployWithCustomParams(t, testContextSecondContract, pathToContract, big.NewInt(100000000000), 15000, nil)
require.Equal(t, uint32(1), testContextSource.ShardCoordinator.ComputeId(secondSCAddress))

// STEP 3
// change the owner of the second contract -- the new owner will be the first contract
gasPrice := uint64(10)
txData := []byte(core.BuiltInFunctionChangeOwnerAddress + "@" + hex.EncodeToString(firstContract))
tx := vm.CreateTransaction(1, big.NewInt(0), deployer, secondSCAddress, gasPrice, 1000, txData)
returnCode, err := testContextSecondContract.TxProcessor.ProcessTransaction(tx)
require.Nil(t, err)
require.Equal(t, vmcommon.Ok, returnCode)
_, err = testContextSecondContract.Accounts.Commit()
require.Nil(t, err)
utils.CheckOwnerAddr(t, testContextSecondContract, secondSCAddress, firstContract)

// STEP 3
// call `change_owner` function from the first contract
gasLimit := uint64(5000000)
dataField := append([]byte("change_owner"), []byte("@"+hex.EncodeToString(secondSCAddress))...)
dataField = append(dataField, []byte("@"+hex.EncodeToString(firstOwner))...)
tx = vm.CreateTransaction(1, big.NewInt(0), firstOwner, firstContract, gasPrice, gasLimit, dataField)

retCode, err := testContextSource.TxProcessor.ProcessTransaction(tx)
require.Equal(t, vmcommon.Ok, retCode)
require.Nil(t, err)

intermediateTxs := testContextSource.GetIntermediateTransactions(t)
require.Equal(t, 1, len(intermediateTxs))

expectedDataField := core.BuiltInFunctionChangeOwnerAddress + "@" + hex.EncodeToString(firstOwner)
require.True(t, strings.HasPrefix(string(intermediateTxs[0].GetData()), expectedDataField))

logs := testContextSource.TxsLogsProcessor.GetAllCurrentLogs()
require.NotNil(t, logs)

// STEP 4
// executed results smart contract results of the shard1 where the second contract was deployed
testContextSecondContract.TxsLogsProcessor.Clean()
utils.ProcessSCRResult(t, testContextSecondContract, intermediateTxs[0], vmcommon.Ok, nil)
utils.CheckOwnerAddr(t, testContextSecondContract, secondSCAddress, firstOwner)

logs = testContextSecondContract.TxsLogsProcessor.GetAllCurrentLogs()
require.NotNil(t, logs)
require.Equal(t, core.BuiltInFunctionChangeOwnerAddress, string(logs[0].GetLogEvents()[0].GetIdentifier()))
}
Binary file not shown.
5 changes: 5 additions & 0 deletions sharding/mock/enableEpochsHandlerMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ type EnableEpochsHandlerMock struct {
IsFixOldTokenLiquidityFlagEnabledField bool
}

// IsChangeOwnerAddressCrossShardThroughSCEnabled -
func (mock *EnableEpochsHandlerMock) IsChangeOwnerAddressCrossShardThroughSCEnabled() bool {
return false
}

// BlockGasAndFeesReCheckEnableEpoch returns 0
func (mock *EnableEpochsHandlerMock) BlockGasAndFeesReCheckEnableEpoch() uint32 {
return 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ type EnableEpochsHandlerStub struct {
FixDelegationChangeOwnerOnAccountEnabledField bool
IsDynamicGasCostForDataTrieStorageLoadEnabledField bool
IsNFTStopCreateEnabledField bool
IsChangeOwnerAddressCrossShardThroughSCEnabledField bool
}

// ResetPenalizedTooMuchGasFlag -
Expand Down Expand Up @@ -1133,6 +1134,14 @@ func (stub *EnableEpochsHandlerStub) NFTStopCreateEnabled() bool {
return stub.IsNFTStopCreateEnabledField
}

// IsChangeOwnerAddressCrossShardThroughSCEnabled -
func (stub *EnableEpochsHandlerStub) IsChangeOwnerAddressCrossShardThroughSCEnabled() bool {
stub.RLock()
defer stub.RUnlock()

return stub.IsChangeOwnerAddressCrossShardThroughSCEnabledField
}

// IsInterfaceNil -
func (stub *EnableEpochsHandlerStub) IsInterfaceNil() bool {
return stub == nil
Expand Down