aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei-Ning Huang <w@cobinhood.com>2018-10-11 14:05:09 +0800
committerWei-Ning Huang <w@dexon.org>2018-12-19 20:54:27 +0800
commit2d7f7f8794ab3f43f8689e2aaea50c19c5896f8d (patch)
treef7eeca389748107100e93d10340ad1fe944d7dc1
parentbe4c7d41f98d1c6d6bd37a00ab47dff9f846f02f (diff)
downloaddexon-2d7f7f8794ab3f43f8689e2aaea50c19c5896f8d.tar
dexon-2d7f7f8794ab3f43f8689e2aaea50c19c5896f8d.tar.gz
dexon-2d7f7f8794ab3f43f8689e2aaea50c19c5896f8d.tar.bz2
dexon-2d7f7f8794ab3f43f8689e2aaea50c19c5896f8d.tar.lz
dexon-2d7f7f8794ab3f43f8689e2aaea50c19c5896f8d.tar.xz
dexon-2d7f7f8794ab3f43f8689e2aaea50c19c5896f8d.tar.zst
dexon-2d7f7f8794ab3f43f8689e2aaea50c19c5896f8d.zip
core: vm: check pk ownership in stake()
-rw-r--r--core/vm/governance.go13
1 files changed, 12 insertions, 1 deletions
diff --git a/core/vm/governance.go b/core/vm/governance.go
index e4c3b31e3..b78d1bf94 100644
--- a/core/vm/governance.go
+++ b/core/vm/governance.go
@@ -1182,7 +1182,18 @@ func (g *GovernanceContract) stake(publicKey []byte) ([]byte, error) {
return nil, errExecutionReverted
}
- // TODO(w): check of pk belongs to the address.
+ pk, err := crypto.DecompressPubkey(publicKey)
+ if err != nil {
+ g.penalize()
+ return nil, errExecutionReverted
+ }
+
+ // Make sure the public key belongs to the caller.
+ if crypto.PubkeyToAddress(*pk) != caller {
+ g.penalize()
+ return nil, errExecutionReverted
+ }
+
offset = g.state.nodesLength()
g.state.pushNode(&nodeInfo{
owner: caller,