stellar / stellar-cli

CLI for Stellar developers
72 stars 70 forks source link

Stack overflow error when interacting with testnet contract #1588

Open leighmcculloch opened 2 months ago

leighmcculloch commented 2 months ago

What version are you using?

v21.4.1

What did you do?

$ stellar contract invoke --id CASQBSZXLPBXKAS7B556ARFKZI4UNVJKGM4SBZMRUS4OCXVDILOUVHMC --network testnet -- -h

What did you expect to see?

Help output for the contract.

What did you see instead?

thread 'main' has overflowed its stack
fatal runtime error: stack overflow

Reported by @kalepail in Discord:

leighmcculloch commented 2 months ago

Inspecting the contract, it appears to have a recursive contracttype definition. I don't know if that is the cause, but recursive data structure and stack overflow could go hand in hand.

$ stellar contract fetch --id CASQBSZXLPBXKAS7B556ARFKZI4UNVJKGM4SBZMRUS4OCXVDILOUVHMC --network testnet -o contract.wasm
$ stellar contract bindings rust --wasm contract.wasm
pub const WASM: &[u8] = soroban_sdk::contractfile!(
    file = "CASQBSZXLPBXKAS7B556ARFKZI4UNVJKGM4SBZMRUS4OCXVDILOUVHMC.wasm", sha256 =
    "4858768f584c661d9a839bf84d75f12bcf1705ef031fdbec5becd0ab367af0f6"
);
#[soroban_sdk::contractclient(name = "Client")]
pub trait Contract {
    fn init(
        env: soroban_sdk::Env,
        wasm_hash: soroban_sdk::BytesN<32>,
    ) -> Result<(), soroban_sdk::Error>;
    fn deploy(
        env: soroban_sdk::Env,
        salt: soroban_sdk::BytesN<32>,
        id: Signer,
    ) -> Result<soroban_sdk::Address, soroban_sdk::Error>;
}
#[soroban_sdk::contracttype(export = false)]
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
pub struct Policy(pub soroban_sdk::Address);
#[soroban_sdk::contracttype(export = false)]
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
pub struct Ed25519PublicKey(pub soroban_sdk::BytesN<32>);
#[soroban_sdk::contracttype(export = false)]
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
pub struct Secp256r1Id(pub soroban_sdk::Bytes);
#[soroban_sdk::contracttype(export = false)]
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
pub enum Signer {
    Policy(Policy, soroban_sdk::Vec<Signer>),
    Ed25519(Ed25519PublicKey),
    Secp256r1(Secp256r1Id, soroban_sdk::BytesN<65>),
}
#[soroban_sdk::contracterror(export = false)]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
pub enum Error {
    NotInitialized = 1,
    AlreadyInitialized = 2,
}

Specifically the Signer type:

pub enum Signer {
    Policy(Policy, soroban_sdk::Vec<Signer>),
kalepail commented 2 months ago

Removing this recursion definitely cleared up this issue fwiw

willemneal commented 2 months ago

Looking into it here: #1593