Rust Stylus Architecture

Why Rust via Stylus?

Traditional Solidity contracts on Ethereum suffer from high gas costs for complex computation. While suitable for simple token transfers, they struggle with heavy mathematical loops (like calculating daily compound interest for 10 years).

LegacyVault solves this by utilizing Arbitrum Stylus, allowing us to write our "Heavy Logic" in Rust.

circle-info

Writing heavy computation in Rust (compiled to WASM) reduces gas and increases execution speed compared to equivalent EVM bytecode. Rust's compile-time safety helps avoid common classes of bugs (e.g., reentrancy, integer overflow).


The Hybrid Model

1

The Muscle (Solidity Factory)

We use a standard Solidity Factory (VaultFactory.sol) to handle the user interface of creating new vaults. This ensures compatibility with standard tools like Etherscan and Metamask.

  • Role: Deploys minimal proxies (clones).

  • Cost: extremely cheap deployment for users.

2

The Brain (Rust Logic)

The core intelligence (vault-logic) resides in a single compiled WASM binary.

  • Performance: Rust compiles to WebAssembly (WASM), which executes much faster and cheaper than EVM bytecode.

  • Safety: Rust's memory safety features prevent common vulnerabilities like Reentrancy and Overflow at the compiler level.


The Loop Architecture

The "Ping" Check

Instead of relying on an external Keeper network to check "Is Alive?", the logic is embedded directly in the contract state.

vault-logic/src/lib.rs
// vault-logic/src/lib.rs
// Direct, type-safe comparison
if msg::sender() != self.owner.get() {
    return Err(b"Unauthorized".to_vec());
}
self.last_ping.set(block::timestamp());