Integrate swapped bls into core protocol

pull/974/head
Rongjian Lan 6 years ago
parent 4b7e4fdcc9
commit 3bd0ee7455
  1. 4
      consensus/consensus_leader_msg.go
  2. 8
      consensus/consensus_service.go
  3. 16
      consensus/consensus_v2.go
  4. 4
      consensus/consensus_validator_msg.go
  5. 2
      contracts/structs/structs.go
  6. 6
      core/resharding.go
  7. 24
      core/resharding_test.go
  8. 4
      core/types/block.go
  9. 24
      core/types/block_test.go
  10. 2
      core/types/shard_state.go
  11. 16
      core/types/shard_state_test.go
  12. 3
      node/staking.go

@ -47,7 +47,7 @@ func (consensus *Consensus) constructPreparedMessage() ([]byte, *bls.Sign) {
//// Payload
buffer := bytes.NewBuffer([]byte{})
// 48 bytes aggregated signature
// 96 bytes aggregated signature
aggSig := bls_cosi.AggregateSig(consensus.GetPrepareSigsArray())
buffer.Write(aggSig.Serialize())
@ -80,7 +80,7 @@ func (consensus *Consensus) constructCommittedMessage() ([]byte, *bls.Sign) {
//// Payload
buffer := bytes.NewBuffer([]byte{})
// 48 bytes aggregated signature
// 96 bytes aggregated signature
aggSig := bls_cosi.AggregateSig(consensus.GetCommitSigsArray())
buffer.Write(aggSig.Serialize())

@ -574,14 +574,14 @@ func (consensus *Consensus) SetBlockNum(blockNum uint64) {
// read the payload for signature and bitmap; offset is the beginning position of reading
func (consensus *Consensus) readSignatureBitmapPayload(recvPayload []byte, offset int) (*bls.Sign, *bls_cosi.Mask, error) {
if offset+48 > len(recvPayload) {
if offset+96 > len(recvPayload) {
return nil, nil, errors.New("payload not have enough length")
}
payload := append(recvPayload[:0:0], recvPayload...)
//#### Read payload data
// 48 byte of multi-sig
multiSig := payload[offset : offset+48]
offset += 48
// 96 byte of multi-sig
multiSig := payload[offset : offset+96]
offset += 96
// bitmap
bitmap := payload[offset:]
//#### END Read payload data

@ -683,20 +683,20 @@ func (consensus *Consensus) tryCatchup() {
consensus.LeaderPubKey = msgs[0].SenderPubkey
//#### Read payload data from committed msg
aggSig := make([]byte, 48)
bitmap := make([]byte, len(msgs[0].Payload)-48)
aggSig := make([]byte, 96)
bitmap := make([]byte, len(msgs[0].Payload)-96)
offset := 0
copy(aggSig[:], msgs[0].Payload[offset:offset+48])
offset += 48
copy(aggSig[:], msgs[0].Payload[offset:offset+96])
offset += 96
copy(bitmap[:], msgs[0].Payload[offset:])
//#### END Read payload data from committed msg
//#### Read payload data from prepared msg
prepareSig := make([]byte, 48)
prepareBitmap := make([]byte, len(msg.Payload)-48)
prepareSig := make([]byte, 96)
prepareBitmap := make([]byte, len(msg.Payload)-96)
offset = 0
copy(prepareSig[:], msg.Payload[offset:offset+48])
offset += 48
copy(prepareSig[:], msg.Payload[offset:offset+96])
offset += 96
copy(prepareBitmap[:], msg.Payload[offset:])
//#### END Read payload data from committed msg

@ -19,7 +19,7 @@ func (consensus *Consensus) constructPrepareMessage() []byte {
consensusMsg := message.GetConsensus()
consensus.populateMessageFields(consensusMsg)
// 48 byte of bls signature
// 96 byte of bls signature
sign := consensus.priKey.SignHash(consensusMsg.BlockHash)
if sign != nil {
consensusMsg.Payload = sign.Serialize()
@ -45,7 +45,7 @@ func (consensus *Consensus) constructCommitMessage(commitPayload []byte) []byte
consensusMsg := message.GetConsensus()
consensus.populateMessageFields(consensusMsg)
// 48 byte of bls signature
// 96 byte of bls signature
sign := consensus.priKey.SignHash(commitPayload)
if sign != nil {
consensusMsg.Payload = sign.Serialize()

@ -13,7 +13,7 @@ type StakeInfoReturnValue struct {
LockedAddresses []common.Address
BlsPubicKeys1 [][32]byte
BlsPubicKeys2 [][32]byte
BlsPubicKeys3 [][32]byte
BlsPubicKeys3 [][32]byte // TODO: remove third part as know we use 48 bytes pub key
BlockNums []*big.Int
LockPeriodCounts []*big.Int // The number of locking period the token will be locked.
Amounts []*big.Int

@ -27,7 +27,7 @@ const (
// GenesisShardNum is the number of shard at genesis
GenesisShardNum = 4
// GenesisShardSize is the size of each shard at genesis
GenesisShardSize = 100
GenesisShardSize = 10
// CuckooRate is the percentage of nodes getting reshuffled in the second step of cuckoo resharding.
CuckooRate = 0.1
)
@ -228,8 +228,8 @@ func GetInitShardState() types.ShardState {
index := i + j*GenesisShardNum // The initial account to use for genesis nodes
priKey := bls.SecretKey{}
priKey.SetHexString(contract.GenesisBLSAccounts[index].Private)
pubKey := [96]byte{}
copy(pubKey[:], priKey.GetPublicKey().Serialize()[:])
pubKey := types.BlsPublicKey{}
pubKey.FromLibBLSPublicKey(priKey.GetPublicKey())
// TODO: directly read address for bls too
curNodeID := types.NodeID{contract.GenesisAccounts[index].Address, pubKey}
com.NodeList = append(com.NodeList, curNodeID)

@ -11,16 +11,16 @@ import (
)
var (
blsPubKey1 = [96]byte{}
blsPubKey2 = [96]byte{}
blsPubKey3 = [96]byte{}
blsPubKey4 = [96]byte{}
blsPubKey5 = [96]byte{}
blsPubKey6 = [96]byte{}
blsPubKey7 = [96]byte{}
blsPubKey8 = [96]byte{}
blsPubKey9 = [96]byte{}
blsPubKey10 = [96]byte{}
blsPubKey1 = [48]byte{}
blsPubKey2 = [48]byte{}
blsPubKey3 = [48]byte{}
blsPubKey4 = [48]byte{}
blsPubKey5 = [48]byte{}
blsPubKey6 = [48]byte{}
blsPubKey7 = [48]byte{}
blsPubKey8 = [48]byte{}
blsPubKey9 = [48]byte{}
blsPubKey10 = [48]byte{}
)
func init() {
@ -44,7 +44,7 @@ func fakeGetInitShardState(numberOfShards, numOfNodes int) types.ShardState {
com := types.Committee{ShardID: sid}
for j := 0; j < numOfNodes; j++ {
nid := strconv.Itoa(int(rand.Int63()))
blsPubKey := [96]byte{}
blsPubKey := [48]byte{}
copy(blsPubKey1[:], []byte(nid))
com.NodeList = append(com.NodeList, types.NodeID{nid, blsPubKey})
}
@ -59,7 +59,7 @@ func fakeNewNodeList(seed int64) []types.NodeID {
nodeList := []types.NodeID{}
for i := 0; i < numNewNodes; i++ {
nid := strconv.Itoa(int(rand.Int63()))
blsPubKey := [96]byte{}
blsPubKey := [48]byte{}
copy(blsPubKey1[:], []byte(nid))
nodeList = append(nodeList, types.NodeID{nid, blsPubKey})
}

@ -88,9 +88,9 @@ type Header struct {
// Additional Fields
Epoch *big.Int `json:"epoch" gencodec:"required"`
ShardID uint32 `json:"shardID" gencodec:"required"`
PrepareSignature [48]byte `json:"prepareSignature" gencodec:"required"`
PrepareSignature [96]byte `json:"prepareSignature" gencodec:"required"`
PrepareBitmap []byte `json:"prepareBitmap" gencodec:"required"` // Contains which validator signed
CommitSignature [48]byte `json:"commitSignature" gencodec:"required"`
CommitSignature [96]byte `json:"commitSignature" gencodec:"required"`
CommitBitmap []byte `json:"commitBitmap" gencodec:"required"` // Contains which validator signed
RandPreimage [32]byte `json:"randPreimage"`
RandSeed [32]byte `json:"randSeed"`

@ -30,6 +30,12 @@ var (
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
}
pat48HexAA = []byte{
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
@ -38,6 +44,12 @@ var (
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
}
pat48Pi = []byte{
0x03, 0x14, 0x15, 0x92, 0x65, 0x35, 0x89, 0x79,
@ -46,6 +58,12 @@ var (
0x75, 0x10, 0x58, 0x20, 0x97, 0x49, 0x44, 0x59,
0x23, 0x07, 0x81, 0x64, 0x06, 0x28, 0x62, 0x08,
0x99, 0x86, 0x28, 0x03, 0x48, 0x25, 0x34, 0x21,
0x03, 0x14, 0x15, 0x92, 0x65, 0x35, 0x89, 0x79,
0x32, 0x38, 0x46, 0x26, 0x43, 0x38, 0x32, 0x79,
0x50, 0x28, 0x84, 0x19, 0x71, 0x69, 0x39, 0x93,
0x75, 0x10, 0x58, 0x20, 0x97, 0x49, 0x44, 0x59,
0x23, 0x07, 0x81, 0x64, 0x06, 0x28, 0x62, 0x08,
0x99, 0x86, 0x28, 0x03, 0x48, 0x25, 0x34, 0x21,
}
pat48E = []byte{
0x02, 0x71, 0x82, 0x81, 0x82, 0x84, 0x59, 0x04,
@ -54,6 +72,12 @@ var (
0x99, 0x95, 0x95, 0x74, 0x96, 0x69, 0x67, 0x62,
0x77, 0x24, 0x07, 0x66, 0x30, 0x35, 0x35, 0x47,
0x59, 0x45, 0x71, 0x38, 0x21, 0x78, 0x52, 0x51,
0x02, 0x71, 0x82, 0x81, 0x82, 0x84, 0x59, 0x04,
0x52, 0x35, 0x36, 0x02, 0x87, 0x47, 0x13, 0x52,
0x66, 0x24, 0x97, 0x75, 0x72, 0x47, 0x09, 0x36,
0x99, 0x95, 0x95, 0x74, 0x96, 0x69, 0x67, 0x62,
0x77, 0x24, 0x07, 0x66, 0x30, 0x35, 0x35, 0x47,
0x59, 0x45, 0x71, 0x38, 0x21, 0x78, 0x52, 0x51,
}
)

@ -63,7 +63,7 @@ func CompareShardState(s1, s2 ShardState) int {
}
// BlsPublicKey defines the bls public key
type BlsPublicKey [96]byte
type BlsPublicKey [48]byte
// Hex returns the hex string of bls public key
func (pk BlsPublicKey) Hex() string {

@ -6,14 +6,14 @@ import (
)
var (
blsPubKey1 = [96]byte{}
blsPubKey2 = [96]byte{}
blsPubKey3 = [96]byte{}
blsPubKey4 = [96]byte{}
blsPubKey5 = [96]byte{}
blsPubKey6 = [96]byte{}
blsPubKey11 = [96]byte{}
blsPubKey22 = [96]byte{}
blsPubKey1 = [48]byte{}
blsPubKey2 = [48]byte{}
blsPubKey3 = [48]byte{}
blsPubKey4 = [48]byte{}
blsPubKey5 = [48]byte{}
blsPubKey6 = [48]byte{}
blsPubKey11 = [48]byte{}
blsPubKey22 = [48]byte{}
)
func init() {

@ -47,8 +47,7 @@ func (node *Node) UpdateStakingList(stakeInfoReturnValue *structs.StakeInfoRetur
if curEpoch-startEpoch <= lockPeriodCount.Uint64()*lockPeriodInEpochs {
blsPubKey := types.BlsPublicKey{}
copy(blsPubKey[:32], stakeInfoReturnValue.BlsPubicKeys1[i][:])
copy(blsPubKey[32:64], stakeInfoReturnValue.BlsPubicKeys2[i][:])
copy(blsPubKey[64:96], stakeInfoReturnValue.BlsPubicKeys3[i][:])
copy(blsPubKey[32:48], stakeInfoReturnValue.BlsPubicKeys2[i][:16])
node.CurrentStakes[addr] = &structs.StakeInfo{
Account: addr,
BlsPublicKey: blsPubKey,

Loading…
Cancel
Save