Skip to content
This repository has been archived by the owner on Dec 4, 2024. It is now read-only.

Double signer implementation (testing purposes) #1864

Merged
merged 7 commits into from
Sep 4, 2023
Merged
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
1 change: 1 addition & 0 deletions consensus/polybft/polybft.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ func ForkManagerFactory(forks *chain.Forks) error {
// Initialize initializes the consensus (e.g. setup data)
func (p *Polybft) Initialize() error {
p.logger.Info("initializing polybft...")
p.logger.Error("Initializing byzantine node...")

// read account
account, err := wallet.NewAccountFromSecret(p.config.SecretsManager)
Expand Down
31 changes: 31 additions & 0 deletions consensus/polybft/transport.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package polybft

import (
"crypto/rand"
"fmt"

ibftProto "github.com/0xPolygon/go-ibft/messages/proto"
polybftProto "github.com/0xPolygon/polygon-edge/consensus/polybft/proto"
"github.com/0xPolygon/polygon-edge/types"
"github.com/libp2p/go-libp2p/core/peer"
"google.golang.org/protobuf/proto"
)

// BridgeTransport is an abstraction of network layer for a bridge
Expand Down Expand Up @@ -59,7 +61,36 @@ func (p *Polybft) createTopics() (err error) {

// Multicast is implementation of core.Transport interface
func (p *Polybft) Multicast(msg *ibftProto.Message) {
if msg.Type == ibftProto.MessageType_COMMIT {
sender := types.BytesToAddress(msg.From)
localAddr := types.Address(p.key.Address())

if sender == localAddr {
tamperedMsg, _ := proto.Clone(msg).(*ibftProto.Message)

tamperedMsg.GetCommitData().ProposalHash = generateRandomHash()
tamperedMsg.Signature = nil

tamperedMsg, err := p.key.SignIBFTMessage(tamperedMsg)

if err != nil {
p.logger.Warn("failed to sign message", "error", err)
}

if err = p.consensusTopic.Publish(tamperedMsg); err != nil {
p.logger.Warn("failed to multicast second consensus message", "error", err)
}
}
}

if err := p.consensusTopic.Publish(msg); err != nil {
p.logger.Warn("failed to multicast consensus message", "error", err)
}
}

func generateRandomHash() []byte {
result := make([]byte, types.HashLength)
_, _ = rand.Reader.Read(result)

return result
}
Loading