# 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>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.fly.trade/flycn/developers/deprecated-magpie-contracts/magpieaggregator-diamond-proxy/libraries/libguard.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
