Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
240 changes: 189 additions & 51 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,3 @@ endif # ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION
if ENABLE_FASTDEV_UNSAFE_FOR_PRODUCTION
AM_CPPFLAGS += -DENABLE_FASTDEV_UNSAFE_FOR_PRODUCTION
endif # ENABLE_FASTDEV_UNSAFE_FOR_PRODUCTION

if CAP_0084_MUXED_CONTRACT
AM_CPPFLAGS += -DCAP_0084_MUXED_CONTRACT
endif # CAP_0084_MUXED_CONTRACT
3 changes: 0 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -618,9 +618,6 @@ AS_IF([test "x$enable_fastdev_unsafe_for_production" = "xyes"], [
AM_CONDITIONAL(ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION,
[test x$enable_next_protocol_version_unsafe_for_production = xyes])

AM_CONDITIONAL(CAP_0084_MUXED_CONTRACT,
[test x$enable_next_protocol_version_unsafe_for_production = xyes])

AC_PATH_PROG(CARGO, cargo)
if test x"$CARGO" = x; then
AC_MSG_ERROR([cannot find cargo, needed for rust code])
Expand Down
11 changes: 5 additions & 6 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ BUILT_SOURCES = $(SRC_X_FILES:.x=.h) $(GENERATED_VERSION_SOURCES) $(TEST_FILES)

$(SRC_X_FILES:.x=.h): $(XDRC) Makefile
XDR_FEATURE_FLAGS =
if CAP_0084_MUXED_CONTRACT
XDR_FEATURE_FLAGS += -DCAP_0084_MUXED_CONTRACT
endif

SUFFIXES = .x .h .rs
.x.h:
Expand Down Expand Up @@ -235,11 +232,13 @@ SOROBAN_BUILD_DIR=$(abspath $(RUST_BUILD_DIR))/soroban
# ALL_SOROBAN_PROTOCOLS as you see fit).

if ENABLE_FASTDEV_UNSAFE_FOR_PRODUCTION
ALL_SOROBAN_PROTOCOLS=p28 p29
# Only the two latest soroban modules belong here (keep in sync with the
# fastdev feature in src/rust/Cargo.toml).
ALL_SOROBAN_PROTOCOLS=p29 p30
else
ALL_SOROBAN_PROTOCOLS=p21 p22 p23 p24 p25 p26 p27 p28 p29
ALL_SOROBAN_PROTOCOLS=p21 p22 p23 p24 p25 p26 p27 p28 p29 p30
endif
WIP_SOROBAN_PROTOCOL=p30
WIP_SOROBAN_PROTOCOL=

CARGO_XDR_FEATURE_FLAGS =

Expand Down
4 changes: 4 additions & 0 deletions src/herder/Upgrades.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,10 @@ Upgrades::applyVersionUpgrade(Application& app, AbstractLedgerTxn& ltx,
SorobanNetworkConfig::updateCostTypesForV26(ltx, app);
SorobanNetworkConfig::createLedgerEntriesForV26(ltx, app);
}
if (needUpgradeToVersion(ProtocolVersion::V_30, prevVersion, newVersion))
{
SorobanNetworkConfig::createCostTypesForV30(ltx, app);
}

if (protocolVersionEquals(prevVersion, ProtocolVersion::V_23) &&
protocolVersionEquals(newVersion, ProtocolVersion::V_24) &&
Expand Down
71 changes: 71 additions & 0 deletions src/herder/test/UpgradesTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2865,6 +2865,77 @@ TEST_CASE("upgrade to version 26 and check cost types", "[upgrades]")
}
}

TEST_CASE("upgrade to version 30 and check cost types", "[upgrades]")
{
VirtualClock clock;
auto cfg = getTestConfig();
cfg.USE_CONFIG_FOR_GENESIS = false;

auto app = createTestApplication(clock, cfg);

executeUpgrade(*app, makeProtocolVersionUpgrade(29));

LedgerKey cpuKey(CONFIG_SETTING);
cpuKey.configSetting().configSettingID =
CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS;
LedgerKey memKey(CONFIG_SETTING);
memKey.configSetting().configSettingID =
CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES;

{
LedgerTxn ltx(app->getLedgerTxnRoot());
REQUIRE(ltx.load(cpuKey)
.current()
.data.configSetting()
.contractCostParamsCpuInsns()
.size() ==
static_cast<uint32>(ContractCostType::Bn254G1Msm) + 1);
REQUIRE(ltx.load(memKey)
.current()
.data.configSetting()
.contractCostParamsMemBytes()
.size() ==
static_cast<uint32>(ContractCostType::Bn254G1Msm) + 1);
}

executeUpgrade(*app, makeProtocolVersionUpgrade(30));

{
LedgerTxn ltx(app->getLedgerTxnRoot());

auto cpuLtxe = ltx.load(cpuKey);
auto const& cpuParams =
cpuLtxe.current().data.configSetting().contractCostParamsCpuInsns();
auto memLtxe = ltx.load(memKey);
auto const& memParams =
memLtxe.current().data.configSetting().contractCostParamsMemBytes();

REQUIRE(cpuParams.size() ==
static_cast<uint32>(ContractCostType::VerifyMlDsa87Sig) + 1);
REQUIRE(memParams.size() ==
static_cast<uint32>(ContractCostType::VerifyMlDsa87Sig) + 1);
REQUIRE(SorobanNetworkConfig::isValidCostParams(cpuParams, 30));
REQUIRE(SorobanNetworkConfig::isValidCostParams(memParams, 30));
REQUIRE(!SorobanNetworkConfig::isValidCostParams(cpuParams, 29));

auto cpu = [&](ContractCostType t) {
return cpuParams[static_cast<size_t>(t)];
};
auto mem = [&](ContractCostType t) {
return memParams[static_cast<size_t>(t)];
};
REQUIRE(cpu(ContractCostType::MlDsa87DecodeVerifyingKey).constTerm ==
2625760);
REQUIRE(cpu(ContractCostType::VerifyMlDsa44Sig).constTerm == 685165);
REQUIRE(cpu(ContractCostType::VerifyMlDsa44Sig).linearTerm == 6103);
REQUIRE(cpu(ContractCostType::VerifyMlDsa87Sig).constTerm == 1437210);
REQUIRE(cpu(ContractCostType::VerifyMlDsa87Sig).linearTerm == 6102);
REQUIRE(mem(ContractCostType::MlDsa87DecodeVerifyingKey).constTerm ==
73808);
REQUIRE(mem(ContractCostType::VerifyMlDsa87Sig).constTerm == 0);
Comment thread
sisuresh marked this conversation as resolved.
Resolved
}
}

// There is a subtle inconsistency where for a ledger that upgrades from
// protocol vN to vN+1 that also changed LedgerCloseMeta version, the ledger
// header will be protocol vN+1, but the meta emitted for that ledger will be
Expand Down
2 changes: 0 additions & 2 deletions src/ledger/LedgerHashUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,10 @@ template <> class hash<stellar::SCAddress>
stellar::hashMix(
res, std::hash<stellar::uint256>()(addr.liquidityPoolId()));
break;
#ifdef CAP_0084_MUXED_CONTRACT
case stellar::SC_ADDRESS_TYPE_MUXED_CONTRACT:
stellar::hashMix(
res, stellar::shortHash::xdrComputeHash(addr.muxedContract()));
break;
#endif
}
return res;
}
Expand Down
139 changes: 138 additions & 1 deletion src/ledger/NetworkConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,67 @@ updateCpuCostParamsEntryForV26(AbstractLedgerTxn& ltxRoot)
ltx.commit();
}

void
updateCpuCostParamsEntryForV30(AbstractLedgerTxn& ltxRoot)
{
LedgerTxn ltx(ltxRoot);

LedgerKey key(CONFIG_SETTING);
key.configSetting().configSettingID =
ConfigSettingID::CONFIG_SETTING_CONTRACT_COST_PARAMS_CPU_INSTRUCTIONS;
auto txle = ltx.load(key);
releaseAssertOrThrow(txle);
auto& params =
txle.current().data.configSetting().contractCostParamsCpuInsns();

// Resize to fit the new cost types added in v30
params.resize(static_cast<uint32>(ContractCostType::VerifyMlDsa87Sig) + 1);

auto const& vals = xdr::xdr_traits<ContractCostType>::enum_values();

// While we loop over the full ContractCostType enum, we only set the
// entries that have been newly created in v30
for (auto val : vals)
{
switch (val)
{
case MlDsa44DecodeVerifyingKey:
params[val] = ContractCostParamEntry(ExtensionPoint{0}, 849110, 0);
break;
case MlDsa65DecodeVerifyingKey:
params[val] = ContractCostParamEntry(ExtensionPoint{0}, 1505271, 0);
break;
case MlDsa87DecodeVerifyingKey:
params[val] = ContractCostParamEntry(ExtensionPoint{0}, 2625760, 0);
break;
case MlDsa44DecodeSignature:
params[val] = ContractCostParamEntry(ExtensionPoint{0}, 37888, 0);
break;
case MlDsa65DecodeSignature:
params[val] = ContractCostParamEntry(ExtensionPoint{0}, 47691, 0);
break;
case MlDsa87DecodeSignature:
params[val] = ContractCostParamEntry(ExtensionPoint{0}, 66346, 0);
break;
case VerifyMlDsa44Sig:
params[val] =
ContractCostParamEntry(ExtensionPoint{0}, 685165, 6103);
break;
case VerifyMlDsa65Sig:
params[val] =
ContractCostParamEntry(ExtensionPoint{0}, 983619, 6103);
break;
case VerifyMlDsa87Sig:
params[val] =
ContractCostParamEntry(ExtensionPoint{0}, 1437210, 6102);
break;
default:
break;
}
}
ltx.commit();
}

ConfigSettingEntry
initialStateArchivalSettings(Config const& cfg)
{
Expand Down Expand Up @@ -1189,6 +1250,64 @@ updateMemCostParamsEntryForV26(AbstractLedgerTxn& ltxRoot)
ltx.commit();
}

void
updateMemCostParamsEntryForV30(AbstractLedgerTxn& ltxRoot)
{
LedgerTxn ltx(ltxRoot);

LedgerKey key(CONFIG_SETTING);
key.configSetting().configSettingID =
ConfigSettingID::CONFIG_SETTING_CONTRACT_COST_PARAMS_MEMORY_BYTES;
auto txle = ltx.load(key);
releaseAssertOrThrow(txle);
auto& params =
txle.current().data.configSetting().contractCostParamsMemBytes();

// Resize to fit the new cost types added in v30
params.resize(static_cast<uint32>(ContractCostType::VerifyMlDsa87Sig) + 1);

auto const& vals = xdr::xdr_traits<ContractCostType>::enum_values();

// While we loop over the full ContractCostType enum, we only set the
// entries that have been newly created in v30
for (auto val : vals)
{
switch (val)
{
case MlDsa44DecodeVerifyingKey:
params[val] = ContractCostParamEntry(ExtensionPoint{0}, 24656, 0);
break;
case MlDsa65DecodeVerifyingKey:
params[val] = ContractCostParamEntry(ExtensionPoint{0}, 43088, 0);
break;
case MlDsa87DecodeVerifyingKey:
params[val] = ContractCostParamEntry(ExtensionPoint{0}, 73808, 0);
break;
case MlDsa44DecodeSignature:
params[val] = ContractCostParamEntry(ExtensionPoint{0}, 4104, 0);
break;
case MlDsa65DecodeSignature:
params[val] = ContractCostParamEntry(ExtensionPoint{0}, 5128, 0);
break;
case MlDsa87DecodeSignature:
params[val] = ContractCostParamEntry(ExtensionPoint{0}, 7176, 0);
break;
case VerifyMlDsa44Sig:
params[val] = ContractCostParamEntry(ExtensionPoint{0}, 0, 0);
break;
case VerifyMlDsa65Sig:
params[val] = ContractCostParamEntry(ExtensionPoint{0}, 0, 0);
break;
case VerifyMlDsa87Sig:
params[val] = ContractCostParamEntry(ExtensionPoint{0}, 0, 0);
break;
default:
break;
}
}
ltx.commit();
}

ConfigSettingEntry
initialParallelComputeEntry()
{
Expand Down Expand Up @@ -1688,6 +1807,15 @@ SorobanNetworkConfig::updateCostTypesForV26(AbstractLedgerTxn& ltx,
updateMemCostParamsEntryForV26(ltx);
}

void
SorobanNetworkConfig::createCostTypesForV30(AbstractLedgerTxn& ltx,
Application& app)
{
ZoneScoped;
updateCpuCostParamsEntryForV30(ltx);
updateMemCostParamsEntryForV30(ltx);
}

void
SorobanNetworkConfig::createAndUpdateLedgerEntriesForV23(AbstractLedgerTxn& ltx,
Application& app)
Expand Down Expand Up @@ -1760,6 +1888,10 @@ SorobanNetworkConfig::initializeGenesisLedgerForTesting(
SorobanNetworkConfig::updateCostTypesForV26(ltx, app);
SorobanNetworkConfig::createLedgerEntriesForV26(ltx, app);
}
if (protocolVersionStartsFrom(genesisLedgerProtocol, ProtocolVersion::V_30))
{
SorobanNetworkConfig::createCostTypesForV30(ltx, app);
}
}

SorobanNetworkConfig
Expand Down Expand Up @@ -2836,10 +2968,15 @@ SorobanNetworkConfig::isValidCostParams(ContractCostParams const& params,
{
return static_cast<uint32_t>(ContractCostType::Bn254FrInv) + 1;
}
else
else if (protocolVersionIsBefore(ledgerVersion, ProtocolVersion::V_30))
{
return static_cast<uint32_t>(ContractCostType::Bn254G1Msm) + 1;
}
Comment thread
sisuresh marked this conversation as resolved.
Resolved
else
{
return static_cast<uint32_t>(ContractCostType::VerifyMlDsa87Sig) +
1;
}
};

if (params.size() != getNumCostTypes(ledgerVersion))
Expand Down
5 changes: 5 additions & 0 deletions src/ledger/NetworkConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ class SorobanNetworkConfig
static void createLedgerEntriesForV26(AbstractLedgerTxn& ltx,
Application& app);

// Creates the new cost types introduced in v30.
// This should happen once during the correspondent protocol version
// upgrade.
static void createCostTypesForV30(AbstractLedgerTxn& ltx, Application& app);

// Creates the new ledger entries introduced in v23 and updates the existing
// entries.
// This should happen once during the correspondent protocol version
Expand Down
2 changes: 1 addition & 1 deletion src/main/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

namespace stellar
{
uint32 const Config::CURRENT_LEDGER_PROTOCOL_VERSION = 29
uint32 const Config::CURRENT_LEDGER_PROTOCOL_VERSION = 30
#ifdef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION
+ 1
#endif
Expand Down
4 changes: 0 additions & 4 deletions src/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,6 @@ checkXDRFileIdentity()
// Verify that C++ and Rust have the same XDR feature flags enabled.
std::vector<std::string> cppFeatures;
Comment thread
sisuresh marked this conversation as resolved.
Resolved

#ifdef CAP_0084_MUXED_CONTRACT
cppFeatures.push_back("cap_0084_muxed_contract");
#endif

#ifndef ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION
// If we're not building for the next protocol, no XDR feature flags
// should be enabled. If any are, it's a build misconfiguration.
Expand Down
2 changes: 1 addition & 1 deletion src/protocol-curr/xdr
12 changes: 8 additions & 4 deletions src/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,13 @@ tracy-client = { version = "=0.17.0", features = [
version = "=30.0.0"
git = "https://github.com/stellar/rs-soroban-env"
package = "soroban-env-host"
rev = "fddfd567a6cb6ea801fac8bd807daa8f35bfd094"
rev = "8abed902b850b7c1aebddf131a6521684231bb93"
optional = true
# This dependency is only enabled by the `fastdev` feature, which implies
# `next`, so the host is always wanted at its next-protocol number here. The
# non-fastdev build takes p30 from the submodule rlib instead, where
# src/Makefile.am passes --features=next to SOROBAN_MAX_PROTOCOL.
features = ["next"]

[dependencies.soroban-env-host-p29]
version = "=29.0.0"
Expand Down Expand Up @@ -212,14 +217,13 @@ optional = true
[dependencies.stellar-quorum-analyzer]
version = "0.1.0"
git = "https://github.com/stellar/stellar-quorum-analyzer"
rev = "502a354eb9a31cf86098be84aa1b3081767fa3c7"
rev = "811d19a1a523f035f9a442e9197a6fed609550f1"

[features]

# Turn on the optional fastdev build. This is typically only useful in an IDE or when
# orchestrated by the build system. See note above and in docs/CONTRIBUTING.md.
fastdev = ["dep:soroban-env-host-p28",
"dep:soroban-env-host-p29",
fastdev = ["dep:soroban-env-host-p29",
"dep:soroban-env-host-p30",
"next"]

Expand Down
2 changes: 1 addition & 1 deletion src/rust/soroban/p30
Submodule p30 updated 44 files
+187 −42 Cargo.lock
+1 −2 Cargo.toml
+10 −0 cackle.toml
+7 −0 deny.toml
+39 −0 soroban-env-common/env.json
+7 −4 soroban-env-host/Cargo.toml
+207 −0 soroban-env-host/benches/common/cost_types/ml_dsa.rs
+2 −0 soroban-env-host/benches/common/cost_types/mod.rs
+9 −2 soroban-env-host/benches/common/measure.rs
+11 −0 soroban-env-host/benches/common/mod.rs
+29 −0 soroban-env-host/observations/test__dispatch__invalid_object_handle_verify_sig_ml_dsa_44_arg_0.json
+29 −0 soroban-env-host/observations/test__dispatch__invalid_object_handle_verify_sig_ml_dsa_44_arg_1.json
+29 −0 soroban-env-host/observations/test__dispatch__invalid_object_handle_verify_sig_ml_dsa_44_arg_2.json
+29 −0 soroban-env-host/observations/test__dispatch__invalid_object_handle_verify_sig_ml_dsa_44_arg_3.json
+29 −0 soroban-env-host/observations/test__dispatch__invalid_object_handle_verify_sig_ml_dsa_65_arg_0.json
+29 −0 soroban-env-host/observations/test__dispatch__invalid_object_handle_verify_sig_ml_dsa_65_arg_1.json
+29 −0 soroban-env-host/observations/test__dispatch__invalid_object_handle_verify_sig_ml_dsa_65_arg_2.json
+29 −0 soroban-env-host/observations/test__dispatch__invalid_object_handle_verify_sig_ml_dsa_65_arg_3.json
+29 −0 soroban-env-host/observations/test__dispatch__invalid_object_handle_verify_sig_ml_dsa_87_arg_0.json
+29 −0 soroban-env-host/observations/test__dispatch__invalid_object_handle_verify_sig_ml_dsa_87_arg_1.json
+29 −0 soroban-env-host/observations/test__dispatch__invalid_object_handle_verify_sig_ml_dsa_87_arg_2.json
+29 −0 soroban-env-host/observations/test__dispatch__invalid_object_handle_verify_sig_ml_dsa_87_arg_3.json
+904 −0 soroban-env-host/observations/test__ml_dsa__ml_dsa_acvp_sig_gen_external.json
+454 −0 soroban-env-host/observations/test__ml_dsa__ml_dsa_acvp_sig_ver_external.json
+34 −0 soroban-env-host/observations/test__ml_dsa__ml_dsa_boundary_inputs.json
+14 −0 soroban-env-host/observations/test__ml_dsa__ml_dsa_budget_exhaustion.json
+24 −0 soroban-env-host/observations/test__ml_dsa__ml_dsa_cross_variant_confusion.json
+214 −0 soroban-env-host/observations/test__ml_dsa__ml_dsa_error_paths.json
+64 −0 soroban-env-host/observations/test__ml_dsa__ml_dsa_verify_happy_path.json
+1,804 −0 soroban-env-host/observations/test__ml_dsa__ml_dsa_wycheproof_44.json
+2,104 −0 soroban-env-host/observations/test__ml_dsa__ml_dsa_wycheproof_65.json
+2,414 −0 soroban-env-host/observations/test__ml_dsa__ml_dsa_wycheproof_87.json
+83 −0 soroban-env-host/src/budget.rs
+174 −0 soroban-env-host/src/cost_runner/cost_types/ml_dsa.rs
+2 −0 soroban-env-host/src/cost_runner/cost_types/mod.rs
+251 −0 soroban-env-host/src/crypto/ml_dsa.rs
+1 −0 soroban-env-host/src/crypto/mod.rs
+42 −0 soroban-env-host/src/host.rs
+1 −0 soroban-env-host/src/test.rs
+9 −0 soroban-env-host/src/test/budget_metering.rs
+3,897 −0 soroban-env-host/src/test/data/ml_dsa/acvp/ML-DSA-sigGen-FIPS204/internalProjection.json
+2,199 −0 soroban-env-host/src/test/data/ml_dsa/acvp/ML-DSA-sigVer-FIPS204/internalProjection.json
+9 −0 soroban-env-host/src/test/hostile.rs
+453 −0 soroban-env-host/src/test/ml_dsa.rs
Loading
Loading