Skip to content
Open
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
2 changes: 1 addition & 1 deletion contracts/contract-factory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ impl ContractFactory {
.deploy_v2(wasm_hash, constructor_args)
}

pub fn get_deployed_address(env: &Env, salt: BytesN<32>) -> Address {
#[must_use] pub fn get_deployed_address(env: &Env, salt: BytesN<32>) -> Address {
env.deployer()
.with_current_contract(salt)
.deployed_address()
Expand Down
18 changes: 9 additions & 9 deletions contracts/contract-factory/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
extern crate std;

use soroban_sdk::{
symbol_short, testutils::Address as _, vec, Address, BytesN, Env, IntoVal, Val, Vec,
symbol_short, testutils::Address as _, vec, Address, BytesN, Env, IntoVal as _, Val, Vec,
};

use crate::test_constants::SMART_ACCOUNT_WASM;
use crate::{ContractDeploymentArgs, ContractFactory, ContractFactoryClient};

fn create_factory_client<'a>(e: &Env, admin: &Address) -> ContractFactoryClient<'a> {
let address = e.register(ContractFactory, (admin,));
ContractFactoryClient::new(e, &address)
return ContractFactoryClient::new(e, &address)
}

pub struct TestAccounts {
Expand All @@ -37,7 +37,7 @@ fn setup_roles(e: &Env, client: &ContractFactoryClient, admin: &Address) -> Test
client.grant_role(&deployer_admin, &deployer1, &symbol_short!("deployer"));
client.grant_role(&deployer_admin, &deployer2, &symbol_short!("deployer"));

TestAccounts {
return TestAccounts {
deployer_admin,
deployer1,
deployer2,
Expand All @@ -47,9 +47,9 @@ fn setup_roles(e: &Env, client: &ContractFactoryClient, admin: &Address) -> Test

// Helper function to create a mock salt
fn create_mock_salt(e: &Env, value: u8) -> BytesN<32> {
let mut bytes = [0u8; 32];
let mut bytes = [0_u8; 32];
bytes[0] = value; // Make it unique
BytesN::from_array(e, &bytes)
return BytesN::from_array(e, &bytes)
}

#[test]
Expand Down Expand Up @@ -279,7 +279,7 @@ fn test_constructor_args_handling() {

// Create constructor args with some values (unused but kept for documentation)
let _arg1 = Address::generate(&e);
let _arg2 = 42u32;
let _arg2 = 42_u32;
let _constructor_args: Vec<Val> = vec![&e, _arg1.into_val(&e), _arg2.into_val(&e)];

// Should be able to get deployed address regardless of constructor args
Expand Down Expand Up @@ -400,7 +400,7 @@ fn test_deploy_idempotency() {
&ContractDeploymentArgs {
wasm_hash,
salt,
constructor_args: constructor_args.clone(),
constructor_args: constructor_args,
},
);

Expand All @@ -410,13 +410,13 @@ fn test_deploy_idempotency() {
// Verify first deployment returns the predicted address
assert_eq!(deployed_address1, predicted_address);

let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
let result = std::panic::catch_unwind(core::panic::AssertUnwindSafe(|| {
let wasm_bytes = soroban_sdk::Bytes::from_slice(&e, SMART_ACCOUNT_WASM);
let wasm_hash = e.deployer().upload_contract_wasm(wasm_bytes);
let salt = create_mock_salt(&e, 1);
let constructor_args: Vec<Val> = vec![&e];

client.deploy(
return client.deploy(
&accounts.deployer1,
&ContractDeploymentArgs {
wasm_hash,
Expand Down
14 changes: 7 additions & 7 deletions contracts/examples/plugin-policy-example/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use smart_account_interfaces::{SmartAccountPlugin, SmartAccountPolicy};
use soroban_sdk::{
auth::{Context, ContractContext},
contract, contractimpl, contracttype, symbol_short, Address, Env, Symbol, TryFromVal, Vec,
contract, contractimpl, contracttype, symbol_short, Address, Env, Symbol, TryFromVal as _, Vec,
};

const AUTH_COUNTER_KEY: Symbol = symbol_short!("COUNTER");
Expand Down Expand Up @@ -121,18 +121,18 @@ impl SmartAccountPolicy for PluginPolicyContract {
// Helper function to get the current counter (for testing purposes)
#[contractimpl]
impl PluginPolicyContract {
pub fn get_auth_counter(env: Env) -> u32 {
#[must_use] pub fn get_auth_counter(env: Env) -> u32 {
env.storage().instance().get(&AUTH_COUNTER_KEY).unwrap_or(0)
}
}

#[cfg(test)]
mod test {
use super::*;
use soroban_sdk::{auth::ContractContext, testutils::Address as _, IntoVal};
use soroban_sdk::{auth::ContractContext, testutils::Address as _, IntoVal as _};

fn setup() -> Env {
Env::default()
return Env::default()
}

#[test]
Expand Down Expand Up @@ -175,7 +175,7 @@ mod test {
let transfer_context = Context::Contract(ContractContext {
contract: token_address,
fn_name: symbol_short!("transfer"),
args: (Address::generate(&env), Address::generate(&env), 50i128).into_val(&env),
args: (Address::generate(&env), Address::generate(&env), 50_i128).into_val(&env),
});

let mut contexts = Vec::new(&env);
Expand All @@ -199,7 +199,7 @@ mod test {
let transfer_context = Context::Contract(ContractContext {
contract: token_address,
fn_name: symbol_short!("transfer"),
args: (Address::generate(&env), Address::generate(&env), 150i128).into_val(&env),
args: (Address::generate(&env), Address::generate(&env), 150_i128).into_val(&env),
});

let mut contexts = Vec::new(&env);
Expand All @@ -223,7 +223,7 @@ mod test {
let other_context = Context::Contract(ContractContext {
contract: contract_address,
fn_name: symbol_short!("approve"),
args: (Address::generate(&env), 1000i128).into_val(&env),
args: (Address::generate(&env), 1000_i128).into_val(&env),
});

let mut contexts = Vec::new(&env);
Expand Down
10 changes: 5 additions & 5 deletions contracts/initializable/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use soroban_sdk::{contracterror, symbol_short, Env, Symbol};

#[contracterror(export = false)]
#[derive(Copy, Clone, Debug, PartialEq)]
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[repr(u32)]
pub enum Error {
AlreadyInitialized = 0,
Expand All @@ -13,7 +13,7 @@ pub enum Error {
const INITIALIZED: Symbol = symbol_short!("INIT");

/// Macro to ensure a function only runs if the contract is initialized
/// Usage: only_initialized!(env);
/// Usage: `only_initialized!(env)`;
/// This should be called at the beginning of functions that require initialization
#[macro_export]
macro_rules! only_initialized {
Expand All @@ -25,7 +25,7 @@ macro_rules! only_initialized {
}

/// Macro to ensure a function only runs if the contract is initialized
/// Usage: only_initialized!(env);
/// Usage: `only_initialized!(env)`;
/// This should be called at the beginning of functions that require initialization
#[macro_export]
macro_rules! only_not_initialized {
Expand All @@ -37,7 +37,7 @@ macro_rules! only_not_initialized {
}

pub trait Initializable {
fn get_initialization_value(env: &Env) -> bool {
#[must_use] fn get_initialization_value(env: &Env) -> bool {
env.storage()
.instance()
.get::<Symbol, bool>(&INITIALIZED)
Expand Down Expand Up @@ -76,7 +76,7 @@ pub trait Initializable {
Ok(())
}

fn is_initialized(env: &Env) -> bool {
#[must_use] fn is_initialized(env: &Env) -> bool {
Self::get_initialization_value(env)
}

Expand Down
18 changes: 9 additions & 9 deletions contracts/smart-account/src/account.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::auth::core::authorizer::Authorizer;
use crate::auth::permissions::{PolicyCallback, SignerPolicy, SignerRole};
use crate::auth::permissions::{PolicyCallback as _, SignerPolicy, SignerRole};
use crate::auth::proof::SignatureProofs;
use crate::auth::signer::{Signer, SignerKey};
use crate::config::{
Expand All @@ -24,7 +24,7 @@ use soroban_sdk::{
use storage::Storage;
use upgradeable::{SmartAccountUpgradeable, SmartAccountUpgradeableAuth};

/// SmartAccount is a multi-signature account contract that provides enhanced security
/// `SmartAccount` is a multi-signature account contract that provides enhanced security
/// through role-based access control, policy-based authorization, and an extensible plugin system.
///
/// The account supports different signers with different signer roles (Admin, Standard, Restricted) with customizable
Expand Down Expand Up @@ -79,7 +79,7 @@ impl SmartAccountInterface for SmartAccount {

// Register signers. Duplication will fail
for signer in signers.iter() {
SmartAccount::add_signer(&env, signer).unwrap_or_else(|e| panic_with_error!(env, e));
Self::add_signer(&env, signer).unwrap_or_else(|e| panic_with_error!(env, e));
}

// Initialize plugins storage
Expand All @@ -89,12 +89,12 @@ impl SmartAccountInterface for SmartAccount {
.unwrap();
// Install plugins
for plugin in plugins {
SmartAccount::install_plugin(&env, plugin)
Self::install_plugin(&env, plugin)
.unwrap_or_else(|e| panic_with_error!(env, e));
}

// Initialize the contract
SmartAccount::initialize(&env).unwrap_or_else(|e| panic_with_error!(env, e));
Self::initialize(&env).unwrap_or_else(|e| panic_with_error!(env, e));
}

fn add_signer(env: &Env, signer: Signer) -> Result<(), Error> {
Expand Down Expand Up @@ -296,15 +296,15 @@ impl SmartAccount {
Ok(())
}

/// Activates policies by calling their on_add callbacks
/// Activates policies by calling their `on_add` callbacks
fn activate_policies(env: &Env, policies: &Vec<SignerPolicy>) -> Result<(), Error> {
for policy in policies {
policy.on_add(env)?;
}
Ok(())
}

/// Deactivates policies by calling their on_revoke callbacks
/// Deactivates policies by calling their `on_revoke` callbacks
fn deactivate_policies(env: &Env, policies: &Vec<SignerPolicy>) -> Result<(), Error> {
for policy in policies {
policy.on_revoke(env)?;
Expand All @@ -314,8 +314,8 @@ impl SmartAccount {

/// Handles changes to a policy set by calling appropriate callbacks
///
/// - Policies only in old set: on_revoke() called (removed)
/// - Policies only in new set: on_add() called (added)
/// - Policies only in old set: `on_revoke()` called (removed)
/// - Policies only in new set: `on_add()` called (added)
/// - Policies in both sets: no callbacks (unchanged)
fn handle_policy_set_changes(
env: &Env,
Expand Down
4 changes: 2 additions & 2 deletions contracts/smart-account/src/auth/core/authorizer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Authorization service that verifies proofs and enforces role/policy checks.
use crate::auth::permissions::{AuthorizationCheck, SignerRole};
use crate::auth::permissions::{AuthorizationCheck as _, SignerRole};
use crate::auth::proof::SignatureProofs;
use crate::auth::signer::{Signer, SignerKey};
use crate::auth::signers::SignatureVerifier as _;
Expand Down Expand Up @@ -60,7 +60,7 @@ impl Authorizer {

pub fn call_plugins_on_auth(env: &Env, auth_contexts: &Vec<Context>) -> Result<(), Error> {
let storage = Storage::instance();
for (plugin, _) in storage
for (plugin, ()) in storage
.get::<Symbol, Map<Address, ()>>(env, &PLUGINS_KEY)
.unwrap()
.iter()
Expand Down
20 changes: 10 additions & 10 deletions contracts/smart-account/src/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,43 @@
///
/// ## Core Objects and Classes
///
/// ### SignerPolicy
/// ### `SignerPolicy`
/// An enum that wraps individual policy implementations for restricted signers, including external delegation.
///
/// ### SignerRole
/// ### `SignerRole`
/// Defines the authorization level and restrictions for a signer:
/// - `Admin` - Can authorize any operation, including changing signers and upgrading contracts
/// - `Standard(Vec<SignerPolicy>)` - Can authorize any operation except changing signers and upgrading contracts; subject to policy restrictions if policies are provided (all policies must pass), including external policies
///
/// ### SignatureProofs
/// A wrapper struct containing a Map<SignerKey, SignerProof> that pairs signer keys with their
/// ### `SignatureProofs`
/// A wrapper struct containing a Map<`SignerKey`, `SignerProof`> that pairs signer keys with their
/// cryptographic proofs. Used to bundle authorization data for multi-signature operations.
///
/// ### SignerProof
/// ### `SignerProof`
/// An enum representing cryptographic proofs (e.g. signatures) for signature verification
///
/// ### SignerKey
/// ### `SignerKey`
/// An enum representing an identifier for different signature schemes:
///
/// ### Signer
/// The main signer enum that combines a cryptographic signer with a role:
///
/// ## Core Traits
///
/// ### AuthorizationCheck
/// ### `AuthorizationCheck`
/// Core trait for authorization checking. Implementations must provide:
/// - `is_authorized(&self, env: &Env, context: &Context) -> bool` - Determines if an operation
/// is authorized based on the execution context.
///
/// ### SignatureVerifier
/// ### `SignatureVerifier`
/// Trait for cryptographic signature verification. Implementations must provide:
/// - `verify(&self, env: &Env, payload: &BytesN<32>, proof: &SignerProof) -> Result<(), Error>`
/// Verifies a signature proof against a payload hash. Used by Signer and specific signer types.
///
/// ### PolicyCallback
/// ### `PolicyCallback`
/// Trait for validating initialization parameters in signing policies. Implementations must provide:
/// - `check(&self, env: &Env) -> Result<(), Error>` - Validates that policy parameters are
/// correct and feasible at initialization time. Used by SignerPolicy and policy implementations.
/// correct and feasible at initialization time. Used by `SignerPolicy` and policy implementations.
///
/// ## Architecture
///
Expand Down
20 changes: 10 additions & 10 deletions contracts/smart-account/src/auth/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub trait PolicyCallback {

// Main policy enum that wraps the individual policies
#[contracttype]
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum SignerPolicy {
TimeWindowPolicy(TimeBasedPolicy),
ExternalValidatorPolicy(ExternalPolicy),
Expand All @@ -29,30 +29,30 @@ pub enum SignerPolicy {
impl AuthorizationCheck for SignerPolicy {
fn is_authorized(&self, env: &Env, contexts: &Vec<Context>) -> bool {
match self {
SignerPolicy::TimeWindowPolicy(policy) => policy.is_authorized(env, contexts),
SignerPolicy::ExternalValidatorPolicy(policy) => policy.is_authorized(env, contexts),
Self::TimeWindowPolicy(policy) => policy.is_authorized(env, contexts),
Self::ExternalValidatorPolicy(policy) => policy.is_authorized(env, contexts),
}
}
}

impl PolicyCallback for SignerPolicy {
fn on_add(&self, env: &Env) -> Result<(), Error> {
match self {
SignerPolicy::TimeWindowPolicy(policy) => policy.on_add(env),
SignerPolicy::ExternalValidatorPolicy(policy) => policy.on_add(env),
Self::TimeWindowPolicy(policy) => policy.on_add(env),
Self::ExternalValidatorPolicy(policy) => policy.on_add(env),
}
}
fn on_revoke(&self, env: &Env) -> Result<(), Error> {
match self {
SignerPolicy::TimeWindowPolicy(policy) => policy.on_revoke(env),
SignerPolicy::ExternalValidatorPolicy(policy) => policy.on_revoke(env),
Self::TimeWindowPolicy(policy) => policy.on_revoke(env),
Self::ExternalValidatorPolicy(policy) => policy.on_revoke(env),
}
}
}

// This defines the roles that a configured signer can have
#[contracttype]
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum SignerRole {
// Can authorize any operation, including changing signers and upgrading the contract
Admin,
Expand All @@ -77,8 +77,8 @@ impl AuthorizationCheck for SignerRole {
});

match self {
SignerRole::Admin => true,
SignerRole::Standard(policies) => {
Self::Admin => true,
Self::Standard(policies) => {
// Standard signers cannot perform admin operations
if needs_admin_approval {
false
Expand Down
2 changes: 1 addition & 1 deletion contracts/smart-account/src/auth/policy/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
};

#[contracttype]
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ExternalPolicy {
pub policy_address: Address,
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/smart-account/src/auth/policy/time_based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
};

#[contracttype]
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TimeBasedPolicy {
pub not_before: u64,
pub not_after: u64,
Expand Down
Loading
Loading