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
47379749
Commit
47379749
authored
May 16, 2019
by
caopingcp
Committed by
vipwzw
May 18, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update vrf usage
parent
be6fe665
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
16 deletions
+21
-16
ticket.go
plugin/consensus/ticket/ticket.go
+10
-6
ticket_test.go
plugin/consensus/ticket/ticket_test.go
+8
-3
ticketnum.go
plugin/dapp/ticket/executor/ticketnum.go
+1
-3
ticket.proto
plugin/dapp/ticket/proto/ticket.proto
+2
-4
ticket.pb.go
plugin/dapp/ticket/types/ticket.pb.go
+0
-0
No files found.
plugin/consensus/ticket/ticket.go
View file @
47379749
...
...
@@ -6,6 +6,7 @@ package ticket
import
(
"bytes"
"crypto/ecdsa"
"encoding/hex"
"errors"
"fmt"
...
...
@@ -20,13 +21,14 @@ import (
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/common/difficulty"
"github.com/33cn/chain33/common/log/log15"
vrf
"github.com/33cn/chain33/common/vrf/
p256
"
vrf
"github.com/33cn/chain33/common/vrf/
secp256k1
"
"github.com/33cn/chain33/queue"
drivers
"github.com/33cn/chain33/system/consensus"
driver
"github.com/33cn/chain33/system/dapp"
cty
"github.com/33cn/chain33/system/dapp/coins/types"
"github.com/33cn/chain33/types"
ty
"github.com/33cn/plugin/plugin/dapp/ticket/types"
secp256k1
"github.com/btcsuite/btcd/btcec"
"github.com/golang/protobuf/proto"
)
...
...
@@ -377,11 +379,12 @@ func (client *Client) CheckBlock(parent *types.Block, current *types.BlockDetail
if
input
==
nil
{
input
=
miner
.
PrivHash
}
if
err
=
vrfVerify
(
miner
.
PubKey
,
input
,
miner
.
VrfProof
,
miner
.
VrfHash
);
err
!=
nil
{
minerTx
:=
current
.
Block
.
Txs
[
0
]
if
err
=
vrfVerify
(
minerTx
.
Signature
.
Pubkey
,
input
,
miner
.
VrfProof
,
miner
.
VrfHash
);
err
!=
nil
{
return
err
}
}
else
{
if
len
(
miner
.
PubKey
)
!=
0
||
len
(
miner
.
VrfHash
)
!=
0
||
len
(
miner
.
VrfProof
)
!=
0
{
if
len
(
miner
.
VrfHash
)
!=
0
||
len
(
miner
.
VrfProof
)
!=
0
{
tlog
.
Error
(
"block error: not yet add vrf"
)
return
ty
.
ErrNoVrf
}
...
...
@@ -390,11 +393,12 @@ func (client *Client) CheckBlock(parent *types.Block, current *types.BlockDetail
}
func
vrfVerify
(
pub
[]
byte
,
input
[]
byte
,
proof
[]
byte
,
hash
[]
byte
)
error
{
vrfPub
,
err
:=
vrf
.
ParseVrfPubKey
(
pub
)
pubKey
,
err
:=
secp256k1
.
ParsePubKey
(
pub
,
secp256k1
.
S256
()
)
if
err
!=
nil
{
tlog
.
Error
(
"vrfVerify"
,
"err"
,
err
)
return
ty
.
ErrVrfVerify
}
vrfPub
:=
&
vrf
.
PublicKey
{
PublicKey
:
(
*
ecdsa
.
PublicKey
)(
pubKey
)}
vrfHash
,
err
:=
vrfPub
.
ProofToHash
(
input
,
proof
)
if
err
!=
nil
{
tlog
.
Error
(
"vrfVerify"
,
"err"
,
err
)
...
...
@@ -653,9 +657,9 @@ func (client *Client) addMinerTx(parent, block *types.Block, diff *big.Int, priv
if
input
==
nil
{
input
=
miner
.
PrivHash
}
vrfPriv
,
_
,
pubKey
:=
vrf
.
GenVrfKey
(
priv
)
privKey
,
_
:=
secp256k1
.
PrivKeyFromBytes
(
secp256k1
.
S256
(),
priv
.
Bytes
())
vrfPriv
:=
&
vrf
.
PrivateKey
{
PrivateKey
:
(
*
ecdsa
.
PrivateKey
)(
privKey
)}
vrfHash
,
vrfProof
:=
vrfPriv
.
Evaluate
(
input
)
miner
.
PubKey
=
pubKey
miner
.
VrfHash
=
vrfHash
[
:
]
miner
.
VrfProof
=
vrfProof
}
...
...
plugin/consensus/ticket/ticket_test.go
View file @
47379749
...
...
@@ -5,17 +5,19 @@
package
ticket
import
(
"crypto/ecdsa"
"fmt"
"testing"
"github.com/33cn/chain33/account"
"github.com/33cn/chain33/common/crypto"
vrf
"github.com/33cn/chain33/common/vrf/
p256
"
vrf
"github.com/33cn/chain33/common/vrf/
secp256k1
"
"github.com/33cn/chain33/queue"
"github.com/33cn/chain33/types"
"github.com/33cn/chain33/util"
"github.com/33cn/chain33/util/testnode"
ty
"github.com/33cn/plugin/plugin/dapp/ticket/types"
secp256k1
"github.com/btcsuite/btcd/btcec"
"github.com/stretchr/testify/assert"
_
"github.com/33cn/chain33/system"
...
...
@@ -170,8 +172,11 @@ func Test_vrfVerify(t *testing.T) {
assert
.
NoError
(
t
,
err
)
priv
,
err
:=
c
.
GenKey
()
assert
.
NoError
(
t
,
err
)
pub
:=
priv
.
PubKey
()
.
Bytes
()
privKey
,
_
:=
secp256k1
.
PrivKeyFromBytes
(
secp256k1
.
S256
(),
priv
.
Bytes
())
vpriv
:=
&
vrf
.
PrivateKey
{
PrivateKey
:
(
*
ecdsa
.
PrivateKey
)(
privKey
)}
vpriv
,
_
,
pubKey
:=
vrf
.
GenVrfKey
(
priv
)
m1
:=
[]
byte
(
"data1"
)
m2
:=
[]
byte
(
"data2"
)
m3
:=
[]
byte
(
"data2"
)
...
...
@@ -191,7 +196,7 @@ func Test_vrfVerify(t *testing.T) {
{
m3
,
hash3
,
proof1
,
ty
.
ErrVrfVerify
},
{
m3
,
hash1
,
proof3
,
ty
.
ErrVrfVerify
},
}
{
err
:=
vrfVerify
(
pub
Key
,
tc
.
m
,
tc
.
proof
,
tc
.
hash
[
:
])
err
:=
vrfVerify
(
pub
,
tc
.
m
,
tc
.
proof
,
tc
.
hash
[
:
])
if
got
,
want
:=
err
,
tc
.
err
;
got
!=
want
{
t
.
Errorf
(
"vrfVerify(%s, %x): %v, want %v"
,
tc
.
m
,
tc
.
proof
,
got
,
want
)
}
...
...
plugin/dapp/ticket/executor/ticketnum.go
View file @
47379749
...
...
@@ -45,7 +45,6 @@ func (ticket *Ticket) GetRandNum(blockHash []byte, blockNum int64) (types.Messag
var
ticketIds
string
var
privHashs
[]
byte
var
vrfHashs
[]
byte
var
vrfProofs
[]
byte
for
_
,
ticketAction
:=
range
txActions
{
//tlog.Debug("GetRandNum", "modify", ticketAction.GetMiner().GetModify(), "bits", ticketAction.GetMiner().GetBits(), "ticketId", ticketAction.GetMiner().GetTicketId(), "PrivHash", ticketAction.GetMiner().GetPrivHash())
...
...
@@ -54,12 +53,11 @@ func (ticket *Ticket) GetRandNum(blockHash []byte, blockNum int64) (types.Messag
ticketIds
+=
ticketAction
.
GetMiner
()
.
GetTicketId
()
privHashs
=
append
(
privHashs
,
ticketAction
.
GetMiner
()
.
GetPrivHash
()
...
)
vrfHashs
=
append
(
vrfHashs
,
ticketAction
.
GetMiner
()
.
GetVrfHash
()
...
)
vrfProofs
=
append
(
vrfProofs
,
ticketAction
.
GetMiner
()
.
GetVrfProof
()
...
)
}
newmodify
:=
fmt
.
Sprintf
(
"%s:%s:%d:%s"
,
string
(
modifies
),
ticketIds
,
bits
,
string
(
privHashs
))
if
len
(
vrfHashs
)
!=
0
{
newmodify
=
newmodify
+
":"
+
fmt
.
Sprintf
(
"%x:%x"
,
vrfHashs
,
vrfProof
s
)
newmodify
=
fmt
.
Sprintf
(
"%s:%x"
,
newmodify
,
vrfHash
s
)
}
modify
:=
common
.
Sha256
([]
byte
(
newmodify
))
...
...
plugin/dapp/ticket/proto/ticket.proto
View file @
47379749
...
...
@@ -41,12 +41,10 @@ message TicketMiner {
bytes
modify
=
4
;
//挖到区块时公开
bytes
privHash
=
5
;
//VRF公钥
bytes
pubKey
=
6
;
//VRF计算得到的hash
bytes
vrfHash
=
7
;
bytes
vrfHash
=
6
;
//VRF计算得到的proof
bytes
vrfProof
=
8
;
bytes
vrfProof
=
7
;
}
message
TicketMinerOld
{
...
...
plugin/dapp/ticket/types/ticket.pb.go
View file @
47379749
This diff is collapsed.
Click to expand it.
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