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>2019-04-09 13:49:52 +0800
commitee9678ab194a7daec5a7bc353d994d0dcbee2209 (patch)
treebae4b2a10b5d137d0633fe01ce6c917b9fef5749
parent307a09df8e1dd77fa551cdd000ca872603600225 (diff)
downloaddexon-ee9678ab194a7daec5a7bc353d994d0dcbee2209.tar
dexon-ee9678ab194a7daec5a7bc353d994d0dcbee2209.tar.gz
dexon-ee9678ab194a7daec5a7bc353d994d0dcbee2209.tar.bz2
dexon-ee9678ab194a7daec5a7bc353d994d0dcbee2209.tar.lz
dexon-ee9678ab194a7daec5a7bc353d994d0dcbee2209.tar.xz
dexon-ee9678ab194a7daec5a7bc353d994d0dcbee2209.tar.zst
dexon-ee9678ab194a7daec5a7bc353d994d0dcbee2209.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,