From a4a4559881f0345573f511e64326fce6c9efec41 Mon Sep 17 00:00:00 2001 From: Yilun Date: Tue, 20 Jul 2021 17:33:35 -0700 Subject: [PATCH] Use random beacon as salt when computing sigchain miner Signed-off-by: Yilun --- chain/blockvalidator.go | 2 +- config/config.go | 4 ++++ pb/sigchain.go | 12 +++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/chain/blockvalidator.go b/chain/blockvalidator.go index 16f250021..2401da39d 100644 --- a/chain/blockvalidator.go +++ b/chain/blockvalidator.go @@ -295,7 +295,7 @@ func GetNextBlockSigner(height uint32, timestamp int64) ([]byte, []byte, pb.Winn return nil, nil, 0, err } - publicKey, chordID, err = sigChain.GetMiner(height) + publicKey, chordID, err = sigChain.GetMiner(height, header.UnsignedHeader.RandomBeacon) if err != nil { return nil, nil, 0, err } diff --git a/config/config.go b/config/config.go index f8490a456..d21bb6d3f 100644 --- a/config/config.go +++ b/config/config.go @@ -220,6 +220,10 @@ var ( heights: []uint32{2633000, 0}, values: []int32{10, 0}, } + SigChainMinerSalt = HeightDependentBool{ + heights: []uint32{2900000, 0}, + values: []bool{true, false}, + } ) var ( diff --git a/pb/sigchain.go b/pb/sigchain.go index 5fc87bd4c..8c3c48022 100644 --- a/pb/sigchain.go +++ b/pb/sigchain.go @@ -201,7 +201,7 @@ func (sc *SigChain) GetSignerIndex(pubkey []byte) (int, error) { return idx, err } -func (sc *SigChain) GetMiner(height uint32) ([]byte, []byte, error) { +func (sc *SigChain) GetMiner(height uint32, randomBeacon []byte) ([]byte, []byte, error) { if !sc.IsComplete() { return nil, nil, errors.New("sigchain is not complete") } @@ -235,15 +235,21 @@ func (sc *SigChain) GetMiner(height uint32) ([]byte, []byte, error) { return nil, nil, err } + h := sigHash + if config.SigChainMinerSalt.GetValueAtHeight(height) { + hs := sha256.Sum256(append(sigHash, randomBeacon...)) + h = hs[:] + } + x := big.NewInt(0) - x.SetBytes(sigHash) + x.SetBytes(h) y := big.NewInt(int64(elemLen)) newIndex := big.NewInt(0) newIndex.Mod(x, y) originalIndex := minerElems[newIndex.Int64()].index if originalIndex == 0 { - return sc.SrcPubkey, sc.Elems[0].Id, nil + return nil, nil, errors.New("invalid miner index") } return sc.Elems[originalIndex-1].NextPubkey, sc.Elems[originalIndex].Id, nil