Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
554b78f0
Commit
554b78f0
authored
Jun 08, 2020
by
madengji
Committed by
33cn
Jun 29, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bls take crypto interface
parent
27aab59b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
123 additions
and
86 deletions
+123
-86
parablssign.go
plugin/consensus/para/parablssign.go
+6
-1
parablssign_test.go
plugin/consensus/para/parablssign_test.go
+50
-38
build.sh
plugin/dapp/paracross/cmd/build.sh
+1
-0
action.go
plugin/dapp/paracross/executor/action.go
+26
-19
paracross.go
plugin/dapp/paracross/executor/paracross.go
+8
-2
paracross_test.go
plugin/dapp/paracross/executor/paracross_test.go
+32
-26
No files found.
plugin/consensus/para/parablssign.go
View file @
554b78f0
...
@@ -413,7 +413,12 @@ func (b *blsClient) aggregateSigns(signs [][]byte) (crypto.Signature, error) {
...
@@ -413,7 +413,12 @@ func (b *blsClient) aggregateSigns(signs [][]byte) (crypto.Signature, error) {
}
}
signatures
=
append
(
signatures
,
si
)
signatures
=
append
(
signatures
,
si
)
}
}
return
b
.
cryptoCli
.
Aggregate
(
signatures
)
agg
,
err
:=
crypto
.
ToAggregate
(
b
.
cryptoCli
)
if
err
!=
nil
{
return
nil
,
types
.
ErrNotSupport
}
return
agg
.
Aggregate
(
signatures
)
}
}
func
(
b
*
blsClient
)
updatePeers
(
id
string
,
add
bool
)
{
func
(
b
*
blsClient
)
updatePeers
(
id
string
,
add
bool
)
{
...
...
plugin/consensus/para/parablssign_test.go
View file @
554b78f0
...
@@ -7,12 +7,12 @@ package para
...
@@ -7,12 +7,12 @@ package para
import
(
import
(
"testing"
"testing"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
"github.com/33cn/plugin/plugin/dapp/evm/executor/vm/common"
"github.com/33cn/chain33/common/crypto"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/herumi/bls-eth-go-binary/bls"
"github.com/stretchr/testify/assert"
"github.com/magiconair/properties/assert"
)
)
func
TestSetAddrsBitMap
(
t
*
testing
.
T
)
{
func
TestSetAddrsBitMap
(
t
*
testing
.
T
)
{
...
@@ -60,27 +60,29 @@ func TestIntegrateCommits(t *testing.T) {
...
@@ -60,27 +60,29 @@ func TestIntegrateCommits(t *testing.T) {
}
}
func
TestBlsSignMain
(
t
*
testing
.
T
)
{
func
TestBlsSignMain
(
t
*
testing
.
T
)
{
//只初始化一次,多次初始化会并行产生冲突
cryptoCli
,
err
:=
crypto
.
New
(
"bls"
)
bls
.
Init
(
bls
.
BLS12_381
)
assert
.
NoError
(
t
,
err
)
testSecpPrikey2BlsPub
(
t
)
testSecpPrikey2BlsPub
(
t
,
cryptoCli
)
testBlsSign
(
t
)
testBlsSign
(
t
,
cryptoCli
)
testVerifyBlsSign
(
t
)
testVerifyBlsSign
(
t
,
cryptoCli
)
}
}
func
testSecpPrikey2BlsPub
(
t
*
testing
.
T
)
{
func
testSecpPrikey2BlsPub
(
t
*
testing
.
T
,
cryptCli
crypto
.
Crypto
)
{
cli
:=
blsClient
{}
cli
.
cryptoCli
=
cryptCli
key
:=
""
key
:=
""
ret
,
_
:=
secp256Prikey2BlsPub
(
key
)
ret
,
_
:=
cli
.
secp256Prikey2BlsPub
(
key
)
assert
.
Equal
(
t
,
""
,
ret
)
assert
.
Equal
(
t
,
""
,
ret
)
//real prikey="1626b254a75e5c44de9500a0c7897643e7736c09a7270b807546acb7cf7c94c9"
//real prikey="1626b254a75e5c44de9500a0c7897643e7736c09a7270b807546acb7cf7c94c9"
key
=
"0xcacb1f5d51700aea07fca2246ab43b0917d70405c65edea9b5063d72eb5c6b71"
key
=
"0xcacb1f5d51700aea07fca2246ab43b0917d70405c65edea9b5063d72eb5c6b71"
q
:=
"0x980287e26d4d44f8c57944ffc096f7d98a460c97dadbffaed14ff0de901fa7f8afc59fcb1805a0b031e5eae5601df1c2"
q
:=
"0x980287e26d4d44f8c57944ffc096f7d98a460c97dadbffaed14ff0de901fa7f8afc59fcb1805a0b031e5eae5601df1c2"
ret
,
_
=
secp256Prikey2BlsPub
(
key
)
ret
,
_
=
cli
.
secp256Prikey2BlsPub
(
key
)
assert
.
Equal
(
t
,
q
,
ret
)
assert
.
Equal
(
t
,
q
,
ret
)
}
}
func
testBlsSign
(
t
*
testing
.
T
)
{
func
testBlsSign
(
t
*
testing
.
T
,
cryptCli
crypto
.
Crypto
)
{
status
:=
&
pt
.
ParacrossNodeStatus
{}
status
:=
&
pt
.
ParacrossNodeStatus
{}
status
.
Height
=
0
status
.
Height
=
0
status
.
Title
=
"user.p.para."
status
.
Title
=
"user.p.para."
...
@@ -90,50 +92,60 @@ func testBlsSign(t *testing.T) {
...
@@ -90,50 +92,60 @@ func testBlsSign(t *testing.T) {
PriKS
:=
"6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
PriKS
:=
"6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
commit
:=
&
pt
.
ParacrossCommitAction
{
Status
:
status
}
commit
:=
&
pt
.
ParacrossCommitAction
{
Status
:
status
}
client
:=
&
blsClient
{}
client
:=
&
blsClient
{
cryptoCli
:
cryptCli
}
client
.
peersBlsPubKey
=
make
(
map
[
string
]
*
bls
.
PublicKey
)
client
.
peersBlsPubKey
=
make
(
map
[
string
]
crypto
.
PubKey
)
var
prikey
bls
.
SecretKey
p
,
err
:=
common
.
FromHex
(
PriKS
)
prikey
.
DeserializeHexStr
(
PriKS
)
assert
.
NoError
(
t
,
err
)
t
.
Log
(
"pri"
,
prikey
.
SerializeToHexStr
())
prikey
,
err
:=
client
.
cryptoCli
.
PrivKeyFromBytes
(
p
)
client
.
blsPriKey
=
&
prikey
assert
.
NoError
(
t
,
err
)
err
:=
client
.
blsSign
([]
*
pt
.
ParacrossCommitAction
{
commit
})
assert
.
Equal
(
t
,
err
,
nil
)
client
.
blsPriKey
=
prikey
err
=
client
.
blsSign
([]
*
pt
.
ParacrossCommitAction
{
commit
})
var
pub
bls
.
PublicKey
assert
.
NoError
(
t
,
err
)
pub
.
DeserializeHexStr
(
PubKS
)
client
.
peersBlsPubKey
[
KS
]
=
&
pub
p
,
err
=
common
.
FromHex
(
PubKS
)
t
.
Log
(
"pubks"
,
pub
.
SerializeToHexStr
())
assert
.
NoError
(
t
,
err
)
var
sign
bls
.
Sign
pub
,
err
:=
cryptCli
.
PubKeyFromBytes
(
p
)
sign
.
Deserialize
(
commit
.
Bls
.
Sign
)
assert
.
NoError
(
t
,
err
)
client
.
peersBlsPubKey
[
KS
]
=
pub
sign
,
err
:=
cryptCli
.
SignatureFromBytes
(
commit
.
Bls
.
Sign
)
assert
.
NoError
(
t
,
err
)
msg
:=
types
.
Encode
(
status
)
msg
:=
types
.
Encode
(
status
)
ret
:=
sign
.
VerifyByte
(
&
pub
,
msg
)
ret
:=
pub
.
VerifyBytes
(
msg
,
sign
)
assert
.
Equal
(
t
,
ret
,
true
)
assert
.
Equal
(
t
,
ret
,
true
)
err
=
client
.
verifyBlsSign
(
KS
,
commit
)
err
=
client
.
verifyBlsSign
(
KS
,
commit
)
assert
.
Equal
(
t
,
err
,
nil
)
assert
.
Equal
(
t
,
err
,
nil
)
}
}
func
testVerifyBlsSign
(
t
*
testing
.
T
)
{
func
testVerifyBlsSign
(
t
*
testing
.
T
,
cryptCli
crypto
.
Crypto
)
{
client
:=
&
blsClient
{}
client
:=
&
blsClient
{
cryptoCli
:
cryptCli
}
client
.
peersBlsPubKey
=
make
(
map
[
string
]
*
bls
.
Public
Key
)
client
.
peersBlsPubKey
=
make
(
map
[
string
]
crypto
.
Pub
Key
)
KS
:=
"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"
KS
:=
"1KSBd17H7ZK8iT37aJztFB22XGwsPTdwE4"
PubKS
:=
"a3d97d4186c80268fe6d3689dd574599e25df2dffdcff03f7d8ef64a3bd483241b7d0985958990de2d373d5604caf805"
PubKS
:=
"a3d97d4186c80268fe6d3689dd574599e25df2dffdcff03f7d8ef64a3bd483241b7d0985958990de2d373d5604caf805"
var
pub
bls
.
PublicKey
pub
.
DeserializeHexStr
(
PubKS
)
p
,
err
:=
common
.
FromHex
(
PubKS
)
client
.
peersBlsPubKey
[
KS
]
=
&
pub
assert
.
NoError
(
t
,
err
)
pub
,
err
:=
cryptCli
.
PubKeyFromBytes
(
p
)
assert
.
NoError
(
t
,
err
)
client
.
peersBlsPubKey
[
KS
]
=
pub
commit
:=
&
pt
.
ParacrossCommitAction
{}
commit
:=
&
pt
.
ParacrossCommitAction
{}
blsInfo
:=
&
pt
.
ParacrossCommitBlsInfo
{}
blsInfo
:=
&
pt
.
ParacrossCommitBlsInfo
{}
signData
:=
"0x82753675393576758571cbbaefada498614b4a0a967ca2dd5724eb46ecfd1c89f1e49792ebbe1866c1d6d6ceaf3054c7189751477a5b7312218eb77dcab1bfb6287c6fbf2e1c6cf8fe2ade7c17596b081dc98be785a34db5b45a5cca08e7e744"
signData
:=
"0x82753675393576758571cbbaefada498614b4a0a967ca2dd5724eb46ecfd1c89f1e49792ebbe1866c1d6d6ceaf3054c7189751477a5b7312218eb77dcab1bfb6287c6fbf2e1c6cf8fe2ade7c17596b081dc98be785a34db5b45a5cca08e7e744"
blsInfo
.
Sign
=
common
.
FromHex
(
signData
)
blsInfo
.
Sign
,
err
=
common
.
FromHex
(
signData
)
assert
.
NoError
(
t
,
err
)
status
:=
&
pt
.
ParacrossNodeStatus
{}
status
:=
&
pt
.
ParacrossNodeStatus
{}
data
:=
"0x1a0c757365722e702e706172612e322097162f9d4a888121fdba2fb1ab402596acdbcb602121bd12284adb739d85f225"
data
:=
"0x1a0c757365722e702e706172612e322097162f9d4a888121fdba2fb1ab402596acdbcb602121bd12284adb739d85f225"
msg
:=
common
.
FromHex
(
data
)
msg
,
err
:=
common
.
FromHex
(
data
)
assert
.
NoError
(
t
,
err
)
types
.
Decode
(
msg
,
status
)
types
.
Decode
(
msg
,
status
)
commit
.
Status
=
status
commit
.
Status
=
status
commit
.
Bls
=
blsInfo
commit
.
Bls
=
blsInfo
err
:
=
client
.
verifyBlsSign
(
KS
,
commit
)
err
=
client
.
verifyBlsSign
(
KS
,
commit
)
assert
.
Equal
(
t
,
err
,
nil
)
assert
.
Equal
(
t
,
err
,
nil
)
}
}
plugin/dapp/paracross/cmd/build.sh
View file @
554b78f0
...
@@ -11,6 +11,7 @@ OUT_DIR="${1}/$strapp"
...
@@ -11,6 +11,7 @@ OUT_DIR="${1}/$strapp"
#SRC_CLI=github.com/33cn/plugin/cli
#SRC_CLI=github.com/33cn/plugin/cli
#go build -v -o "${PARACLI}" -ldflags "-X ${SRC_CLI}/buildflags.ParaName=user.p.${PARANAME}. -X ${SRC_CLI}/buildflags.RPCAddr=http://localhost:8901" "${SRC_CLI}"
#go build -v -o "${PARACLI}" -ldflags "-X ${SRC_CLI}/buildflags.ParaName=user.p.${PARANAME}. -X ${SRC_CLI}/buildflags.RPCAddr=http://localhost:8901" "${SRC_CLI}"
mkdir
-p
"
${
OUT_DIR
}
"
# shellcheck disable=SC2086
# shellcheck disable=SC2086
cp
./build/
*
"
${
OUT_DIR
}
"
cp
./build/
*
"
${
OUT_DIR
}
"
...
...
plugin/dapp/paracross/executor/action.go
View file @
554b78f0
...
@@ -12,13 +12,13 @@ import (
...
@@ -12,13 +12,13 @@ import (
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/client"
"github.com/33cn/chain33/client"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/crypto"
dbm
"github.com/33cn/chain33/common/db"
dbm
"github.com/33cn/chain33/common/db"
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util"
"github.com/33cn/chain33/util"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/proto"
"github.com/herumi/bls-eth-go-binary/bls"
"github.com/pkg/errors"
"github.com/pkg/errors"
)
)
...
@@ -413,8 +413,8 @@ func getValidAddrs(nodes map[string]struct{}, addrs []string) []string {
...
@@ -413,8 +413,8 @@ func getValidAddrs(nodes map[string]struct{}, addrs []string) []string {
}
}
//bls签名共识交易验证 大约平均耗时30ms (20~40ms)
//bls签名共识交易验证 大约平均耗时30ms (20~40ms)
func
(
a
*
action
)
verify
BlsSign
(
nodesArry
[]
string
,
commit
*
pt
.
ParacrossCommitAction
)
([]
string
,
error
)
{
func
(
a
*
action
)
proc
BlsSign
(
nodesArry
[]
string
,
commit
*
pt
.
ParacrossCommitAction
)
([]
string
,
error
)
{
//1. 获取addr对应的bls 公钥 单独耗时3ms (3 addrs)
signAddrs
:=
getAddrsByBitMap
(
nodesArry
,
commit
.
Bls
.
AddrsMap
)
signAddrs
:=
getAddrsByBitMap
(
nodesArry
,
commit
.
Bls
.
AddrsMap
)
var
pubs
[]
string
var
pubs
[]
string
for
_
,
addr
:=
range
signAddrs
{
for
_
,
addr
:=
range
signAddrs
{
...
@@ -424,7 +424,7 @@ func (a *action) verifyBlsSign(nodesArry []string, commit *pt.ParacrossCommitAct
...
@@ -424,7 +424,7 @@ func (a *action) verifyBlsSign(nodesArry []string, commit *pt.ParacrossCommitAct
}
}
pubs
=
append
(
pubs
,
pub
)
pubs
=
append
(
pubs
,
pub
)
}
}
err
:=
verifyBlsSign
Plus
(
pubs
,
commit
)
err
:=
verifyBlsSign
(
a
.
exec
.
cryptoCli
,
pubs
,
commit
)
if
err
!=
nil
{
if
err
!=
nil
{
clog
.
Error
(
"paracross.Commit bls sign verify"
,
"addr"
,
signAddrs
,
"nodes"
,
nodesArry
,
"from"
,
a
.
fromaddr
)
clog
.
Error
(
"paracross.Commit bls sign verify"
,
"addr"
,
signAddrs
,
"nodes"
,
nodesArry
,
"from"
,
a
.
fromaddr
)
return
nil
,
err
return
nil
,
err
...
@@ -432,14 +432,16 @@ func (a *action) verifyBlsSign(nodesArry []string, commit *pt.ParacrossCommitAct
...
@@ -432,14 +432,16 @@ func (a *action) verifyBlsSign(nodesArry []string, commit *pt.ParacrossCommitAct
return
signAddrs
,
nil
return
signAddrs
,
nil
}
}
func
verifyBlsSign
Plus
(
pubs
[]
string
,
commit
*
pt
.
ParacrossCommitAction
)
error
{
func
verifyBlsSign
(
cryptoCli
crypto
.
Crypto
,
pubs
[]
string
,
commit
*
pt
.
ParacrossCommitAction
)
error
{
t1
:=
types
.
Now
()
t1
:=
types
.
Now
()
//
单独deserial 90us, g2pubs的公钥结构不好整合到protobuf,就不好压缩到数据库直接读取
//
1. 获取addr对应的bls 公钥
pubKeys
:=
make
([]
bls
.
Public
Key
,
0
)
pubKeys
:=
make
([]
crypto
.
Pub
Key
,
0
)
for
_
,
p
:=
range
pubs
{
for
_
,
p
:=
range
pubs
{
k
,
err
:=
common
.
FromHex
(
p
)
var
pub
bls
.
PublicKey
if
err
!=
nil
{
err
:=
pub
.
DeserializeHexStr
(
p
)
return
errors
.
Wrapf
(
err
,
"pub FromHex=%s"
,
p
)
}
pub
,
err
:=
cryptoCli
.
PubKeyFromBytes
(
k
)
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"DeserializePublicKey=%s"
,
p
)
return
errors
.
Wrapf
(
err
,
"DeserializePublicKey=%s"
,
p
)
}
}
...
@@ -447,21 +449,26 @@ func verifyBlsSignPlus(pubs []string, commit *pt.ParacrossCommitAction) error {
...
@@ -447,21 +449,26 @@ func verifyBlsSignPlus(pubs []string, commit *pt.ParacrossCommitAction) error {
}
}
//3. 获取聚合的签名, deserial 300us
//2. 获取聚合的签名, deserial 300us
var
sign
bls
.
Sign
sign
,
err
:=
cryptoCli
.
SignatureFromBytes
(
commit
.
Bls
.
Sign
)
err
:=
sign
.
Deserialize
(
commit
.
Bls
.
Sign
)
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"DeserializeSignature,key=%s"
,
common
.
ToHex
(
commit
.
Bls
.
Sign
))
return
errors
.
Wrapf
(
err
,
"DeserializeSignature,key=%s"
,
common
.
ToHex
(
commit
.
Bls
.
Sign
))
}
}
//
4
. 获取签名前原始msg
//
3
. 获取签名前原始msg
msg
:=
types
.
Encode
(
commit
.
Status
)
msg
:=
types
.
Encode
(
commit
.
Status
)
//verify 1ms, total 2ms
if
!
sign
.
FastAggregateVerify
(
pubKeys
,
msg
)
{
//4. verify 1ms, total 2ms
agg
,
err
:=
crypto
.
ToAggregate
(
cryptoCli
)
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"ToAggregate"
)
}
err
=
agg
.
VerifyAggregatedOne
(
pubKeys
,
msg
,
sign
)
if
err
!=
nil
{
clog
.
Error
(
"paracross.Commit bls sign verify"
,
"title"
,
commit
.
Status
.
Title
,
"height"
,
commit
.
Status
.
Height
,
clog
.
Error
(
"paracross.Commit bls sign verify"
,
"title"
,
commit
.
Status
.
Title
,
"height"
,
commit
.
Status
.
Height
,
"addrsMap"
,
common
.
ToHex
(
commit
.
Bls
.
AddrsMap
),
"sign"
,
common
.
ToHex
(
commit
.
Bls
.
Sign
),
"data"
,
common
.
ToHex
(
msg
))
"addrsMap"
,
common
.
ToHex
(
commit
.
Bls
.
AddrsMap
),
"sign"
,
common
.
ToHex
(
commit
.
Bls
.
Sign
),
"data"
,
common
.
ToHex
(
msg
))
return
pt
.
ErrBlsSignVerify
return
pt
.
ErrBlsSignVerify
}
}
clog
.
Info
(
"paracross
verify
BlsSign success"
,
"title"
,
commit
.
Status
.
Title
,
"height"
,
commit
.
Status
.
Height
,
"time"
,
types
.
Since
(
t1
))
clog
.
Info
(
"paracross
proc
BlsSign success"
,
"title"
,
commit
.
Status
.
Title
,
"height"
,
commit
.
Status
.
Height
,
"time"
,
types
.
Since
(
t1
))
return
nil
return
nil
}
}
...
@@ -484,9 +491,9 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
...
@@ -484,9 +491,9 @@ func (a *action) Commit(commit *pt.ParacrossCommitAction) (*types.Receipt, error
//获取commitAddrs, bls sign 包含多个账户的聚合签名
//获取commitAddrs, bls sign 包含多个账户的聚合签名
commitAddrs
:=
[]
string
{
a
.
fromaddr
}
commitAddrs
:=
[]
string
{
a
.
fromaddr
}
if
commit
.
Bls
!=
nil
{
if
commit
.
Bls
!=
nil
{
addrs
,
err
:=
a
.
verify
BlsSign
(
nodesArry
,
commit
)
addrs
,
err
:=
a
.
proc
BlsSign
(
nodesArry
,
commit
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
Wrap
(
err
,
"
verify
BlsSign"
)
return
nil
,
errors
.
Wrap
(
err
,
"
proc
BlsSign"
)
}
}
commitAddrs
=
addrs
commitAddrs
=
addrs
}
}
...
...
plugin/dapp/paracross/executor/paracross.go
View file @
554b78f0
...
@@ -9,22 +9,24 @@ import (
...
@@ -9,22 +9,24 @@ import (
"encoding/hex"
"encoding/hex"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common"
"github.com/33cn/chain33/common/crypto"
log
"github.com/33cn/chain33/common/log/log15"
log
"github.com/33cn/chain33/common/log/log15"
drivers
"github.com/33cn/chain33/system/dapp"
drivers
"github.com/33cn/chain33/system/dapp"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util"
"github.com/33cn/chain33/util"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/herumi/bls-eth-go-binary/bls"
)
)
var
(
var
(
clog
=
log
.
New
(
"module"
,
"execs.paracross"
)
clog
=
log
.
New
(
"module"
,
"execs.paracross"
)
enableParacrossTransfer
=
true
enableParacrossTransfer
=
true
driverName
=
pt
.
ParaX
driverName
=
pt
.
ParaX
blsSignName
=
"bls"
)
)
// Paracross exec
// Paracross exec
type
Paracross
struct
{
type
Paracross
struct
{
cryptoCli
crypto
.
Crypto
drivers
.
DriverBase
drivers
.
DriverBase
}
}
...
@@ -33,7 +35,6 @@ func Init(name string, cfg *types.Chain33Config, sub []byte) {
...
@@ -33,7 +35,6 @@ func Init(name string, cfg *types.Chain33Config, sub []byte) {
drivers
.
Register
(
cfg
,
GetName
(),
newParacross
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
drivers
.
Register
(
cfg
,
GetName
(),
newParacross
,
cfg
.
GetDappFork
(
driverName
,
"Enable"
))
InitExecType
()
InitExecType
()
setPrefix
()
setPrefix
()
bls
.
Init
(
bls
.
BLS12_381
)
}
}
func
InitExecType
()
{
func
InitExecType
()
{
...
@@ -50,6 +51,11 @@ func newParacross() drivers.Driver {
...
@@ -50,6 +51,11 @@ func newParacross() drivers.Driver {
c
:=
&
Paracross
{}
c
:=
&
Paracross
{}
c
.
SetChild
(
c
)
c
.
SetChild
(
c
)
c
.
SetExecutorType
(
types
.
LoadExecutorType
(
driverName
))
c
.
SetExecutorType
(
types
.
LoadExecutorType
(
driverName
))
cli
,
err
:=
crypto
.
New
(
"bls"
)
if
err
!=
nil
{
panic
(
"paracross need bls sign register"
)
}
c
.
cryptoCli
=
cli
return
c
return
c
}
}
...
...
plugin/dapp/paracross/executor/paracross_test.go
View file @
554b78f0
...
@@ -20,7 +20,6 @@ import (
...
@@ -20,7 +20,6 @@ import (
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/types"
"github.com/33cn/plugin/plugin/dapp/paracross/testnode"
"github.com/33cn/plugin/plugin/dapp/paracross/testnode"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
pt
"github.com/33cn/plugin/plugin/dapp/paracross/types"
"github.com/herumi/bls-eth-go-binary/bls"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/suite"
"github.com/stretchr/testify/suite"
...
@@ -828,7 +827,8 @@ func TestValidParaCrossExec(t *testing.T) {
...
@@ -828,7 +827,8 @@ func TestValidParaCrossExec(t *testing.T) {
}
}
func
TestVerifyBlsSign
(
t
*
testing
.
T
)
{
func
TestVerifyBlsSign
(
t
*
testing
.
T
)
{
bls
.
Init
(
bls
.
BLS12_381
)
cryptoCli
,
err
:=
crypto
.
New
(
"bls"
)
assert
.
NoError
(
t
,
err
)
status
:=
&
pt
.
ParacrossNodeStatus
{}
status
:=
&
pt
.
ParacrossNodeStatus
{}
status
.
Height
=
0
status
.
Height
=
0
...
@@ -837,36 +837,42 @@ func TestVerifyBlsSign(t *testing.T) {
...
@@ -837,36 +837,42 @@ func TestVerifyBlsSign(t *testing.T) {
blsInfo
:=
&
pt
.
ParacrossCommitBlsInfo
{}
blsInfo
:=
&
pt
.
ParacrossCommitBlsInfo
{}
commit
:=
&
pt
.
ParacrossCommitAction
{
Status
:
status
,
Bls
:
blsInfo
}
commit
:=
&
pt
.
ParacrossCommitAction
{
Status
:
status
,
Bls
:
blsInfo
}
PriKS
:=
"0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
priKSStr
:=
"0x6da92a632ab7deb67d38c0f6560bcfed28167998f6496db64c258d5e8393a81b"
PriJR
:=
"0x19c069234f9d3e61135fefbeb7791b149cdf6af536f26bebb310d4cd22c3fee4"
p
,
err
:=
common
.
FromHex
(
priKSStr
)
var
priKeyKs
bls
.
SecretKey
assert
.
NoError
(
t
,
err
)
var
prikeyJr
bls
.
SecretKey
priKS
,
err
:=
cryptoCli
.
PrivKeyFromBytes
(
p
)
//set hex 支持有0x前缀的,unserial支持无前缀的
assert
.
NoError
(
t
,
err
)
priKeyKs
.
SetHexString
(
PriKS
)
prikeyJr
.
SetHexString
(
PriJR
)
priJRStr
:=
"0x19c069234f9d3e61135fefbeb7791b149cdf6af536f26bebb310d4cd22c3fee4"
signKs
:=
priKeyKs
.
SignByte
(
msg
)
p
,
err
=
common
.
FromHex
(
priJRStr
)
signJr
:=
prikeyJr
.
SignByte
(
msg
)
assert
.
NoError
(
t
,
err
)
pubKs
:=
priKeyKs
.
GetPublicKey
()
priJR
,
err
:=
cryptoCli
.
PrivKeyFromBytes
(
p
)
pubJr
:=
prikeyJr
.
GetPublicKey
()
assert
.
NoError
(
t
,
err
)
var
si
bls
.
Sign
si
.
Aggregate
([]
bls
.
Sign
{
*
signKs
,
*
signJr
})
signKs
:=
priKS
.
Sign
(
msg
)
pubs
:=
[]
bls
.
PublicKey
{
*
pubKs
,
*
pubJr
}
signJr
:=
priJR
.
Sign
(
msg
)
pubKs
:=
priKS
.
PubKey
()
ret
:=
si
.
FastAggregateVerify
(
pubs
,
msg
)
pubJr
:=
priJR
.
PubKey
()
assert
.
Equal
(
t
,
true
,
ret
)
agg
,
err
:=
crypto
.
ToAggregate
(
cryptoCli
)
blsInfo
.
Sign
=
append
(
blsInfo
.
Sign
,
si
.
Serialize
()
...
)
assert
.
NoError
(
t
,
err
)
blsInfo
.
AddrsMap
=
[]
byte
{
0x3
}
aggSigns
,
err
:=
agg
.
Aggregate
([]
crypto
.
Signature
{
signKs
,
signJr
})
assert
.
NoError
(
t
,
err
)
pubs
:=
[]
crypto
.
PubKey
{
pubKs
,
pubJr
}
err
=
agg
.
VerifyAggregatedOne
(
pubs
,
msg
,
aggSigns
)
assert
.
NoError
(
t
,
err
)
blsInfo
.
Sign
=
aggSigns
.
Bytes
()
PubKS
:=
"a3d97d4186c80268fe6d3689dd574599e25df2dffdcff03f7d8ef64a3bd483241b7d0985958990de2d373d5604caf805"
PubKS
:=
"a3d97d4186c80268fe6d3689dd574599e25df2dffdcff03f7d8ef64a3bd483241b7d0985958990de2d373d5604caf805"
PubJR
:=
"81307df1fdde8f0e846ed1542c859c1e9daba2553e62e48db0877329c5c63fb86e70b9e2e83263da0eb7fcad275857f8"
PubJR
:=
"81307df1fdde8f0e846ed1542c859c1e9daba2553e62e48db0877329c5c63fb86e70b9e2e83263da0eb7fcad275857f8"
pubKeys
:=
[]
string
{
PubJR
,
PubKS
}
pubKeys
:=
[]
string
{
PubJR
,
PubKS
}
err
:=
verifyBlsSignPlus
(
pubKeys
,
commit
)
err
=
verifyBlsSign
(
cryptoCli
,
pubKeys
,
commit
)
assert
.
Equal
(
t
,
nil
,
err
)
assert
.
Equal
(
t
,
nil
,
err
)
blsInfo
.
Sign
=
signKs
.
Serialize
()
blsInfo
.
Sign
=
signKs
.
Bytes
()
blsInfo
.
AddrsMap
=
[]
byte
{
0x3
}
pubKeys
=
[]
string
{
PubKS
}
pubKeys
=
[]
string
{
PubKS
}
err
=
verifyBlsSign
Plus
(
pubKeys
,
commit
)
err
=
verifyBlsSign
(
cryptoCli
,
pubKeys
,
commit
)
assert
.
Equal
(
t
,
nil
,
err
)
assert
.
Equal
(
t
,
nil
,
err
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment