# Temporary Variable

## Idea

This is a no-brainer one. Basically there are two functions called `supply()` and `remove()`:

```solidity
    function supply(
        address _user,
        uint256 _amount
    ) public {
        require(_user == msg.sender, "unauthorized");
        require(_balances[_user] == 0, "already exists");
        require(_amount > 0, "invalid amount");
        _balances[_user] += _amount;
        _blacklist[_user] = false;
    }
```

```solidity
    function remove (
        address _from,
        uint256 _amount
    ) public isUserBlacklisted(_from)  {
        require(_from == msg.sender, "unauthorized");
        uint256 _accountbalance = _balances[_from];
        require(_amount <= _accountbalance, "not enough balance");


        if (_amount == _accountbalance) {
            delete _balances[_from];
            delete _blacklist[_from];
        }
        else {
            _accountbalance -= _amount;
            _balances[_from] = _accountbalance;
        }
    }
```

The assertion is:

```solidity
        uint256 newbalance = _factory.checkbalance(user1);
        assertEq(newbalance, 200);
```

where `checkbalance()` just reads the mapping `_balance`:

```solidity
    function checkbalance(address _user) public view returns (uint256) {
        return _balances[_user];
    }
```

This is so obvious. The function `supply()` does not ask for money, we can just call it with any amount we desire. Before calling `supply()`, we should call `remove()` to clear user balance, so that the check `require(_balances[_user] == 0, "already exists");` will pass.

## PoC

{% embed url="<https://github.com/ret2basic/QuillCTF-PoC/blob/main/TemporaryVariable/test/factory.t.sol>" %}
TemporaryVariable PoC
{% endembed %}


---

# 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://ret2basic.gitbook.io/ctfwriteup/web3-ctf/quillctf/temporary-variable.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.
