Skip to content

Commit c2f5140

Browse files
authored
Remove rust_bridge checkValid roundtrip (#4921)
# Description Resolves stellar/stellar-core-internal#376 # Checklist - [x] Reviewed the [contributing](https://github.com/stellar/stellar-core/blob/master/CONTRIBUTING.md#submitting-changes) document - [x] Rebased on top of master (no merge commits) - [x] Ran `clang-format` v8.0.0 (via `make format` or the Visual Studio extension) - [x] Compiles - [x] Ran all tests - [ ] If change impacts performance, include supporting evidence per the [performance document](https://github.com/stellar/stellar-core/blob/master/performance-eval/performance-eval.md)
2 parents f5fba53 + 4287224 commit c2f5140

File tree

5 files changed

+4
-145
lines changed

5 files changed

+4
-145
lines changed

src/transactions/FeeBumpTransactionFrame.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "util/GlobalChecks.h"
2424
#include "util/ProtocolVersion.h"
2525
#include "util/numeric128.h"
26+
#include "xdrpp/depth_checker.h"
2627
#include "xdrpp/marshal.h"
2728

2829
#include <numeric>
@@ -248,9 +249,7 @@ FeeBumpTransactionFrame::checkValid(
248249
uint64_t lowerBoundCloseTimeOffset, uint64_t upperBoundCloseTimeOffset,
249250
DiagnosticEventManager& diagnosticEvents) const
250251
{
251-
if (!checkVNext(ls.getLedgerHeader().current().ledgerVersion,
252-
app.getConfig(), mEnvelope) ||
253-
!XDRProvidesValidFee())
252+
if (!xdr::check_xdr_depth(mEnvelope, 500) || !XDRProvidesValidFee())
254253
{
255254
return FeeBumpMutableTransactionResult::createTxError(txMALFORMED);
256255
}

src/transactions/TransactionFrame.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "util/XDRStream.h"
4141
#include "xdr/Stellar-contract.h"
4242
#include "xdr/Stellar-ledger.h"
43+
#include "xdrpp/depth_checker.h"
4344
#include "xdrpp/marshal.h"
4445
#include "xdrpp/printer.h"
4546
#include <Tracy.hpp>
@@ -1725,8 +1726,7 @@ TransactionFrame::checkValid(AppConnector& app, LedgerSnapshot const& ls,
17251726
// `checkValidWithOptionallyChargedFee` in order to not validate the
17261727
// envelope XDR twice for the fee bump transactions (they use
17271728
// `checkValidWithOptionallyChargedFee` for the inner tx).
1728-
if (!checkVNext(ls.getLedgerHeader().current().ledgerVersion,
1729-
app.getConfig(), mEnvelope))
1729+
if (!xdr::check_xdr_depth(mEnvelope, 500))
17301730
{
17311731
return MutableTransactionResult::createTxError(txMALFORMED);
17321732
}

src/transactions/TransactionUtils.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2164,22 +2164,6 @@ hasMuxedAccount(TransactionEnvelope const& e)
21642164
return c.mHasMuxedAccount;
21652165
}
21662166

2167-
bool
2168-
checkVNext(uint32_t currProtocol, Config const& cfg,
2169-
TransactionEnvelope const& envelope)
2170-
{
2171-
uint32_t maxProtocol = cfg.CURRENT_LEDGER_PROTOCOL_VERSION;
2172-
if (!xdr::check_xdr_depth(envelope, 500))
2173-
{
2174-
return false;
2175-
}
2176-
2177-
auto cxxBuf = CxxBuf{
2178-
std::make_unique<std::vector<uint8_t>>(xdr::xdr_to_opaque(envelope))};
2179-
return rust_bridge::can_parse_transaction(maxProtocol, currProtocol, cxxBuf,
2180-
1000);
2181-
}
2182-
21832167
ClaimAtom
21842168
makeClaimAtom(uint32_t ledgerVersion, AccountID const& accountID,
21852169
int64_t offerID, Asset const& wheat, int64_t numWheatReceived,

src/transactions/TransactionUtils.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,6 @@ bool accountFlagMaskCheckIsValid(uint32_t flag, uint32_t ledgerVersion);
262262

263263
bool hasMuxedAccount(TransactionEnvelope const& e);
264264

265-
bool checkVNext(uint32_t currProtocol, Config const& cfg,
266-
TransactionEnvelope const& envelope);
267-
268265
uint64_t getUpperBoundCloseTimeOffset(Application& app, uint64_t lastCloseTime);
269266

270267
bool hasAccountEntryExtV2(AccountEntry const& ae);

src/transactions/test/TxEnvelopeTests.cpp

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,127 +2496,6 @@ TEST_CASE("soroban txs not allowed before protocol upgrade",
24962496
REQUIRE(!tx->checkValidForTesting(app->getAppConnector(), ltx, 0, 0, 0));
24972497
REQUIRE(tx->getResultCode() == txMALFORMED);
24982498
}
2499-
2500-
TEST_CASE("XDR protocol 22 compatibility validation", "[tx][envelope]")
2501-
{
2502-
auto validateTx = [](ProtocolVersion protocolVersion) {
2503-
VirtualClock clock;
2504-
auto cfg = getTestConfig();
2505-
cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION =
2506-
static_cast<uint32_t>(protocolVersion);
2507-
auto app = createTestApplication(clock, cfg);
2508-
auto root = app->getRoot();
2509-
Operation op;
2510-
op.body.type(INVOKE_HOST_FUNCTION);
2511-
op.body.invokeHostFunctionOp().hostFunction.type(
2512-
HOST_FUNCTION_TYPE_CREATE_CONTRACT_V2);
2513-
2514-
auto tx =
2515-
sorobanTransactionFrameFromOps(app->getNetworkID(), *root, {op}, {},
2516-
SorobanResources(), 1000, 1'000'000);
2517-
LedgerTxn ltx(app->getLedgerTxnRoot());
2518-
return tx->checkValid(app->getAppConnector(), ltx, 0, 0, 0);
2519-
};
2520-
SECTION("not valid in protocol 21")
2521-
{
2522-
auto res = validateTx(ProtocolVersion::V_21);
2523-
REQUIRE(res->getResultCode() == txMALFORMED);
2524-
}
2525-
SECTION("valid in protocol 22")
2526-
{
2527-
auto res = validateTx(ProtocolVersion::V_22);
2528-
REQUIRE(res->isSuccess());
2529-
}
2530-
}
2531-
2532-
TEST_CASE("XDR protocol 23 compatibility validation", "[tx][envelope]")
2533-
{
2534-
auto runTest = [](ProtocolVersion protocolVersion, bool expectSuccess) {
2535-
VirtualClock clock;
2536-
auto cfg = getTestConfig();
2537-
cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION =
2538-
static_cast<uint32_t>(protocolVersion);
2539-
auto app = createTestApplication(clock, cfg);
2540-
auto root = app->getRoot();
2541-
Operation op;
2542-
op.body.type(INVOKE_HOST_FUNCTION);
2543-
op.body.invokeHostFunctionOp().hostFunction.type(
2544-
HOST_FUNCTION_TYPE_INVOKE_CONTRACT);
2545-
2546-
LedgerSnapshot ls(*app);
2547-
SECTION("muxed account ScAddress in function args")
2548-
{
2549-
auto& val = op.body.invokeHostFunctionOp()
2550-
.hostFunction.invokeContract()
2551-
.args.emplace_back();
2552-
val.type(SCV_ADDRESS);
2553-
val.address().type(SC_ADDRESS_TYPE_MUXED_ACCOUNT);
2554-
val.address().muxedAccount().id = 123;
2555-
auto tx = sorobanTransactionFrameFromOps(
2556-
app->getNetworkID(), *root, {op}, {}, SorobanResources(), 1000,
2557-
1'000'000);
2558-
2559-
auto res = tx->checkValid(app->getAppConnector(), ls, 0, 0, 0);
2560-
REQUIRE(res->isSuccess() == expectSuccess);
2561-
if (!expectSuccess)
2562-
{
2563-
REQUIRE(res->getResultCode() == txMALFORMED);
2564-
}
2565-
}
2566-
SECTION("claimable balance ScAddress in auth")
2567-
{
2568-
auto& authEntry =
2569-
op.body.invokeHostFunctionOp().auth.emplace_back();
2570-
authEntry.rootInvocation.function.type(
2571-
SOROBAN_AUTHORIZED_FUNCTION_TYPE_CONTRACT_FN);
2572-
auto& address =
2573-
authEntry.rootInvocation.function.contractFn().contractAddress;
2574-
address.type(SC_ADDRESS_TYPE_CLAIMABLE_BALANCE);
2575-
address.claimableBalanceId().v0()[0] = 1;
2576-
auto tx = sorobanTransactionFrameFromOps(
2577-
app->getNetworkID(), *root, {op}, {}, SorobanResources(), 1000,
2578-
1'000'000);
2579-
auto res = tx->checkValid(app->getAppConnector(), ls, 0, 0, 0);
2580-
REQUIRE(res->isSuccess() == expectSuccess);
2581-
if (!expectSuccess)
2582-
{
2583-
REQUIRE(res->getResultCode() == txMALFORMED);
2584-
}
2585-
}
2586-
SECTION("liquidity pool ScAddress in footprint")
2587-
{
2588-
Operation ttlOp;
2589-
ttlOp.body.type(EXTEND_FOOTPRINT_TTL);
2590-
2591-
SorobanResources resources;
2592-
auto& key = resources.footprint.readOnly.emplace_back();
2593-
key.type(CONTRACT_DATA);
2594-
auto& address = key.contractData().contract;
2595-
2596-
address.type(SC_ADDRESS_TYPE_LIQUIDITY_POOL);
2597-
address.liquidityPoolId()[1] = 10;
2598-
auto tx = sorobanTransactionFrameFromOps(app->getNetworkID(), *root,
2599-
{ttlOp}, {}, resources,
2600-
1000, 1'000'000);
2601-
auto res = tx->checkValid(app->getAppConnector(), ls, 0, 0, 0);
2602-
REQUIRE(res->isSuccess() == expectSuccess);
2603-
if (!expectSuccess)
2604-
{
2605-
REQUIRE(res->getResultCode() == txMALFORMED);
2606-
}
2607-
}
2608-
};
2609-
2610-
SECTION("not valid in protocol 22")
2611-
{
2612-
runTest(ProtocolVersion::V_22, false);
2613-
}
2614-
SECTION("valid in protocol 23")
2615-
{
2616-
runTest(ProtocolVersion::V_23, true);
2617-
}
2618-
}
2619-
26202499
TEST_CASE_VERSIONS("Soroban extension for non-Soroban tx",
26212500
"[tx][envelope][soroban]")
26222501
{

0 commit comments

Comments
 (0)