diff options
author | Determinant <[email protected]> | 2018-07-27 17:33:23 -0400 |
---|---|---|
committer | Determinant <[email protected]> | 2018-07-27 17:33:23 -0400 |
commit | ec6a1f84324faf8e7c92f32137464db57410f58a (patch) | |
tree | 10a0f289a255eb5c78be2cb4a5e2702fc7995182 /src | |
parent | 5f00c067f863f812a740dc209b1fb829f04042eb (diff) |
fix signature verification bug
Diffstat (limited to 'src')
-rw-r--r-- | src/consensus.cpp | 2 | ||||
-rw-r--r-- | src/crypto.cpp | 17 | ||||
-rw-r--r-- | src/hotstuff.cpp | 9 | ||||
-rw-r--r-- | src/hotstuff_client.cpp | 2 |
4 files changed, 14 insertions, 16 deletions
diff --git a/src/consensus.cpp b/src/consensus.cpp index 57152f0..ac7e56a 100644 --- a/src/consensus.cpp +++ b/src/consensus.cpp @@ -125,7 +125,7 @@ void HotStuffCore::on_propose(const std::vector<command_t> &cmds, } /* create the new block */ block_t bnew = storage->add_blk( - Block( + new Block( parents, cmds, p->height + 1, diff --git a/src/crypto.cpp b/src/crypto.cpp index 560a8ac..88c2f57 100644 --- a/src/crypto.cpp +++ b/src/crypto.cpp @@ -8,19 +8,22 @@ secp256k1_context_t secp256k1_default_verify_ctx = new Secp256k1Context(false); QuorumCertSecp256k1::QuorumCertSecp256k1( const ReplicaConfig &config, const uint256_t &blk_hash): - QuorumCert(), blk_hash(blk_hash), rids(config.nmajority) { + QuorumCert(), blk_hash(blk_hash), rids(config.nreplicas) { rids.clear(); } bool QuorumCertSecp256k1::verify(const ReplicaConfig &config) { - bytearray_t _blk_hash(blk_hash); - if (rids.size() < config.nmajority) return false; + if (sigs.size() < config.nmajority) return false; for (size_t i = 0; i < rids.size(); i++) - if (!sigs[i].verify(_blk_hash, - static_cast<const PubKeySecp256k1 &>(config.get_pubkey(rids.get(i))), - secp256k1_default_verify_ctx - )) + if (rids.get(i)) + { + HOTSTUFF_LOG_DEBUG("checking cert(%d), blk_hash=%s", + i, get_hex10(blk_hash).c_str()); + if (!sigs[i].verify(blk_hash, + static_cast<const PubKeySecp256k1 &>(config.get_pubkey(i)), + secp256k1_default_verify_ctx)) return false; + } return true; } diff --git a/src/hotstuff.cpp b/src/hotstuff.cpp index 43da8a8..c01f2f3 100644 --- a/src/hotstuff.cpp +++ b/src/hotstuff.cpp @@ -53,13 +53,7 @@ void MsgRespBlock::postponed_parse(HotStuffCore *hsc) { { Block _blk; _blk.unserialize(serialized, hsc); - if (!_blk.verify(hsc->get_config())) - blk = hsc->storage->add_blk(std::move(_blk)); - else - { - blk = nullptr; - LOG_WARN("block is invalid"); - } + blk = hsc->storage->add_blk(std::move(_blk), hsc->get_config()); } } @@ -244,6 +238,7 @@ void HotStuffBase::propose_handler(MsgPropose &&msg, conn_t conn) { msg.postponed_parse(this); auto &prop = msg.proposal; block_t blk = prop.blk; + if (!blk) return; promise::all(std::vector<promise_t>{ async_deliver_blk(prop.bqc_hash, peer), async_deliver_blk(blk->get_hash(), peer), diff --git a/src/hotstuff_client.cpp b/src/hotstuff_client.cpp index c1e7ea4..e213e78 100644 --- a/src/hotstuff_client.cpp +++ b/src/hotstuff_client.cpp @@ -67,7 +67,7 @@ void try_send() { void client_resp_cmd_handler(MsgRespCmd &&msg, MsgNetwork<opcode_t>::conn_t) { auto &fin = msg.fin; - HOTSTUFF_LOG_DEBUG("got %s", std::string(msg).c_str()); + HOTSTUFF_LOG_DEBUG("got %s", std::string(msg.fin).c_str()); const uint256_t &cmd_hash = fin.cmd_hash; auto it = waiting.find(cmd_hash); if (fin.rid != proposer) |