-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Internal audit reward #181
Open
77ph
wants to merge
2
commits into
main
Choose a base branch
from
internal_audit_reward
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Internal audit of agent-academy-2 | ||
The review has been performed based on the contract code in the following repository:<br> | ||
`https://github.com/valory-xyz/agent-academy-2` <br> | ||
commit: `v0.4.0` <br> | ||
|
||
## Objectives | ||
The audit focused on `compensation` behavior. The audit is preliminary. | ||
|
||
## Places that raised questions | ||
### events loop | ||
```python | ||
def _get_gas_spent(self) -> Generator[None, None, str]: | ||
# we start from the block the block in which the last withdraw event happened, or from the first block if we have | ||
# never withdrawn | ||
from_block = ( | ||
0 | ||
if latest_withdraw_event == self._NO_EVENT | ||
else latest_withdraw_event["block_number"] | ||
) | ||
# we end at the block in which the last unbonding event happened | ||
to_block = latest_unbonding_event["block_number"] | ||
As I understand it, in this standard aglorhythm, 2 conditions must be met: | ||
- Do not lose transactions. That is, all transactions were counted | ||
- Do not count a transaction twice. | ||
Typically a new "from" is previous "to" | ||
In this case, "from" and "to" they move independently. | ||
``` | ||
|
||
### Requires clarification of the logic of work. | ||
``` | ||
def get_tx(self) -> Generator[None, None, str]: | ||
Required transactions to execute the swap and disburse: | ||
1. Withdraw the k3pr from the keep3r contract | ||
2. Approve the k3pr for the swap | ||
3. Swap the k3pr for eth | ||
4. Disburse the eth to the agents | ||
i.e. | ||
1. You take all available k3pr | ||
2. Calculate how much you get ETH based on k3pr: dy = get_dy(dx), x - k3pr, y - eth | ||
3. Swap all k3pr to ETH | ||
4. Disburse ETH: if ETH > total_gas_spent_in_ETH for each agent => gas_spent + (ETH - total_gas_spent_in_ETH) * share_agent / len(agents) | ||
5. go #1 | ||
Most likely this strategy is the simplest. | ||
Alternative strategies are more complicated. | ||
surplus = eth_amount - total_gas_spent | ||
agent_surplus = int(surplus * agent_surplus_share) - what will happen to the rest? | ||
``` | ||
|
||
### Use use_eth in exchange | ||
Ref: https://etherscan.io/address/0x21410232b484136404911780bc32756d5d1a9fa9#code#L728 <br> | ||
Otherwise you will get back WETH tokes. Test please, on the testnet. | ||
|
||
### min_dy too big and slippage tolerance | ||
```python | ||
def _get_swap_tx( | ||
self, pool_address: str, k3pr_amount: int, min_eth_amount: int | ||
) -> Generator[None, None, Optional[Dict[str, Any]]]: | ||
"""Swap tx.""" | ||
contract_api_response = yield from self.get_contract_api_response( | ||
performative=ContractApiMessage.Performative.GET_STATE, | ||
contract_address=pool_address, | ||
contract_id=str(CurvePoolContract.contract_id), | ||
contract_callable="build_exchange_tx", | ||
dx=k3pr_amount, | ||
i=self._K3PR_INDEX, | ||
j=self._ETH_INDEX, | ||
min_dy=min_eth_amount, | ||
) | ||
min_dy=min_eth_amount, | ||
vs | ||
https://curve.readthedocs.io/factory-pools.html | ||
StableSwap.exchange(i: int128, j: int128, dx: uint256, min_dy: uint256, _receiver: address = msg.sender)→ uint256: nonpayable | ||
Performs an exchange between two tokens. | ||
|
||
Index values can be found using the coins public getter method, or get_coins within the factory contract. | ||
|
||
i: Index value of the token to send. | ||
|
||
j: Index value of the token to receive. | ||
|
||
dx: The amount of i being exchanged. | ||
|
||
min_dy: The minimum amount of j to receive. If the swap would result in less, the transaction will revert. | ||
|
||
_receiver: An optional address that will receive j. If not given, defaults to the caller. | ||
|
||
Returns the amount of j received in the exchange. | ||
|
||
expected = pool.get_dy(0, 1, 10**18) * 0.99 | ||
pool.exchange(0, 1, 10**18, expected, {'from': alice}) | ||
Comment on lines
+89
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needs to be addressed |
||
|
||
dy = def _exchange(sender: address, mvalue: uint256, i: uint256, j: uint256, dx: uint256, min_dy: uint256, | ||
use_eth: bool, receiver: address, callbacker: address, callback_sig: bytes32) -> uint256: | ||
The exact value of what you will receive. | ||
It may not be like as get_dy | ||
https://etherscan.io/address/0x21410232b484136404911780bc32756d5d1a9fa9#code#L759 | ||
``` | ||
|
||
|
||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to be addressed