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
26 changes: 1 addition & 25 deletions contracts/privacy-channel/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
use moonlight_errors::Error;
use moonlight_utxo_core::core::UtxoHandlerTrait;
use soroban_sdk::{
contract, contractevent, contractimpl, panic_with_error, symbol_short, Address, BytesN, Env,
Symbol, Vec,
};
use soroban_sdk::{contract, contractevent, contractimpl, Address, BytesN, Env, Vec};
use stellar_access::ownable;
use stellar_contract_utils::upgradeable;

Expand Down Expand Up @@ -36,23 +32,6 @@ fn bump_instance_ttl(e: &Env) {
.extend_ttl(INSTANCE_LIFETIME_THRESHOLD, INSTANCE_BUMP_AMOUNT);
}

// MOON-06: reentrancy guard. `transact` makes external SAC calls (deposit pull / withdraw push);
// a non-standard or malicious asset could call back into `transact`. The guard is a transient flag
// that is set on entry and cleared on exit; a re-entrant call observes it and reverts. (On revert
// the transient write is rolled back, so the flag never persists across transactions.)
const REENTRANCY_GUARD: Symbol = symbol_short!("RGUARD");

fn enter_reentrancy_guard(e: &Env) {
if e.storage().temporary().has(&REENTRANCY_GUARD) {
panic_with_error!(e, Error::ReentrantCall);
}
e.storage().temporary().set(&REENTRANCY_GUARD, &true);
}

fn exit_reentrancy_guard(e: &Env) {
e.storage().temporary().remove(&REENTRANCY_GUARD);
}

#[contractimpl]
impl PrivacyChannelContract {
pub fn __constructor(e: &Env, admin: Address, auth_contract: Address, asset: Address) {
Expand Down Expand Up @@ -106,15 +85,12 @@ impl PrivacyChannelContract {

pub fn transact(e: Env, op: ChannelOperation) {
bump_instance_ttl(&e);
enter_reentrancy_guard(&e);

let (utxo_op, total_deposit, total_withdraw) =
pre_process_channel_operation(&e, op.clone());

Self::process_bundle(&e, utxo_op.clone(), total_deposit, total_withdraw);

execute_external_operations(&e, op.deposit, op.withdraw);

exit_reentrancy_guard(&e);
}
}
2 changes: 0 additions & 2 deletions contracts/privacy-channel/src/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ pub mod moon01;
#[cfg(test)]
pub mod moon05;
#[cfg(test)]
pub mod moon06;
#[cfg(test)]
pub mod test;
86 changes: 0 additions & 86 deletions contracts/privacy-channel/src/test/moon06.rs

This file was deleted.

2 changes: 0 additions & 2 deletions modules/errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ pub enum MoonlightError {
UnauthorizedOperation = 3_006,
/// A deposit or withdraw amount was not strictly positive.
InvalidExternalAmount = 3_007,
/// `transact` was re-entered while a call was already in progress.
ReentrantCall = 3_008,

// Helper errors: 4000-4099.
/// An address payload was expected to be an Ed25519 account address but was not.
Expand Down
Loading