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

Sketch for muxed account support in Soroban host. #1521

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
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
1 change: 0 additions & 1 deletion Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ version = "=0.31.1-soroban.20.0.1"
git = "https://github.com/stellar/wasmi"
rev = "0ed3f3dee30dc41ebe21972399e0a73a41944aa0"

# [patch."https://github.com/stellar/rs-stellar-xdr"]
[patch."https://github.com/stellar/rs-stellar-xdr"]
# [patch.crates-io]
# stellar-xdr = { path = "../rs-stellar-xdr" }
stellar-xdr = { path = "../rs-stellar-xdr" }
# [patch."https://github.com/stellar/wasmi"]
# soroban-wasmi = { path = "../wasmi/crates/wasmi/" }
# soroban-wasmi_core = { path = "../wasmi/crates/core/" }
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ crate-git-revision = "0.0.6"

[dependencies]
soroban-env-macros = { workspace = true }
stellar-xdr = { workspace = true, default-features = false, features = [ "curr" ] }
stellar-xdr = { workspace = true, default-features = false, features = [ "next" ] }
wasmi = { workspace = true, optional = true }
wasmparser = { workspace = true, optional = true}
serde = { version = "1.0.192", features = ["derive"], optional = true }
Expand Down
13 changes: 13 additions & 0 deletions soroban-env-common/env.json
Original file line number Diff line number Diff line change
Expand Up @@ -2416,6 +2416,19 @@
"return": "Val",
"docs": "Returns the executable corresponding to the provided address. When the address does not exist on-chain, returns `Void` value. When it does exist, returns a value of `AddressExecutable` contract type. It is an enum with `Wasm` value and the corresponding Wasm hash for the Wasm contracts, `StellarAsset` value for Stellar Asset contract instances, and `Account` value for the 'classic' (G-) accounts.",
"min_supported_protocol": 23
},
{
"export": "5",
"name": "muxed_address_to_address",
"args": [
{
"name": "muxed_address",
"type": "MuxedAddressObject"
}
],
"return": "AddressObject",
"docs": "",
"min_supported_protocol": 23
}
]
},
Expand Down
3 changes: 2 additions & 1 deletion soroban-env-common/src/compare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,8 @@ impl<E: Env> Compare<Val> for E {
| Tag::SymbolObject
| Tag::VecObject
| Tag::MapObject
| Tag::AddressObject => Err(self.error_from_error_val(Error::from_type_and_code(
| Tag::AddressObject
| Tag::MuxedAddressObject => Err(self.error_from_error_val(Error::from_type_and_code(
ScErrorType::Context,
ScErrorCode::InternalError,
))),
Expand Down
1 change: 1 addition & 0 deletions soroban-env-common/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ where
| Tag::VecObject
| Tag::MapObject
| Tag::AddressObject
| Tag::MuxedAddressObject
| Tag::SmallCodeUpperBound
| Tag::ObjectCodeLowerBound
| Tag::ObjectCodeUpperBound
Expand Down
6 changes: 4 additions & 2 deletions soroban-env-common/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ use crate::Object;
use super::Symbol;
use super::{
AddressObject, Bool, BytesObject, DurationObject, Error, I128Object, I256Object, I256Val,
I64Object, MapObject, StorageType, StringObject, SymbolObject, TimepointObject, U128Object,
U256Object, U256Val, U32Val, U64Object, U64Val, Val, VecObject, Void,
I64Object, MapObject, MuxedAddressObject, StorageType, StringObject, SymbolObject,
TimepointObject, U128Object, U256Object, U256Val, U32Val, U64Object, U64Val, Val, VecObject,
Void,
};
use crate::xdr::{ScErrorCode, ScErrorType};

Expand Down Expand Up @@ -262,6 +263,7 @@ impl_checkedenvarg_for_val_or_wrapper!(Val);
impl_checkedenvarg_for_val_or_wrapper!(Symbol);

impl_checkedenvarg_for_val_or_wrapper!(AddressObject);
impl_checkedenvarg_for_val_or_wrapper!(MuxedAddressObject);
impl_checkedenvarg_for_val_or_wrapper!(BytesObject);
impl_checkedenvarg_for_val_or_wrapper!(DurationObject);

Expand Down
5 changes: 3 additions & 2 deletions soroban-env-common/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use crate::{
AddressObject, BytesObject, DurationObject, I128Object, I256Object, I64Object, MapObject,
Object, StringObject, Symbol, SymbolObject, TimepointObject, U128Object, U256Object, U64Object,
Val, VecObject,
MuxedAddressObject, Object, StringObject, Symbol, SymbolObject, TimepointObject, U128Object,
U256Object, U64Object, Val, VecObject,
};

impl core::hash::Hash for Val {
Expand Down Expand Up @@ -40,3 +40,4 @@ impl_hash_for_wrapper!(Symbol);
impl_hash_for_wrapper!(VecObject);
impl_hash_for_wrapper!(MapObject);
impl_hash_for_wrapper!(AddressObject);
impl_hash_for_wrapper!(MuxedAddressObject);
4 changes: 2 additions & 2 deletions soroban-env-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ pub use storage_type::StorageType;

// Re-export the XDR definitions of a specific version -- curr or next -- of the xdr crate.
#[cfg(not(feature = "next"))]
pub use stellar_xdr::curr as xdr;
pub use stellar_xdr::next as xdr;
#[cfg(feature = "next")]
pub use stellar_xdr::next as xdr;

Expand All @@ -113,7 +113,7 @@ pub use val::{ConversionError, Tag, Val};

#[cfg(feature = "wasmi")]
pub use val::WasmiMarshal;
pub use val::{AddressObject, MapObject, VecObject};
pub use val::{AddressObject, MapObject, MuxedAddressObject, VecObject};
pub use val::{Bool, Void};

pub use compare::Compare;
Expand Down
10 changes: 8 additions & 2 deletions soroban-env-common/src/val.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ pub enum Tag {
/// Tag for a [Val] that refers to a host-side contract address.
AddressObject = 77,

MuxedAddressObject = 78,

/// Code delimiting the upper boundary of "object" types.
ObjectCodeUpperBound = 78,
ObjectCodeUpperBound = 79,

/// Code reserved to indicate mis-tagged [`Val`]s.
Bad = 0x7f,
Expand Down Expand Up @@ -238,6 +240,7 @@ impl Tag {
Tag::VecObject => Some(ScValType::Vec),
Tag::MapObject => Some(ScValType::Map),
Tag::AddressObject => Some(ScValType::Address),
Tag::MuxedAddressObject => Some(ScValType::Address),
Tag::ObjectCodeUpperBound => None,
Tag::Bad => None,
}
Expand Down Expand Up @@ -337,6 +340,7 @@ impl<E: Env> Compare<Bool> for E {
declare_tag_based_object_wrapper!(VecObject);
declare_tag_based_object_wrapper!(MapObject);
declare_tag_based_object_wrapper!(AddressObject);
declare_tag_based_object_wrapper!(MuxedAddressObject);

// This is a 0-arg struct rather than an enum to ensure it completely compiles
// away, the same way `()` would, while remaining a separate type to allow
Expand Down Expand Up @@ -685,7 +689,8 @@ impl Val {
| Tag::SymbolObject
| Tag::VecObject
| Tag::MapObject
| Tag::AddressObject => self.has_minor(0),
| Tag::AddressObject
| Tag::MuxedAddressObject => self.has_minor(0),
}
}

Expand Down Expand Up @@ -866,6 +871,7 @@ impl Debug for Val {
Tag::VecObject => fmt_obj("Vec", self, f),
Tag::MapObject => fmt_obj("Map", self, f),
Tag::AddressObject => fmt_obj("Address", self, f),
Tag::MuxedAddressObject => fmt_obj("MuxedAddress", self, f),

Tag::Bad
| Tag::SmallCodeUpperBound
Expand Down
5 changes: 3 additions & 2 deletions soroban-env-common/src/vmcaller_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use crate::xdr::{ScErrorCode, ScErrorType};

use super::{
AddressObject, Bool, BytesObject, DurationObject, Error, I128Object, I256Object, I256Val,
I64Object, MapObject, StorageType, StringObject, SymbolObject, TimepointObject, U128Object,
U256Object, U256Val, U32Val, U64Object, U64Val, Val, VecObject, Void,
I64Object, MapObject, MuxedAddressObject, StorageType, StringObject, SymbolObject,
TimepointObject, U128Object, U256Object, U256Val, U32Val, U64Object, U64Val, Val, VecObject,
Void,
};
use crate::call_macro_with_all_host_functions;
use crate::{CheckedEnvArg, EnvBase, Symbol};
Expand Down
7 changes: 4 additions & 3 deletions soroban-env-guest/src/guest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ use soroban_env_common::call_macro_with_all_host_functions;

use super::{
AddressObject, Bool, BytesObject, DurationObject, Error, I128Object, I256Object, I256Val,
I64Object, MapObject, StorageType, StringObject, SymbolObject, TimepointObject, U128Object,
U256Object, U256Val, U32Val, U64Object, U64Val, Val, VecObject, Void,
I64Object, MapObject, MuxedAddressObject, StorageType, StringObject, SymbolObject,
TimepointObject, U128Object, U256Object, U256Val, U32Val, U64Object, U64Val, Val, VecObject,
Void,
};
use super::{Env, EnvBase, Symbol};
use static_assertions as sa;
Expand Down Expand Up @@ -337,7 +338,7 @@ macro_rules! generate_extern_modules {
#[allow(unused_imports)]
use crate::{I128Object, I256Object, I256Val, I64Object, I64Val, U128Object, U256Object, U256Val, U32Val, U64Object, U64Val, StorageType, TimepointObject, DurationObject};
#[allow(unused_imports)]
use crate::{Void,AddressObject,SymbolObject,StringObject,Bool};
use crate::{Void,AddressObject,MuxedAddressObject,SymbolObject,StringObject,Bool};
#[link(wasm_import_module = $mod_str)]
extern "C" {
$(
Expand Down
4 changes: 2 additions & 2 deletions soroban-env-host/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2030,6 +2030,7 @@ impl AccountAuthorizationTracker {
&self.invocation_tracker.root_authorized_invocation,
)?;
}
ScAddress::MuxedAccount(_) => unreachable!(),
}
Ok(())
}
Expand Down Expand Up @@ -2072,8 +2073,6 @@ impl AccountAuthorizationTracker {
// - Return budget error in case if it was suppressed above.
let _ = acc.metered_clone(host.as_budget())?;
}
// We only know for sure that the contract instance and Wasm will be
// loaded.
ScAddress::Contract(contract_id) => {
let instance_key = host.contract_instance_ledger_key(&contract_id)?;
let entry = host
Expand Down Expand Up @@ -2110,6 +2109,7 @@ impl AccountAuthorizationTracker {
ContractExecutable::StellarAsset => (),
}
}
ScAddress::MuxedAccount(_) => unreachable!(),
}
Ok(())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ pub(crate) fn read_balance(e: &Host, addr: Address) -> Result<i128, HostError> {
Ok(0)
}
}
ScAddress::MuxedAccount(_) => unreachable!(),
}
}

Expand Down Expand Up @@ -130,6 +131,7 @@ pub(crate) fn receive_balance(e: &Host, addr: Address, amount: i128) -> Result<(
balance.amount = new_balance;
write_contract_balance(e, addr, balance, &id)
}
ScAddress::MuxedAccount(_) => unreachable!(),
}
}

Expand Down Expand Up @@ -188,6 +190,7 @@ pub(crate) fn spend_balance_no_authorization_check(
}
Ok(())
}
ScAddress::MuxedAccount(_) => unreachable!(),
}
}

Expand Down Expand Up @@ -219,6 +222,7 @@ pub(crate) fn is_authorized(e: &Host, addr: Address) -> Result<bool, HostError>
Ok(!is_asset_auth_required(e)?)
}
}
ScAddress::MuxedAccount(_) => unreachable!(),
}
}

Expand Down Expand Up @@ -257,6 +261,7 @@ pub(crate) fn write_authorization(
write_contract_balance(e, addr, balance, &id)
}
}
ScAddress::MuxedAccount(_) => unreachable!(),
}
}

Expand Down Expand Up @@ -326,6 +331,7 @@ pub(crate) fn check_clawbackable(e: &Host, addr: Address) -> Result<(), HostErro

Ok(())
}
ScAddress::MuxedAccount(_) => unreachable!(),
}
}

Expand Down
17 changes: 15 additions & 2 deletions soroban-env-host/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ pub(crate) use internal::{
use crate::{
num::{i256_from_pieces, u256_from_pieces},
xdr::{
ContractEventBody, ContractEventType, ContractExecutable, PublicKey::PublicKeyTypeEd25519,
ScAddress, ScContractInstance, ScVal,
ContractEventBody, ContractEventType, ContractExecutable, MuxedAccount,
PublicKey::PublicKeyTypeEd25519, ScAddress, ScContractInstance, ScVal,
},
Error, Host, HostError, Val, VecObject,
};
Expand All @@ -35,6 +35,19 @@ fn display_address(addr: &ScAddress, f: &mut std::fmt::Formatter<'_>) -> std::fm
let strkey = stellar_strkey::Contract(hash.0);
write!(f, "{}", strkey)
}
ScAddress::MuxedAccount(muxed_account) => match muxed_account {
MuxedAccount::Ed25519(uint256) => {
let strkey = stellar_strkey::ed25519::PublicKey(uint256.0);
write!(f, "{}", strkey)
}
MuxedAccount::MuxedEd25519(m) => {
let strkey = stellar_strkey::ed25519::MuxedAccount {
ed25519: m.ed25519.0.clone(),
id: m.id.clone(),
};
write!(f, "{}", strkey)
}
},
}
}

Expand Down
Loading
Loading