Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce trusted catchup #3615

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
34 changes: 27 additions & 7 deletions src/main/CommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,22 +502,41 @@ parseCatchup(std::string const& catchup, std::string const& hash,
throw std::runtime_error(errorMessage);
}

std::optional<Hash> validHash;
try
{
if (!hash.empty())
{
validHash = std::make_optional<Hash>(hexToBin256(hash));
}
}
catch (std::exception&)
{
throw std::runtime_error("Invalid trusted hash");
}

try
{
auto mode = extraValidation
? CatchupConfiguration::Mode::OFFLINE_COMPLETE
: CatchupConfiguration::Mode::OFFLINE_BASIC;
auto ledger = parseLedger(catchup.substr(0, separatorIndex));
if (ledger == CatchupConfiguration::CURRENT)
{
CLOG_WARNING(History,
"Catching up to `current` ledger of an untrusted "
"archive. If you want to ensure validity of replayed "
"data, pass ledger number and trusted hash instead.");
}
auto count = parseLedgerCount(catchup.substr(separatorIndex + 1));
if (hash.empty())
{
return CatchupConfiguration(ledger, count, mode);
}
else
{
return CatchupConfiguration(
{ledger, std::make_optional<Hash>(hexToBin256(hash))}, count,
mode);
releaseAssert(validHash.has_value());
return CatchupConfiguration({ledger, validHash}, count, mode);
}
}
catch (std::exception&)
Expand Down Expand Up @@ -899,14 +918,15 @@ runCatchup(CommandLineArgs const& args)
app->resetLedgerState();
lm.startNewLedger();
}
else if (hash.empty() && !forceUntrusted)
else if (hash.empty() && !forceUntrusted &&
cc.toLedger() != CatchupConfiguration::CURRENT)
{
CLOG_WARNING(
History,
std::string msg =
"Unsafe command: use --trusted-checkpoint-hashes or "
"--trusted-hash to ensure catchup integrity. If you "
"want to run untrusted catchup, use "
"--force-untrusted-catchup.");
"--force-untrusted-catchup";
throw std::runtime_error(msg);
}

Json::Value catchupInfo;
Expand Down