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

Send bitmap + epoch in outgoing operations #15

Open
wants to merge 3 commits into
base: feat/sovereign-cross-validators-changes
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ require (
github.com/gin-gonic/gin v1.9.1
github.com/gorilla/websocket v1.5.0
github.com/joho/godotenv v1.5.1
github.com/multiversx/mx-chain-core-go v1.2.23-0.20241007113300-50ac1ae23824
github.com/multiversx/mx-chain-core-go v1.2.24-0.20250113143225-72ba2e508401
github.com/multiversx/mx-chain-crypto-go v1.2.11
github.com/multiversx/mx-chain-go v1.7.12
github.com/multiversx/mx-chain-logger-go v1.0.14
github.com/multiversx/mx-sdk-go v1.4.4-0.20241105143052-f5830f5b9079
github.com/stretchr/testify v1.8.4
github.com/tyler-smith/go-bip39 v1.1.0
github.com/urfave/cli v1.22.14
google.golang.org/grpc v1.60.1
)
Expand Down Expand Up @@ -56,7 +57,6 @@ require (
github.com/tklauser/go-sysconf v0.3.4 // indirect
github.com/tklauser/numcpus v0.2.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
golang.org/x/arch v0.3.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUY
github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o=
github.com/multiversx/mx-chain-communication-go v1.0.14 h1:YhAUDjBBpc5h5W0A7LHLXUMIMeCgwgGvkqfAPbFqsno=
github.com/multiversx/mx-chain-communication-go v1.0.14/go.mod h1:qYCqgk0h+YpcTA84jHIpCBy6UShRwmXzHSCcdfwNrkw=
github.com/multiversx/mx-chain-core-go v1.2.23-0.20241007113300-50ac1ae23824 h1:OHYcWOeTNwSaTMRAfusu6/1zoTWGEtHKPBig4dbRAwM=
github.com/multiversx/mx-chain-core-go v1.2.23-0.20241007113300-50ac1ae23824/go.mod h1:P/YBoFnt25XUaCQ7Q/SD15vhnc9yV5JDhHxyFO9P8Z0=
github.com/multiversx/mx-chain-core-go v1.2.24-0.20250113143225-72ba2e508401 h1:jMSqlYlzHwbbjYerMGNZtZsm4eZshH3uXW9N8iNbHD0=
github.com/multiversx/mx-chain-core-go v1.2.24-0.20250113143225-72ba2e508401/go.mod h1:P/YBoFnt25XUaCQ7Q/SD15vhnc9yV5JDhHxyFO9P8Z0=
github.com/multiversx/mx-chain-crypto-go v1.2.11 h1:MNPJoiTJA5/tedYrI0N22OorbsKDESWG0SF8MCJwcJI=
github.com/multiversx/mx-chain-crypto-go v1.2.11/go.mod h1:pcZutPdfLiAFytzCU3LxU3s8cXkvpNqquyitFSfoF3o=
github.com/multiversx/mx-chain-go v1.7.12 h1:cQ3g5sFZEcQmIRwi/wt+K/3d5nIwCMQRC1ZnJDRuRY4=
Expand Down
2 changes: 2 additions & 0 deletions server/bridgeServer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"testing"

"github.com/multiversx/mx-chain-core-go/data/sovereign"

Copy link
Contributor

Choose a reason for hiding this comment

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

Wrong imports

"github.com/multiversx/mx-chain-sovereign-bridge-go/testscommon"

"github.com/stretchr/testify/require"
)

Expand Down
14 changes: 13 additions & 1 deletion server/txSender/dataFormatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package txSender

import (
"bytes"
"encoding/binary"
"encoding/hex"

"github.com/multiversx/mx-chain-core-go/core"
Expand Down Expand Up @@ -68,8 +69,19 @@ func (df *dataFormatter) createRegisterBridgeOperationsData(bridgeData *sovereig
registerBridgeOpData := []byte(registerBridgeOpsPrefix +
"@" + hex.EncodeToString(bridgeData.AggregatedSignature) +
"@" + hex.EncodeToString(bridgeData.Hash))
registerBridgeOpData = append(registerBridgeOpData, hashesHexEncodedArgs...)

return append(registerBridgeOpData, hashesHexEncodedArgs...)
bridgeDataArgs := []byte(
"@" + hex.EncodeToString(bridgeData.PubKeysBitmap) +
Copy link
Contributor

Choose a reason for hiding this comment

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

I would put PubKeysBitmap before or after AggregatedSignature, not at the end

Copy link
Contributor

Choose a reason for hiding this comment

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

It's mandatory to have bitmap + epoch before hashesHexEncodedArgs so the contract can decode the arguments properly.

"@" + hex.EncodeToString(uint32ToBytes(bridgeData.Epoch)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need the Epoch?
Do we really need a to keep all the maps <epoch, validators> in the contract storage?

Copy link
Contributor

Choose a reason for hiding this comment

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

I see now why we need to keep the history. Maybe there are unconfirmed operations sent in the epoch 1, but were signed by the validators in epoch 0

Choose a reason for hiding this comment

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

it is better to keep for at least 2-3 epochs.


return append(registerBridgeOpData, bridgeDataArgs...)
}

func uint32ToBytes(value uint32) []byte {
buff := make([]byte, 4)
binary.BigEndian.PutUint32(buff, value)
return buff
}

func createBridgeOperationsData(hashOfHashes []byte, outGoingOperations []*sovereign.OutGoingOperation) [][]byte {
Expand Down
18 changes: 15 additions & 3 deletions server/txSender/dataFormatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/data/sovereign"
"github.com/multiversx/mx-chain-sovereign-bridge-go/testscommon"
"github.com/stretchr/testify/require"

"github.com/multiversx/mx-chain-sovereign-bridge-go/testscommon"
)

func TestNewDataFormatter(t *testing.T) {
Expand Down Expand Up @@ -57,6 +58,9 @@ func TestDataFormatter_CreateTxsData(t *testing.T) {
bridgeDataOp2 := []byte("bridgeDataOp2")
bridgeDataOp3 := []byte("bridgeDataOp3")

pubKeysBitmap1 := []byte("pubKeysBitmap1")
pubKeysBitmap2 := []byte("pubKeysBitmap2")

bridgeOps := &sovereign.BridgeOperations{
Data: []*sovereign.BridgeOutGoingData{
{
Expand All @@ -73,6 +77,8 @@ func TestDataFormatter_CreateTxsData(t *testing.T) {
},
AggregatedSignature: aggregatedSig1,
LeaderSignature: leaderSig1,
PubKeysBitmap: pubKeysBitmap1,
Epoch: 1,
},
{
Hash: bridgeDataHash2,
Expand All @@ -84,6 +90,8 @@ func TestDataFormatter_CreateTxsData(t *testing.T) {
},
AggregatedSignature: aggregatedSig2,
LeaderSignature: leaderSig2,
PubKeysBitmap: pubKeysBitmap2,
Epoch: 2,
},
},
}
Expand Down Expand Up @@ -116,7 +124,9 @@ func TestDataFormatter_CreateTxsData(t *testing.T) {
"@" + hex.EncodeToString(aggregatedSig1) +
"@" + hex.EncodeToString(bridgeDataHash1) +
"@" + hex.EncodeToString(opHash1) +
"@" + hex.EncodeToString(opHash2))
"@" + hex.EncodeToString(opHash2) +
"@" + hex.EncodeToString(pubKeysBitmap1) +
"@" + "00000001")
execOp1 := []byte(executeBridgeOpsPrefix +
"@" + hex.EncodeToString(bridgeDataHash1) +
"@" + hex.EncodeToString(bridgeDataOp1))
Expand All @@ -128,7 +138,9 @@ func TestDataFormatter_CreateTxsData(t *testing.T) {
registerBridgeOpsPrefix +
"@" + hex.EncodeToString(aggregatedSig2) +
"@" + hex.EncodeToString(bridgeDataHash2) +
"@" + hex.EncodeToString(opHash3))
"@" + hex.EncodeToString(opHash3) +
"@" + hex.EncodeToString(pubKeysBitmap2) +
"@" + "00000002")
execOp3 := []byte(executeBridgeOpsPrefix +
"@" + hex.EncodeToString(bridgeDataHash2) +
"@" + hex.EncodeToString(bridgeDataOp3))
Expand Down
Loading