blob: 0932652822030df1cc1b5af260e4e6a4ec42295a (
plain) (
tree)
|
|
#include "hotstuff/entity.h"
#include "hotstuff/crypto.h"
namespace hotstuff {
secp256k1_context_t secp256k1_default_sign_ctx = new Secp256k1Context(true);
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.nreplicas) {
rids.clear();
}
bool QuorumCertSecp256k1::verify(const ReplicaConfig &config) {
if (sigs.size() < config.nmajority) return false;
for (size_t i = 0; i < rids.size(); i++)
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;
}
promise_t QuorumCertSecp256k1::verify(const ReplicaConfig &config, VeriPool &vpool) {
if (sigs.size() < config.nmajority)
return promise_t([](promise_t &pm) { pm.resolve(false); });
std::vector<promise_t> vpm;
for (size_t i = 0; i < rids.size(); i++)
if (rids.get(i))
{
HOTSTUFF_LOG_DEBUG("checking cert(%d), blk_hash=%s",
i, get_hex10(blk_hash).c_str());
vpm.push_back(vpool.verify(new Secp256k1VeriTask(blk_hash,
static_cast<const PubKeySecp256k1 &>(config.get_pubkey(i)),
sigs[i])));
}
return promise::all(vpm).then([](const promise::values_t &values) {
for (const auto &v: values)
if (!promise::any_cast<bool>(v)) return false;
return true;
});
}
}
|