Skip to content

Commit

Permalink
[Feature] Double-signing slashing (#1808)
Browse files Browse the repository at this point in the history
* Add governance parameters to genesis an polybft config

* Add Governance as fork (#1700)

* [RFC-191] Add `governorAdmin` flag (#1728)

* Add governorAdmin flag

* Comments fix

* [RFC-191]: Add governance `proposal-quorum` flag (#1730)

* Add proposal-quorum flag

* Comments fix

* [RFC-191]: EVM-740 - Move distribute rewards to first block in epoch (#1735)

* Move distribute rewards to first block of epoch

* Modification of reward distribution as part of governance fork

* Small change

* Comments fix

* Rebase fix

* [RFC-191]: EVM-556 - Deploy governance contracts (#1733)

* Add contracts

* Fix integration test

* [RFC-191]: EVM-558 - Update client configuration based on governance proposals (#1749)

* GovernanceManager

* PostEpoch

* PostBlock and update of client config

* Lint fix

* UTs

* Comments fix

* Retry in PostEpoch as well

* Comments fix

* Rebase fix

* [RFC-191]: EVM-750 - Governance e2e tests (#1761)

* Governance e2e tests

* Comments fix

* [RFC-191]: EVM-760 - Utilize `ForkParams` contract (#1788)

* Add forks activation based on ForkParams contract

* Comments fix

* Don't use hardcoded addresses for governance contracts (#1790)

* Rebase fix

* Minor optimization (#1798)

* Rebase fix

* Small fixes

* Small fix

* Comments fix

* Slashing double signing tracker (#1756)

* Double signing tracker (draft)

* Track all messages and detect double signing by comparing signatures

* Address comments

* Add mutex, fix double sign detection

* Unit tests (part 1)

* PruneMsgsUntil unit test

* tracker.Handle multiple senders UT

* Address comments

* Updated comment

* GetEvidences UT

* Remove redundant variable

* Add missing mutex calls

* Protect from spammers in tracker

* Ignore messages sent by non-validators (#1767)

* Filter messages which are not sent by known validators in double signing tracker

* Init double signing tracker only when stake store is populated with validators

* Fix tests

* Fix GetEvidences UT

* Simplification in add message fn

* Add comments

* Deterministic IBFT message types iterating

* Make linter happy (again)

* Simplify GetEvidences, since messages with unique signatures are added into the storage

* Rename GetValidators to GetAllValidators

* Send messages from a separate routine

* Run IBFT messages handling in parallel

* Double sign evidence struct modifications

* Simplify double signer evidence (#1812)

* Simplification

* Suppress linting error

* Rename checkpoint store to exit event store (#1814)

* Sort rounds and senders in double signing tracker storage (#1806)

* Provide only 2 messages per evidence

* Introduce MinAddressHeap and use it to store addresses sorted

* Add min round heap to keep rounds sorted

* Use sorted slice instead of heap for rounds and addresses

* Prevent adding the same address and rounds multiple times

* Remove SortedMessages structure

* Add randomized test

* Messages.stringer

* Linter fix

* Make randomized test working

* Fix GetDoubleSigners property test

* Rename

* Unexport Min function

* Cleanup

* Release lock if there are no msgs for the given height

* slashing state transaction creation and validation (#1815)

* slashing state transaction creation and validation

* ut fixes

* CR fixes

* linter fix

* Byzantine node testing (#1813)

* Byzantine node testing

* minor fix

* lint fix

* CR fix

* CR fix

* New byzantine binary

---------

Co-authored-by: Nemanja0x <[email protected]>

* Invoke PruneMsgsUntil when block is finalized (#1820)

* generated new bindings & artifacts for ValidatorSet and CustomSupernetManager contracts (#1822)

* Run byzantine node as a validator (#1824)

* Run byzantine node as a validator

* CR fix - rename

* Expose JSON RPC function for slash exit events retrieval (#1823)

* Slash exit events storage

* Tear down checkpoint manager post block test

* bridge_getPendingSlashProofs JSON RPC function

* Add comment

* Don't rely on doubleSignSlashing hardfork within the exit events storage

* Log  exit events that do not contain signature encoded

* Create as much proofs as possible even if error is returned

* Merge fix (move polybft_config to common package)

* Generate SC artifacts and bindings

* Build fix

* Lint fix

* SC artifacts regenerate

* Merge fix (provide isFirstBlockOfEpoch indicator)

* Increase timeout for e2e tests

* Update byzantine binary (#1829)

* GenerateSlashExitProofs UT (#1827)

* Update contracts

* Remove executed slashing exit events from storage (#1832)

* Add removeSlashExitEvents function

* Remove processed slashing events from exit events storage

* Double sign slashing E2E test (#1833)

E2E test for double sign slashing

* e2e helper methods for byzantine validators (#1844)

* Add governance parameters to genesis an polybft config

* Add Governance as fork (#1700)

* [RFC-191] Add `governorAdmin` flag (#1728)

* Add governorAdmin flag

* Comments fix

* [RFC-191]: Add governance `proposal-quorum` flag (#1730)

* Add proposal-quorum flag

* Comments fix

* [RFC-191]: EVM-740 - Move distribute rewards to first block in epoch (#1735)

* Move distribute rewards to first block of epoch

* Modification of reward distribution as part of governance fork

* Small change

* Comments fix

* Rebase fix

* [RFC-191]: EVM-556 - Deploy governance contracts (#1733)

* Add contracts

* Fix integration test

* [RFC-191]: EVM-558 - Update client configuration based on governance proposals (#1749)

* GovernanceManager

* PostEpoch

* PostBlock and update of client config

* Lint fix

* UTs

* Comments fix

* Retry in PostEpoch as well

* Comments fix

* Rebase fix

* [RFC-191]: EVM-750 - Governance e2e tests (#1761)

* Governance e2e tests

* Comments fix

* [RFC-191]: EVM-760 - Utilize `ForkParams` contract (#1788)

* Add forks activation based on ForkParams contract

* Comments fix

* Don't use hardcoded addresses for governance contracts (#1790)

* Rebase fix

* Minor optimization (#1798)

* Rebase fix

* Small fixes

* Small fix

* Comments fix

* Fix cluster script (provide governor-admin only for polybft consensus)

* Update contracts

* Merge fix (update contracts)

* Add governance parameters to genesis an polybft config

* Add Governance as fork (#1700)

* [RFC-191] Add `governorAdmin` flag (#1728)

* Add governorAdmin flag

* Comments fix

* [RFC-191]: Add governance `proposal-quorum` flag (#1730)

* Add proposal-quorum flag

* Comments fix

* [RFC-191]: EVM-740 - Move distribute rewards to first block in epoch (#1735)

* Move distribute rewards to first block of epoch

* Modification of reward distribution as part of governance fork

* Small change

* Comments fix

* Rebase fix

* [RFC-191]: EVM-556 - Deploy governance contracts (#1733)

* Add contracts

* Fix integration test

* [RFC-191]: EVM-558 - Update client configuration based on governance proposals (#1749)

* GovernanceManager

* PostEpoch

* PostBlock and update of client config

* Lint fix

* UTs

* Comments fix

* Retry in PostEpoch as well

* Comments fix

* Rebase fix

* [RFC-191]: EVM-750 - Governance e2e tests (#1761)

* Governance e2e tests

* Comments fix

* [RFC-191]: EVM-760 - Utilize `ForkParams` contract (#1788)

* Add forks activation based on ForkParams contract

* Comments fix

* Don't use hardcoded addresses for governance contracts (#1790)

* Rebase fix

* Minor optimization (#1798)

* Rebase fix

* Small fixes

* Small fix

* Comments fix

* Fix cluster script (provide governor-admin only for polybft consensus)

* Increase E2E tests timeout

* Comments fix

* Comments fix

* Generate SC artifacts

* Address comments (part 1)

* Address comment (part 2)

* Propagate error

* forks as a field

* Formatting

* Fix bridge e2e tests

* Fix UTs

* Update byzantine binary

* Update byzantine binary

---------

Co-authored-by: Goran Rojovic <[email protected]>
Co-authored-by: Goran Rojovic <[email protected]>
Co-authored-by: dusan-maksimovic <[email protected]>
Co-authored-by: Dusan Maksimovic <[email protected]>
Co-authored-by: Marko Jelača <[email protected]>
Co-authored-by: Nemanja0x <[email protected]>
Co-authored-by: Igor Crevar <[email protected]>
  • Loading branch information
8 people authored Sep 6, 2023
1 parent 3cae93a commit 06153fb
Show file tree
Hide file tree
Showing 73 changed files with 2,718 additions and 509 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ 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 \
env EDGE_BINARY=${PWD}/artifacts/polygon-edge E2E_TESTS=true E2E_LOGS=true BYZANTINE_BINARY=${PWD}/e2e-polybft/e2e/polygon-edge-byzantine \
go test -v -timeout=1h30m ./e2e-polybft/e2e/...

.PHONY: test-property-polybft
Expand Down
6 changes: 5 additions & 1 deletion chain/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const (
TxHashWithType = "txHashWithType"
LondonFix = "londonfix"
Governance = "governance"
DoubleSignSlashing = "doubleSignSlashing"
)

// Forks is map which contains all forks and their starting blocks from genesis
Expand Down Expand Up @@ -129,6 +130,7 @@ func (f *Forks) At(block uint64) ForksInTime {
TxHashWithType: f.IsActive(TxHashWithType, block),
LondonFix: f.IsActive(LondonFix, block),
Governance: f.IsActive(Governance, block),
DoubleSignSlashing: f.IsActive(DoubleSignSlashing, block),
}
}

Expand Down Expand Up @@ -159,7 +161,8 @@ type ForksInTime struct {
QuorumCalcAlignment,
TxHashWithType,
LondonFix,
Governance bool
Governance,
DoubleSignSlashing bool
}

// AllForksEnabled should contain all supported forks by current edge version
Expand All @@ -177,4 +180,5 @@ var AllForksEnabled = &Forks{
TxHashWithType: NewFork(0),
LondonFix: NewFork(0),
Governance: NewFork(0),
DoubleSignSlashing: NewFork(0),
}
8 changes: 4 additions & 4 deletions command/genesis/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/0xPolygon/polygon-edge/consensus/ibft"
"github.com/0xPolygon/polygon-edge/consensus/ibft/fork"
"github.com/0xPolygon/polygon-edge/consensus/ibft/signer"
"github.com/0xPolygon/polygon-edge/consensus/polybft"
"github.com/0xPolygon/polygon-edge/consensus/polybft/common"
"github.com/0xPolygon/polygon-edge/contracts/staking"
stakingHelper "github.com/0xPolygon/polygon-edge/helper/staking"
"github.com/0xPolygon/polygon-edge/server"
Expand Down Expand Up @@ -133,7 +133,7 @@ type genesisParams struct {
accessListsOwner string

nativeTokenConfigRaw string
nativeTokenConfig *polybft.TokenConfig
nativeTokenConfig *common.TokenConfig

premineInfos []*premineInfo

Expand Down Expand Up @@ -576,7 +576,7 @@ func (p *genesisParams) isBurnContractEnabled() bool {
// extractNativeTokenMetadata parses provided native token metadata (such as name, symbol and decimals count)
func (p *genesisParams) extractNativeTokenMetadata() error {
if p.nativeTokenConfigRaw == "" {
p.nativeTokenConfig = &polybft.TokenConfig{
p.nativeTokenConfig = &common.TokenConfig{
Name: defaultNativeTokenName,
Symbol: defaultNativeTokenSymbol,
Decimals: defaultNativeTokenDecimals,
Expand Down Expand Up @@ -627,7 +627,7 @@ func (p *genesisParams) extractNativeTokenMetadata() error {
owner = types.StringToAddress(strings.TrimSpace(params[4]))
}

p.nativeTokenConfig = &polybft.TokenConfig{
p.nativeTokenConfig = &common.TokenConfig{
Name: name,
Symbol: symbol,
Decimals: uint8(decimals),
Expand Down
12 changes: 6 additions & 6 deletions command/genesis/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/umbracle/ethgo"

"github.com/0xPolygon/polygon-edge/command"
"github.com/0xPolygon/polygon-edge/consensus/polybft"
"github.com/0xPolygon/polygon-edge/consensus/polybft/common"
"github.com/0xPolygon/polygon-edge/types"
)

Expand All @@ -18,13 +18,13 @@ func Test_extractNativeTokenMetadata(t *testing.T) {
cases := []struct {
name string
rawConfig string
expectedCfg *polybft.TokenConfig
expectedCfg *common.TokenConfig
expectErr bool
}{
{
name: "default token config",
rawConfig: "",
expectedCfg: &polybft.TokenConfig{
expectedCfg: &common.TokenConfig{
Name: defaultNativeTokenName,
Symbol: defaultNativeTokenSymbol,
Decimals: defaultNativeTokenDecimals,
Expand Down Expand Up @@ -66,7 +66,7 @@ func Test_extractNativeTokenMetadata(t *testing.T) {
{
name: "non-mintable valid config",
rawConfig: "MyToken:MTK:9:false",
expectedCfg: &polybft.TokenConfig{
expectedCfg: &common.TokenConfig{
Name: "MyToken",
Symbol: "MTK",
Decimals: 9,
Expand All @@ -78,7 +78,7 @@ func Test_extractNativeTokenMetadata(t *testing.T) {
{
name: "non-mintable token config, owner provided but ignored",
rawConfig: "MyToken:MTK:9:false:0x123456789",
expectedCfg: &polybft.TokenConfig{
expectedCfg: &common.TokenConfig{
Name: "MyToken",
Symbol: "MTK",
Decimals: 9,
Expand All @@ -90,7 +90,7 @@ func Test_extractNativeTokenMetadata(t *testing.T) {
{
name: "mintable token valid config",
rawConfig: "MyMintToken:MMTK:9:true:0x123456789",
expectedCfg: &polybft.TokenConfig{
expectedCfg: &common.TokenConfig{
Name: "MyMintToken",
Symbol: "MMTK",
Decimals: 9,
Expand Down
9 changes: 5 additions & 4 deletions command/genesis/polybft_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/0xPolygon/polygon-edge/command"
"github.com/0xPolygon/polygon-edge/command/helper"
"github.com/0xPolygon/polygon-edge/consensus/polybft"
polyCommon "github.com/0xPolygon/polygon-edge/consensus/polybft/common"
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi"
"github.com/0xPolygon/polygon-edge/consensus/polybft/contractsapi/artifact"
"github.com/0xPolygon/polygon-edge/consensus/polybft/validator"
Expand Down Expand Up @@ -175,7 +176,7 @@ func (p *genesisParams) generatePolyBftChainConfig(o command.OutputFormatter) er
proposalQuorum = proposalQuorumMax
}

polyBftConfig := &polybft.PolyBFTConfig{
polyBftConfig := &polyCommon.PolyBFTConfig{
InitialValidatorSet: initialValidators,
BlockTime: common.Duration{Duration: p.blockTime},
EpochSize: p.epochSize,
Expand All @@ -189,13 +190,13 @@ func (p *genesisParams) generatePolyBftChainConfig(o command.OutputFormatter) er
MaxValidatorSetSize: p.maxNumValidators,
CheckpointInterval: p.checkpointInterval,
WithdrawalWaitPeriod: p.withdrawalWaitPeriod,
RewardConfig: &polybft.RewardsConfig{
RewardConfig: &polyCommon.RewardsConfig{
TokenAddress: rewardTokenAddr,
WalletAddress: walletPremineInfo.address,
WalletAmount: walletPremineInfo.amount,
},
BlockTimeDrift: p.blockTimeDrift,
GovernanceConfig: &polybft.GovernanceConfig{
GovernanceConfig: &polyCommon.GovernanceConfig{
VotingDelay: voteDelay,
VotingPeriod: votingPeriod,
ProposalThreshold: proposalThreshold,
Expand Down Expand Up @@ -369,7 +370,7 @@ func (p *genesisParams) generatePolyBftChainConfig(o command.OutputFormatter) er

func (p *genesisParams) deployContracts(
rewardTokenByteCode []byte,
polybftConfig *polybft.PolyBFTConfig,
polybftConfig *polyCommon.PolyBFTConfig,
chainConfig *chain.Chain,
burnContractAddr types.Address) (map[types.Address]*chain.GenesisAccount, error) {
type contractInfo struct {
Expand Down
7 changes: 4 additions & 3 deletions command/genesis/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/0xPolygon/polygon-edge/command"
"github.com/0xPolygon/polygon-edge/consensus/polybft"
"github.com/0xPolygon/polygon-edge/consensus/polybft/bitmap"
polyCommon "github.com/0xPolygon/polygon-edge/consensus/polybft/common"
"github.com/0xPolygon/polygon-edge/consensus/polybft/validator"
"github.com/0xPolygon/polygon-edge/consensus/polybft/wallet"
"github.com/0xPolygon/polygon-edge/helper/common"
Expand Down Expand Up @@ -124,7 +125,7 @@ func parseTrackerStartBlocks(trackerStartBlocksRaw []string) (map[types.Address]
}

// parseBurnContractInfo parses provided burn contract information and returns burn contract block and address
func parseBurnContractInfo(burnContractInfoRaw string) (*polybft.BurnContractInfo, error) {
func parseBurnContractInfo(burnContractInfoRaw string) (*polyCommon.BurnContractInfo, error) {
// <block>:<address>[:<burn destination address>]
burnContractParts := strings.Split(burnContractInfoRaw, ":")
if len(burnContractParts) < 2 || len(burnContractParts) > 3 {
Expand All @@ -144,7 +145,7 @@ func parseBurnContractInfo(burnContractInfoRaw string) (*polybft.BurnContractInf
}

if len(burnContractParts) == 2 {
return &polybft.BurnContractInfo{
return &polyCommon.BurnContractInfo{
BlockNumber: blockNum,
Address: types.StringToAddress(contractAddress),
DestinationAddress: types.ZeroAddress,
Expand All @@ -156,7 +157,7 @@ func parseBurnContractInfo(burnContractInfoRaw string) (*polybft.BurnContractInf
return nil, fmt.Errorf("failed to parse burn destination address %s: %w", destinationAddress, err)
}

return &polybft.BurnContractInfo{
return &polyCommon.BurnContractInfo{
BlockNumber: blockNum,
Address: types.StringToAddress(contractAddress),
DestinationAddress: types.StringToAddress(destinationAddress),
Expand Down
Loading

0 comments on commit 06153fb

Please sign in to comment.