This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
forked from 0xPolygon/polygon-edge
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose double signer implementation (0xPolygon#1875)
* Double signer implementation (testing purposes) (0xPolygon#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
1 parent
c3da0d4
commit 3d2e58f
Showing
5 changed files
with
59 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.