> For the complete documentation index, see [llms.txt](https://docs.fly.trade/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fly.trade/developers/deprecated-magpie-contracts/magpieaggregator-diamond-proxy/libraries/libguard.md).

# LibGuard

These functions are intended to prevent reentrancy attacks by ensuring that reentrant calls are not executed when the `guarded` flag is set. The `guarded` flag is controlled by these functions to enable or disable the reentrancy guard as needed.

### enforcePreGuard():

This function is used to enforce a pre-reentrancy guard. It retrieves the `AppStorage` instance using `LibMagpieAggregator.getStorage()` and checks if the `guarded` flag is set. If the flag is already set, indicating an ongoing reentrant call, it reverts the transaction with a `ReentrantCall` error. Otherwise, it sets the `guarded` flag to `true`.

### enforcePostGuard():

This function is used to enforce a post-reentrancy guard. It retrieves the `AppStorage` instance using `LibMagpieAggregator.getStorage()` and sets the `guarded` flag to `false`.

### enforceDelegatedCallPreGuard():

Accesses the contract storage to determine if a specific type of delegated call is already in progress. If a call of that type is already in progress, it reverts the transaction to prevent reentrancy. If no such call is in progress, it sets the delegated call state to `true` for that call type.

Input:

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">delegatedCallType
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">DelegatedCallType
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">enum DelegatedCallType {
    BridgeIn,
    BridgeOut,
    DataTransferIn,
    DataTransferOut
}
</code></pre></td></tr></tbody></table>

### enforceDelegatedCall():

Accesses the contract storage to confirm whether a particular type of delegated call is currently in progress. If the expected call is not in progress, it reverts the transaction, indicating an invalid delegated call.

### enforceDelegatedCallPostGaurd():

Accesses the contract storage and sets the delegated call state back to `false` for the specified type of delegated call.

Input:

<table><thead><tr><th>Field</th><th>Type</th><th></th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">delegatedCallType
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">DelegatedCallType
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">enum DelegatedCallType {
    BridgeIn,
    BridgeOut,
    DataTransferIn,
    DataTransferOut
}
</code></pre></td></tr></tbody></table>

### enforceDelegatedCallGuard():

Accesses the contract storage to confirm whether a particular type of delegated call is currently in progress. If the expected call is not in progress, it reverts the transaction, indicating an invalid delegated call.

Input:

<table><thead><tr><th>Field</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><p></p><pre class="language-solidity"><code class="lang-solidity">delegatedCallType
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">DelegatedCallType
</code></pre></td><td><p></p><pre class="language-solidity"><code class="lang-solidity">enum DelegatedCallType {
    BridgeIn,
    BridgeOut,
    DataTransferIn,
    DataTransferOut
}
</code></pre></td></tr></tbody></table>
