From c7538191a6d100756777c98c4137d8bec8fabe19 Mon Sep 17 00:00:00 2001 From: Iuga Mihai Date: Tue, 13 Jun 2023 11:50:27 +0300 Subject: [PATCH 1/4] upgrade vm-common --- go.mod | 2 +- go.sum | 3 ++- vm/systemSmartContracts/esdt.go | 12 ++++++++++++ vm/systemSmartContracts/esdt_test.go | 18 ++++++++++++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index ac3e61cc521..34508e610bc 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/multiversx/mx-chain-logger-go v1.0.11 github.com/multiversx/mx-chain-p2p-go v1.0.14 github.com/multiversx/mx-chain-storage-go v1.0.7 - github.com/multiversx/mx-chain-vm-common-go v1.3.41 + github.com/multiversx/mx-chain-vm-common-go v1.4.4-0.20230613071024-e22c1e6ac6b4 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.54 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.55 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.81 diff --git a/go.sum b/go.sum index 465663cbcc2..f4444eab615 100644 --- a/go.sum +++ b/go.sum @@ -629,8 +629,9 @@ github.com/multiversx/mx-chain-p2p-go v1.0.14/go.mod h1:64lqBWpQa/sDwdmzzHb2waT2 github.com/multiversx/mx-chain-storage-go v1.0.7 h1:UqLo/OLTD3IHiE/TB/SEdNRV1GG2f1R6vIP5ehHwCNw= github.com/multiversx/mx-chain-storage-go v1.0.7/go.mod h1:gtKoV32Cg2Uy8deHzF8Ud0qAl0zv92FvWgPSYIP0Zmg= github.com/multiversx/mx-chain-vm-common-go v1.3.40/go.mod h1:r+aILrY07ue89PH+D+B+Pp0viO1U3kN98t1pXneSgkE= -github.com/multiversx/mx-chain-vm-common-go v1.3.41 h1:jIgv5PvTUNx96v+0a0W+qIulyUYT9bbaTdBlMxwQbOQ= github.com/multiversx/mx-chain-vm-common-go v1.3.41/go.mod h1:r+aILrY07ue89PH+D+B+Pp0viO1U3kN98t1pXneSgkE= +github.com/multiversx/mx-chain-vm-common-go v1.4.4-0.20230613071024-e22c1e6ac6b4 h1:+WyrdSZXwjxtYTEB3OK1s0Lu/xHpEtNDAgziewlZ1DA= +github.com/multiversx/mx-chain-vm-common-go v1.4.4-0.20230613071024-e22c1e6ac6b4/go.mod h1:r+aILrY07ue89PH+D+B+Pp0viO1U3kN98t1pXneSgkE= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.54 h1:c+S0xhfOMtwWEJHMqoPf8plF3sLnz3euPj4Rd/wN2UQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.54/go.mod h1:iuM50SqgelbKYNEm9s4BZcWczIgyCJIGFKajGUCDVm0= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.55 h1:hmo/QQ/qY+WgsMQeBODIX+tEnM/XIf7izNs9+WbKg4Y= diff --git a/vm/systemSmartContracts/esdt.go b/vm/systemSmartContracts/esdt.go index 4f49327ac0b..a9712ed9d1a 100644 --- a/vm/systemSmartContracts/esdt.go +++ b/vm/systemSmartContracts/esdt.go @@ -701,6 +701,8 @@ func (e *esdt) upgradeProperties(tokenIdentifier []byte, token *ESDTDataV2, args return vm.ErrInvalidNumOfArguments } + isUpgradablePropertyInArgs := false + isCanAddSpecialRolePropertyInArgs := false for i := 0; i < len(args); i += 2 { optionalArg := string(args[i]) val, err := checkAndGetSetting(string(args[i+1])) @@ -726,10 +728,12 @@ func (e *esdt) upgradeProperties(tokenIdentifier []byte, token *ESDTDataV2, args token.CanWipe = val case upgradable: token.Upgradable = val + isUpgradablePropertyInArgs = true case canChangeOwner: token.CanChangeOwner = val case canAddSpecialRoles: token.CanAddSpecialRoles = val + isCanAddSpecialRolePropertyInArgs = true case canTransferNFTCreateRole: token.CanTransferNFTCreateRole = val case canCreateMultiShard: @@ -752,6 +756,14 @@ func (e *esdt) upgradeProperties(tokenIdentifier []byte, token *ESDTDataV2, args nonce := big.NewInt(0) topics = append(topics, tokenIdentifier, nonce.Bytes()) topics = append(topics, args...) + + if !isUpgradablePropertyInArgs { + topics = append(topics, []byte(upgradable), boolToSlice(token.Upgradable)) + } + if !isCanAddSpecialRolePropertyInArgs { + topics = append(topics, []byte(canAddSpecialRoles), boolToSlice(token.CanAddSpecialRoles)) + } + logEntry := &vmcommon.LogEntry{ Identifier: []byte(upgradeProperties), Address: callerAddr, diff --git a/vm/systemSmartContracts/esdt_test.go b/vm/systemSmartContracts/esdt_test.go index 861fd7a695c..59c98de66d9 100644 --- a/vm/systemSmartContracts/esdt_test.go +++ b/vm/systemSmartContracts/esdt_test.go @@ -220,6 +220,14 @@ func TestEsdt_ExecuteIssueWithMultiNFTCreate(t *testing.T) { returnCode = e.Execute(vmInput) assert.Equal(t, vmcommon.Ok, returnCode) + upgradePropertiesLog := eei.logs[0] + expectedTopics := [][]byte{[]byte("TICKER-75fd57"), big.NewInt(0).Bytes(), []byte(canCreateMultiShard), boolToSlice(true), []byte(upgradable), boolToSlice(true), []byte(canAddSpecialRoles), boolToSlice(true)} + assert.Equal(t, &vmcommon.LogEntry{ + Identifier: []byte(upgradeProperties), + Address: []byte("addr"), + Topics: expectedTopics, + }, upgradePropertiesLog) + lastOutput := eei.output[len(eei.output)-1] token, _ := e.getExistingToken(lastOutput) assert.True(t, token.CanCreateMultiShard) @@ -252,11 +260,21 @@ func TestEsdt_ExecuteIssue(t *testing.T) { vmInput.Arguments = append(vmInput.Arguments, big.NewInt(100).Bytes()) vmInput.Arguments = append(vmInput.Arguments, big.NewInt(10).Bytes()) + vmInput.Arguments = append(vmInput.Arguments, []byte(upgradable), boolToSlice(false)) + vmInput.Arguments = append(vmInput.Arguments, []byte(canAddSpecialRoles), boolToSlice(false)) vmInput.CallValue, _ = big.NewInt(0).SetString(args.ESDTSCConfig.BaseIssuingCost, 10) vmInput.GasProvided = args.GasCost.MetaChainSystemSCsCost.ESDTIssue output = e.Execute(vmInput) assert.Equal(t, vmcommon.Ok, output) + upgradePropertiesLog := eei.logs[0] + expectedTopics := [][]byte{[]byte("TICKER-75fd57"), big.NewInt(0).Bytes(), []byte(upgradable), boolToSlice(false), []byte(canAddSpecialRoles), boolToSlice(false)} + assert.Equal(t, &vmcommon.LogEntry{ + Identifier: []byte(upgradeProperties), + Address: []byte("addr"), + Topics: expectedTopics, + }, upgradePropertiesLog) + vmInput.Arguments[0] = []byte("01234567891&*@") output = e.Execute(vmInput) assert.Equal(t, vmcommon.UserError, output) From 8a6d89cdcabcdd2cec1ac4bd9588c653feaafdc4 Mon Sep 17 00:00:00 2001 From: Iuga Mihai Date: Wed, 14 Jun 2023 14:21:36 +0300 Subject: [PATCH 2/4] bug fix --- vm/systemSmartContracts/esdt.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/vm/systemSmartContracts/esdt.go b/vm/systemSmartContracts/esdt.go index a9712ed9d1a..eadf22d1ec5 100644 --- a/vm/systemSmartContracts/esdt.go +++ b/vm/systemSmartContracts/esdt.go @@ -694,7 +694,19 @@ func (e *esdt) upgradeProperties(tokenIdentifier []byte, token *ESDTDataV2, args mintBurnable = false } + topics := make([][]byte, 0) + nonce := big.NewInt(0) + topics = append(topics, tokenIdentifier, nonce.Bytes()) + logEntry := &vmcommon.LogEntry{ + Identifier: []byte(upgradeProperties), + Address: callerAddr, + } + if len(args) == 0 { + topics = append(topics, []byte(upgradable), boolToSlice(token.Upgradable), []byte(canAddSpecialRoles), boolToSlice(token.CanAddSpecialRoles)) + logEntry.Topics = topics + e.eei.AddLogEntry(logEntry) + return nil } if len(args)%2 != 0 { @@ -752,11 +764,7 @@ func (e *esdt) upgradeProperties(tokenIdentifier []byte, token *ESDTDataV2, args } } - topics := make([][]byte, 0) - nonce := big.NewInt(0) - topics = append(topics, tokenIdentifier, nonce.Bytes()) topics = append(topics, args...) - if !isUpgradablePropertyInArgs { topics = append(topics, []byte(upgradable), boolToSlice(token.Upgradable)) } @@ -764,11 +772,7 @@ func (e *esdt) upgradeProperties(tokenIdentifier []byte, token *ESDTDataV2, args topics = append(topics, []byte(canAddSpecialRoles), boolToSlice(token.CanAddSpecialRoles)) } - logEntry := &vmcommon.LogEntry{ - Identifier: []byte(upgradeProperties), - Address: callerAddr, - Topics: topics, - } + logEntry.Topics = topics e.eei.AddLogEntry(logEntry) return nil From 01738495b09df13ab62c994eeca768be1810aa34 Mon Sep 17 00:00:00 2001 From: Iuga Mihai Date: Thu, 15 Jun 2023 09:37:06 +0300 Subject: [PATCH 3/4] fix go mod --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 34508e610bc..1e2efcb0aea 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/multiversx/mx-chain-logger-go v1.0.11 github.com/multiversx/mx-chain-p2p-go v1.0.14 github.com/multiversx/mx-chain-storage-go v1.0.7 - github.com/multiversx/mx-chain-vm-common-go v1.4.4-0.20230613071024-e22c1e6ac6b4 + github.com/multiversx/mx-chain-vm-common-go v1.4.4-0.20230614131748-e022f38797ac github.com/multiversx/mx-chain-vm-v1_2-go v1.2.54 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.55 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.81 diff --git a/go.sum b/go.sum index f4444eab615..9c8a9cb3537 100644 --- a/go.sum +++ b/go.sum @@ -630,8 +630,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.7 h1:UqLo/OLTD3IHiE/TB/SEdNRV1GG2 github.com/multiversx/mx-chain-storage-go v1.0.7/go.mod h1:gtKoV32Cg2Uy8deHzF8Ud0qAl0zv92FvWgPSYIP0Zmg= github.com/multiversx/mx-chain-vm-common-go v1.3.40/go.mod h1:r+aILrY07ue89PH+D+B+Pp0viO1U3kN98t1pXneSgkE= github.com/multiversx/mx-chain-vm-common-go v1.3.41/go.mod h1:r+aILrY07ue89PH+D+B+Pp0viO1U3kN98t1pXneSgkE= -github.com/multiversx/mx-chain-vm-common-go v1.4.4-0.20230613071024-e22c1e6ac6b4 h1:+WyrdSZXwjxtYTEB3OK1s0Lu/xHpEtNDAgziewlZ1DA= -github.com/multiversx/mx-chain-vm-common-go v1.4.4-0.20230613071024-e22c1e6ac6b4/go.mod h1:r+aILrY07ue89PH+D+B+Pp0viO1U3kN98t1pXneSgkE= +github.com/multiversx/mx-chain-vm-common-go v1.4.4-0.20230614131748-e022f38797ac h1:Jjlsw3fMqAFsjwzo/jnqQYEf55wK5xHoV+/JqqImfvc= +github.com/multiversx/mx-chain-vm-common-go v1.4.4-0.20230614131748-e022f38797ac/go.mod h1:r+aILrY07ue89PH+D+B+Pp0viO1U3kN98t1pXneSgkE= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.54 h1:c+S0xhfOMtwWEJHMqoPf8plF3sLnz3euPj4Rd/wN2UQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.54/go.mod h1:iuM50SqgelbKYNEm9s4BZcWczIgyCJIGFKajGUCDVm0= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.55 h1:hmo/QQ/qY+WgsMQeBODIX+tEnM/XIf7izNs9+WbKg4Y= From 7e156c0e06db7aa788bace09437230ddbca5a1e8 Mon Sep 17 00:00:00 2001 From: Iuga Mihai Date: Thu, 15 Jun 2023 09:41:47 +0300 Subject: [PATCH 4/4] proper tag --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 1e2efcb0aea..bda86475d92 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/multiversx/mx-chain-logger-go v1.0.11 github.com/multiversx/mx-chain-p2p-go v1.0.14 github.com/multiversx/mx-chain-storage-go v1.0.7 - github.com/multiversx/mx-chain-vm-common-go v1.4.4-0.20230614131748-e022f38797ac + github.com/multiversx/mx-chain-vm-common-go v1.3.42 github.com/multiversx/mx-chain-vm-v1_2-go v1.2.54 github.com/multiversx/mx-chain-vm-v1_3-go v1.3.55 github.com/multiversx/mx-chain-vm-v1_4-go v1.4.81 diff --git a/go.sum b/go.sum index 9c8a9cb3537..e93b1fb6742 100644 --- a/go.sum +++ b/go.sum @@ -630,8 +630,8 @@ github.com/multiversx/mx-chain-storage-go v1.0.7 h1:UqLo/OLTD3IHiE/TB/SEdNRV1GG2 github.com/multiversx/mx-chain-storage-go v1.0.7/go.mod h1:gtKoV32Cg2Uy8deHzF8Ud0qAl0zv92FvWgPSYIP0Zmg= github.com/multiversx/mx-chain-vm-common-go v1.3.40/go.mod h1:r+aILrY07ue89PH+D+B+Pp0viO1U3kN98t1pXneSgkE= github.com/multiversx/mx-chain-vm-common-go v1.3.41/go.mod h1:r+aILrY07ue89PH+D+B+Pp0viO1U3kN98t1pXneSgkE= -github.com/multiversx/mx-chain-vm-common-go v1.4.4-0.20230614131748-e022f38797ac h1:Jjlsw3fMqAFsjwzo/jnqQYEf55wK5xHoV+/JqqImfvc= -github.com/multiversx/mx-chain-vm-common-go v1.4.4-0.20230614131748-e022f38797ac/go.mod h1:r+aILrY07ue89PH+D+B+Pp0viO1U3kN98t1pXneSgkE= +github.com/multiversx/mx-chain-vm-common-go v1.3.42 h1:avhgUwi6f+wpHqaBk76j6islLzUlSRBXwisKoZnUXpk= +github.com/multiversx/mx-chain-vm-common-go v1.3.42/go.mod h1:r+aILrY07ue89PH+D+B+Pp0viO1U3kN98t1pXneSgkE= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.54 h1:c+S0xhfOMtwWEJHMqoPf8plF3sLnz3euPj4Rd/wN2UQ= github.com/multiversx/mx-chain-vm-v1_2-go v1.2.54/go.mod h1:iuM50SqgelbKYNEm9s4BZcWczIgyCJIGFKajGUCDVm0= github.com/multiversx/mx-chain-vm-v1_3-go v1.3.55 h1:hmo/QQ/qY+WgsMQeBODIX+tEnM/XIf7izNs9+WbKg4Y=