Skip to content
Draft
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
7 changes: 4 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
ignore = dirty
[submodule "src/protocol-curr/xdr"]
path = src/protocol-curr/xdr
url = https://github.com/stellar/stellar-xdr
branch = main
url = https://github.com/sisuresh/stellar-xdr-next.git
branch = p28-cap-0084
[submodule "src/rust/soroban/p21"]
path = src/rust/soroban/p21
url = https://github.com/stellar/rs-soroban-env
Expand All @@ -51,7 +51,8 @@
url = https://github.com/stellar/rs-soroban-env.git
[submodule "src/rust/soroban/p28"]
path = src/rust/soroban/p28
url = https://github.com/stellar/rs-soroban-env.git
url = https://github.com/sisuresh/rs-soroban-env.git
branch = p28-cap-0084
[submodule "lib/gperftools"]
path = lib/gperftools
url = https://github.com/gperftools/gperftools.git
34 changes: 24 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ endif # ENABLE_FASTDEV_UNSAFE_FOR_PRODUCTION

if CAP_0083
AM_CPPFLAGS += -DCAP_0083
endif

if CAP_0084_MUXED_CONTRACT
AM_CPPFLAGS += -DCAP_0084_MUXED_CONTRACT
endif
3 changes: 3 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,9 @@ AM_CONDITIONAL(ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION,
AM_CONDITIONAL(CAP_0083,
[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
9 changes: 9 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ XDR_FEATURE_FLAGS =
if CAP_0083
XDR_FEATURE_FLAGS += -DCAP_0083
endif
if CAP_0084_MUXED_CONTRACT
XDR_FEATURE_FLAGS += -DCAP_0084_MUXED_CONTRACT
endif

SUFFIXES = .x .h .rs
.x.h:
Expand Down Expand Up @@ -221,6 +224,12 @@ endif
WIP_SOROBAN_PROTOCOL=

CARGO_XDR_FEATURE_FLAGS =
if CAP_0084_MUXED_CONTRACT
# CAP-0084 host code is gated on the per-cap leaf feature `cap_0084_muxed_contract`
# (rs-soroban-env#1700), which the umbrella `next` feature aggregates; building the
# p28 host with `next` enables it and pulls in the matching stellar-xdr XDR variant.
CARGO_XDR_FEATURE_FLAGS += --features next
endif

if ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION
ALL_SOROBAN_PROTOCOLS+=$(WIP_SOROBAN_PROTOCOL)
Expand Down
6 changes: 6 additions & 0 deletions src/ledger/LedgerHashUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ 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
2 changes: 1 addition & 1 deletion src/protocol-curr/xdr
Submodule xdr updated 1 files
+16 −0 Stellar-contract.x
4 changes: 2 additions & 2 deletions src/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ tracy-client = { version = "=0.17.0", features = [

[dependencies.soroban-env-host-p28]
version = "=27.0.0"
git = "https://github.com/stellar/rs-soroban-env"
git = "https://github.com/sisuresh/rs-soroban-env"
package = "soroban-env-host"
rev = "883fd56374fc619afaa4c4c7489563555b7173f2"
rev = "0df250f37aaae74e210c9016583c943fecdaba42"
optional = true
features = ["next"]

Expand Down
16 changes: 8 additions & 8 deletions src/rust/src/dep-trees/p28-expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ soroban-env-host v27.0.0 (src/rust/soroban/p28/soroban-env-host)
│ │ │ ├── itoa v1.0.6
│ │ │ ├── ryu v1.0.13
│ │ │ └── serde v1.0.192 (*)
│ │ ├── stellar-xdr v27.0.0
│ │ ├── stellar-xdr v28.0.0 (https://github.com/sisuresh/rs-stellar-xdr?rev=3d2ad659a3a285aae9543069ee18cb6245a427ce#3d2ad659)
│ │ │ ├── escape-bytes v0.1.1
│ │ │ ├── ethnum v1.5.3
│ │ │ ├── hex v0.4.3
Expand All @@ -272,7 +272,10 @@ soroban-env-host v27.0.0 (src/rust/soroban/p28/soroban-env-host)
│ │ │ ├── serde_derive v1.0.192 (proc-macro) (*)
│ │ │ └── serde_json v1.0.108 (*)
│ │ │ [build-dependencies]
│ │ │ └── crate-git-revision v0.0.6 (*)
│ │ │ └── crate-git-revision v0.0.9
│ │ │ ├── serde v1.0.192 (*)
│ │ │ ├── serde_derive v1.0.192 (proc-macro) (*)
│ │ │ └── serde_json v1.0.108 (*)
│ │ └── syn v2.0.39 (*)
│ ├── soroban-wasmi v0.31.1-soroban.20.0.1 (https://github.com/stellar/wasmi?rev=0ed3f3dee30dc41ebe21972399e0a73a41944aa0#0ed3f3de)
│ │ ├── smallvec v1.13.2
Expand All @@ -286,25 +289,22 @@ soroban-env-host v27.0.0 (src/rust/soroban/p28/soroban-env-host)
│ │ └── wasmparser-nostd v0.100.2
│ │ └── indexmap-nostd v0.4.0
│ ├── static_assertions v1.1.0
│ ├── stellar-xdr v27.0.0
│ ├── stellar-xdr v28.0.0 (https://github.com/sisuresh/rs-stellar-xdr?rev=3d2ad659a3a285aae9543069ee18cb6245a427ce#3d2ad659)
│ │ ├── base64 v0.22.1
│ │ ├── escape-bytes v0.1.1
│ │ ├── ethnum v1.5.3
│ │ ├── hex v0.4.3
│ │ ├── sha2 v0.10.9 (*)
│ │ └── stellar-strkey v0.0.13 (*)
│ │ [build-dependencies]
│ │ └── crate-git-revision v0.0.6 (*)
│ │ └── crate-git-revision v0.0.9 (*)
│ └── wasmparser v0.116.1
│ ├── indexmap v2.0.2
│ │ ├── equivalent v1.0.1
│ │ └── hashbrown v0.14.1
│ └── semver v1.0.17
│ [build-dependencies]
│ └── crate-git-revision v0.0.9
│ ├── serde v1.0.192 (*)
│ ├── serde_derive v1.0.192 (proc-macro) (*)
│ └── serde_json v1.0.108 (*)
│ └── crate-git-revision v0.0.9 (*)
├── soroban-wasmi v0.31.1-soroban.20.0.1 (https://github.com/stellar/wasmi?rev=0ed3f3dee30dc41ebe21972399e0a73a41944aa0#0ed3f3de) (*)
├── static_assertions v1.1.0
├── stellar-strkey v0.0.13 (*)
Expand Down
5 changes: 2 additions & 3 deletions src/rust/src/soroban_module_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// current-protocol cache as soon as we start, as well as the next-protocol
// cache (if it exists) so that we can upgrade without stalling.

#[cfg(feature = "next")]
use crate::soroban_proto_all::p28;
use crate::{
rust_bridge::CxxBuf,
soroban_proto_all::{get_host_module_for_protocol, p27, protocol_agnostic},
Expand All @@ -22,9 +24,6 @@ use crate::{
#[cfg(not(feature = "fastdev"))]
use crate::soroban_proto_all::{p23, p24, p25, p26};

#[cfg(feature = "next")]
use crate::soroban_proto_all::p28;

pub(crate) struct SorobanModuleCache {
#[cfg(not(feature = "fastdev"))]
pub(crate) p23_cache: p23::soroban_proto_any::ProtocolSpecificModuleCache,
Expand Down
51 changes: 51 additions & 0 deletions src/transactions/test/InvokeHostFunctionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,14 @@ TEST_CASE("Stellar asset contract transfer with CAP-67 address types",
SorobanTest test(cfg);
auto& root = test.getRoot();

#ifdef CAP_0084_MUXED_CONTRACT
// a1 makes several native transfers within a single run (100M + 300M +
// 400M for the muxed-contract case), so it needs enough balance to stay
// above its account reserve after all of them.
auto a1 = root.create("a1", 2'000'000'000);
#else
auto a1 = root.create("a1", 1'000'000'000);
#endif
auto a2 = root.create("a2", 1'000'000'000);
Asset asset = makeAsset(root.getSecretKey(), "USDC");
a1.changeTrust(asset, 2'000'000'000);
Expand Down Expand Up @@ -714,6 +721,45 @@ TEST_CASE("Stellar asset contract transfer with CAP-67 address types",
a1, makeClaimableBalanceAddress(ClaimableBalanceID()), 1));
REQUIRE(client.lastEvent() == std::nullopt);
}
#ifdef CAP_0084_MUXED_CONTRACT
{
INFO("transfer to muxed contract (CAP-0084)");
// The destination is the SAC-transfer contract wrapped in a muxed
// contract address; the SAC de-muxes to the underlying contract for
// the balance and surfaces the id via the `to_muxed_id` event.
REQUIRE(
client.transfer(a1,
makeMuxedContractAddress(
transferContract.getAddress().contractId(),
987'654'321'987'654'321ULL),
400'000'000));
REQUIRE(*client.lastEvent() ==
client.makeTransferEvent(
a1Address, transferContract.getAddress(), 400'000'000,
987'654'321'987'654'321ULL));
}
if (!useNativeAsset)
{
INFO("mint to muxed contract (CAP-0084)");
// Mint to a muxed-contract destination: the SAC de-muxes to the
// underlying contract for the balance (asserted inside mint() via
// the de-muxed getBalance) and surfaces the id via `to_muxed_id`.
// Native has no admin, so mint only applies to the issued asset.
uint64_t const toMuxId = 111'222'333'444'555'666ULL;
REQUIRE(client.mint(
root,
makeMuxedContractAddress(
transferContract.getAddress().contractId(), toMuxId),
500'000'000));
REQUIRE(*client.lastEvent() ==
makeMintOrBurnEvent(
/*isMint=*/true,
client.getContract().getAddress().contractId(),
tokenAsset, transferContract.getAddress(), 500'000'000,
SCMapEntry(makeSymbolSCVal("to_muxed_id"),
makeU64(toMuxId))));
}
#endif
};

SECTION("native asset")
Expand Down Expand Up @@ -7787,6 +7833,11 @@ TEST_CASE("Module cache across protocol versions", "[tx][soroban][modulecache]")
// work-in-progress next host, in which case there _is_ a separate module
// cache and the following line of code should be commented-out.
//
// p28 (CAP-0084) ships its own work-in-progress next host with a separate
// module cache (see p28_cache in soroban_module_cache.rs), so the next
// protocol version _does_ add to the module cache count and the following
// line stays commented-out.
//
// moduleCacheProtocolCount -= 1;
#endif
REQUIRE(app->getLedgerManager()
Expand Down
35 changes: 35 additions & 0 deletions src/transactions/test/SorobanTxTestUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,33 @@ makeMuxedAccountAddress(AccountID const& accountID, uint64_t id)
return addr;
}

#ifdef CAP_0084_MUXED_CONTRACT
SCAddress
makeMuxedContractAddress(Hash const& contractId, uint64_t id)
{
SCAddress addr(SC_ADDRESS_TYPE_MUXED_CONTRACT);
addr.muxedContract().contractId = contractId;
addr.muxedContract().id = id;
return addr;
}

// CAP-0084: resolve a muxed contract address to its underlying contract id.
// The SAC keys balances on the underlying contract, so every balance
// key/value built from an SCAddress must de-mux first. Non-muxed-contract
// addresses are returned unchanged.
static SCAddress
demuxContractAddress(SCAddress const& addr)
{
if (addr.type() == SC_ADDRESS_TYPE_MUXED_CONTRACT)
{
SCAddress c(SC_ADDRESS_TYPE_CONTRACT);
c.contractId() = addr.muxedContract().contractId;
return c;
}
return addr;
}
#endif

SCVal
makeI32(int32_t i32)
{
Expand Down Expand Up @@ -1576,7 +1603,11 @@ LedgerKey
AssetContractTestClient::makeContractDataBalanceKey(SCAddress const& addr)
{
SCVal val(SCV_ADDRESS);
#ifdef CAP_0084_MUXED_CONTRACT
val.address() = demuxContractAddress(addr);
#else
val.address() = addr;
#endif

LedgerKey balanceKey(CONTRACT_DATA);
balanceKey.contractData().contract = mContract.getAddress();
Expand Down Expand Up @@ -1628,7 +1659,11 @@ int64_t
AssetContractTestClient::getBalance(SCAddress const& addr)
{
SCVal val(SCV_ADDRESS);
#ifdef CAP_0084_MUXED_CONTRACT
val.address() = demuxContractAddress(addr);
#else
val.address() = addr;
#endif

return addr.type() == SC_ADDRESS_TYPE_ACCOUNT
? txtest::getBalance(mApp, addr.accountId(), mAsset)
Expand Down
Loading
Loading