Skip to content

Commit

Permalink
Expose double signer implementation (#1875)
Browse files Browse the repository at this point in the history
* Double signer implementation (testing purposes) (#1864)

* finished code with logs

* Update consensus/polybft/transport.go

Co-authored-by: Stefan Negovanović <93934272+Stefan-Ethernal@users.noreply.github.com>

* delete some logs

* Update consensus/polybft/transport.go

Co-authored-by: Stefan Negovanović <93934272+Stefan-Ethernal@users.noreply.github.com>

* fix unused imports

* fix wrong logger call

---------

Co-authored-by: Stefan Negovanović <93934272+Stefan-Ethernal@users.noreply.github.com>

* Use build tags for double signer implementation

* Address comment and rename

---------

Co-authored-by: Dusan Nosovic <118283942+dusannosovic-ethernal@users.noreply.github.com>
  • Loading branch information
Stefan-Ethernal and dusannosovic-ethernal authored Sep 7, 2023
1 parent c3da0d4 commit 3d2e58f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ test-e2e: check-go
.PHONY: test-e2e-polybft
test-e2e-polybft: check-go
go build -o artifacts/polygon-edge .
env EDGE_BINARY=${PWD}/artifacts/polygon-edge E2E_TESTS=true E2E_LOGS=true BYZANTINE_BINARY=${PWD}/e2e-polybft/e2e/polygon-edge-byzantine \
go build -tags doubleSigner -o artifacts/polygon-edge-double-signer .
env EDGE_BINARY=${PWD}/artifacts/polygon-edge \
BYZANTINE_BINARY=${PWD}/artifacts/polygon-edge-double-signer \
E2E_TESTS=true E2E_LOGS=true \
go test -v -timeout=1h30m ./e2e-polybft/e2e/...

.PHONY: test-property-polybft
Expand Down
45 changes: 45 additions & 0 deletions consensus/polybft/ibft_multicast_double_signer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//go:build doubleSigner

package polybft

import (
"crypto/rand"

ibftProto "github.com/0xPolygon/go-ibft/messages/proto"
"google.golang.org/protobuf/proto"

"github.com/0xPolygon/polygon-edge/types"
)

func (p *Polybft) ibftMsgMulticast(msg *ibftProto.Message) {
if msg.Type != ibftProto.MessageType_COMMIT {
return
}

sender := types.BytesToAddress(msg.From)
localAddr := types.Address(p.key.Address())

if sender != localAddr {
return
}

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 incorrect proposal hash message", "error", err)
}

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

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

return result
}
8 changes: 8 additions & 0 deletions consensus/polybft/ibft_multicast_noop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build !doubleSigner

package polybft

import ibftProto "github.com/0xPolygon/go-ibft/messages/proto"

func (p *Polybft) ibftMsgMulticast(msg *ibftProto.Message) {
}
2 changes: 2 additions & 0 deletions consensus/polybft/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ func (p *Polybft) createTopics() (err error) {

// Multicast is implementation of core.Transport interface
func (p *Polybft) Multicast(msg *ibftProto.Message) {
p.ibftMsgMulticast(msg)

if err := p.consensusTopic.Publish(msg); err != nil {
p.logger.Warn("failed to multicast consensus message", "error", err)
}
Expand Down
Binary file removed e2e-polybft/e2e/polygon-edge-byzantine
Binary file not shown.

0 comments on commit 3d2e58f

Please sign in to comment.