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

Commit

Permalink
Double signer implementation (testing purposes) (#1864)
Browse files Browse the repository at this point in the history
* finished code with logs

* Update consensus/polybft/transport.go

Co-authored-by: Stefan Negovanović <[email protected]>

* delete some logs

* Update consensus/polybft/transport.go

Co-authored-by: Stefan Negovanović <[email protected]>

* fix unused imports

* fix wrong logger call

---------

Co-authored-by: Stefan Negovanović <[email protected]>
  • Loading branch information
dusannosovic-ethernal and Stefan-Ethernal committed Sep 6, 2023
1 parent 06153fb commit b4aec98
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions consensus/polybft/polybft.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,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 @@ -71,7 +73,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
}

0 comments on commit b4aec98

Please sign in to comment.