Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

Consensus fuzzing #1840

Merged
merged 2 commits into from
Nov 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions test/fuzzing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,11 @@ target_link_libraries(request_proposal_fuzz
on_demand_ordering_service_transport_grpc
protobuf-mutator
)

add_executable(consensus_fuzz consensus_fuzz.cpp)
target_link_libraries(consensus_fuzz
gtest::gtest
gmock::gmock
yac_transport
protobuf-mutator
)
54 changes: 54 additions & 0 deletions test/fuzzing/consensus_fuzz.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#include <memory>

#include <gtest/gtest.h>
#include <libfuzzer/libfuzzer_macro.h>

#include "consensus/yac/transport/impl/network_impl.hpp"
#include "module/irohad/consensus/yac/yac_mocks.hpp"

using namespace testing;

namespace fuzzing {
struct ConsensusFixture {
std::shared_ptr<
NiceMock<iroha::consensus::yac::MockYacNetworkNotifications>>
notifications_;
std::shared_ptr<iroha::network::AsyncGrpcClient<google::protobuf::Empty>>
async_call_;
std::shared_ptr<iroha::consensus::yac::NetworkImpl> network_;

ConsensusFixture() {
spdlog::set_level(spdlog::level::critical);

notifications_ = std::make_shared<
NiceMock<iroha::consensus::yac::MockYacNetworkNotifications>>();
async_call_ = std::make_shared<
iroha::network::AsyncGrpcClient<google::protobuf::Empty>>();
network_ =
std::make_shared<iroha::consensus::yac::NetworkImpl>(async_call_);
network_->subscribe(notifications_);
}
};
} // namespace fuzzing

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, std::size_t size) {
static fuzzing::ConsensusFixture fixture;

if (size < 1) {
return 0;
}

iroha::consensus::yac::proto::State request;
if (protobuf_mutator::libfuzzer::LoadProtoInput(true, data, size, &request)) {
grpc::ServerContext context;
google::protobuf::Empty response;
fixture.network_->SendState(&context, &request, &response);
}

return 0;
}
61 changes: 33 additions & 28 deletions test/fuzzing/ordering_gate_fuzz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,43 @@
using namespace iroha::ordering;
using namespace testing;

struct OrderingGateFixture {
std::shared_ptr<shared_model::proto::ProtoBlockFactory> block_factory_;
std::shared_ptr<NiceMock<MockOnDemandOrderingService>> ordering_service_;
std::shared_ptr<NiceMock<transport::MockOdOsNotification>> network_client_;
namespace fuzzing {
struct OrderingGateFixture {
std::shared_ptr<shared_model::proto::ProtoBlockFactory> block_factory_;
std::shared_ptr<NiceMock<MockOnDemandOrderingService>> ordering_service_;
std::shared_ptr<NiceMock<transport::MockOdOsNotification>> network_client_;

rxcpp::subjects::subject<OnDemandOrderingGate::BlockRoundEventType> rounds_;
NiceMock<MockUnsafeProposalFactory> *proposal_factory_;
std::shared_ptr<OnDemandOrderingGate> ordering_gate_;
iroha::consensus::Round initial_round_ = {2, 1};
rxcpp::subjects::subject<OnDemandOrderingGate::BlockRoundEventType> rounds_;
NiceMock<MockUnsafeProposalFactory> *proposal_factory_;
std::shared_ptr<OnDemandOrderingGate> ordering_gate_;
iroha::consensus::Round initial_round_ = {2, 1};

OrderingGateFixture()
: block_factory_(std::make_shared<shared_model::proto::ProtoBlockFactory>(
std::make_unique<
shared_model::validation::DefaultUnsignedBlockValidator>())),
ordering_service_(
std::make_shared<NiceMock<MockOnDemandOrderingService>>()),
network_client_(
std::make_shared<NiceMock<transport::MockOdOsNotification>>()) {
auto proposal_factory =
std::make_unique<NiceMock<MockUnsafeProposalFactory>>();
proposal_factory_ = proposal_factory.get();
ordering_gate_ =
std::make_shared<OnDemandOrderingGate>(ordering_service_,
network_client_,
rounds_.get_observable(),
std::move(proposal_factory),
initial_round_);
}
};
OrderingGateFixture()
: block_factory_(std::make_shared<
shared_model::proto::ProtoBlockFactory>(
std::make_unique<
shared_model::validation::DefaultUnsignedBlockValidator>())),
ordering_service_(
std::make_shared<NiceMock<MockOnDemandOrderingService>>

()),
network_client_(
std::make_shared<NiceMock<transport::MockOdOsNotification>>()) {
auto proposal_factory =
std::make_unique<NiceMock<MockUnsafeProposalFactory>>();
proposal_factory_ = proposal_factory.get();
ordering_gate_ =
std::make_shared<OnDemandOrderingGate>(ordering_service_,
network_client_,
rounds_.get_observable(),
std::move(proposal_factory),
initial_round_);
}
};
} // namespace fuzzing

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, std::size_t size) {
static OrderingGateFixture ordering_gate_fixture;
static fuzzing::OrderingGateFixture ordering_gate_fixture;
if (size < 1) {
return 0;
}
Expand Down