-
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
V1.0.0 internal audit #3
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 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
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,22 @@ | ||
# Internal audit of autonolas-staking-programmes | ||
The review has been performed based on the contract code in the following repository:<br> | ||
`https://github.com/valory-xyz/autonolas-staking-programmes` <br> | ||
commit: `v1.0.0-pre-internal-audit` <br> | ||
|
||
## Objectives | ||
The audit focused on contracts in this repo. <br> | ||
Before being allocated to this repository, the code was audited in [audit-before](https://github.com/valory-xyz/autonolas-registries/blob/main/audits/internal4/README.md) <br> | ||
|
||
### Flatten version | ||
Flatten version of contracts. [contracts](https://github.com/valory-xyz/autonolas-staking-programmes/blob/main/audits/internal/analysis/contracts) | ||
|
||
### ERC20/ERC721 checks | ||
N/A | ||
|
||
### Security issues. Updated 25-10-2023 | ||
#### Problems found instrumentally | ||
Several checks are obtained automatically. They are commented. <br> | ||
All automatic warnings are listed in the following file, concerns of which we address in more detail below: <br> | ||
[slither-full](https://github.com/valory-xyz/autonolas-staking-programmes/blob/main/audits/internal/analysis/slither_full.txt) | ||
Re-audit after extract Mech contracts into a this repo. <br> | ||
I don't see any new problems after separating to this repository. <br> |
88 changes: 88 additions & 0 deletions
88
audits/internal/analysis/contracts/MechAgentMod-flatten.sol
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,88 @@ | ||
// Sources flattened with hardhat v2.18.2 https://hardhat.org | ||
|
||
// SPDX-License-Identifier: MIT | ||
|
||
// File contracts/mech_usage/MechAgentMod.sol | ||
// Original license: SPDX_License_Identifier: MIT | ||
pragma solidity ^0.8.21; | ||
|
||
// Multisig interface | ||
interface IMultisig { | ||
/// @dev Gets the multisig nonce. | ||
/// @return Multisig nonce. | ||
function nonce() external view returns (uint256); | ||
} | ||
|
||
// AgentMech interface | ||
interface IAgentMech { | ||
/// @dev Gets the requests count for a specific account. | ||
/// @param account Account address. | ||
/// @return requestsCount Requests count. | ||
function getRequestsCount(address account) external view returns (uint256 requestsCount); | ||
} | ||
|
||
/// @dev Provided zero mech agent address. | ||
error ZeroMechAgentAddress(); | ||
|
||
/// @title MechAgentMod - Abstract smart contract for AI agent mech staking modification | ||
/// @author Aleksandr Kuperman - <[email protected]> | ||
/// @author Andrey Lebedev - <[email protected]> | ||
/// @author Mariapia Moscatiello - <[email protected]> | ||
abstract contract MechAgentMod { | ||
// AI agent mech contract address. | ||
address public immutable agentMech; | ||
|
||
/// @dev MechAgentMod constructor. | ||
/// @param _agentMech AI agent mech contract address. | ||
constructor(address _agentMech) { | ||
if (_agentMech == address(0)) { | ||
revert ZeroMechAgentAddress(); | ||
} | ||
agentMech = _agentMech; | ||
} | ||
|
||
/// @dev Gets service multisig nonces. | ||
/// @param multisig Service multisig address. | ||
/// @return nonces Set of a nonce and a requests count for the multisig. | ||
function _getMultisigNonces(address multisig) internal view virtual returns (uint256[] memory nonces) { | ||
nonces = new uint256[](2); | ||
nonces[0] = IMultisig(multisig).nonce(); | ||
nonces[1] = IAgentMech(agentMech).getRequestsCount(multisig); | ||
} | ||
|
||
/// @dev Gets the liveness ratio. | ||
/// @return Liveness ratio. | ||
function _getLivenessRatio() internal view virtual returns (uint256); | ||
|
||
/// @dev Checks if the service multisig liveness ratio passes the defined liveness threshold. | ||
/// @notice The formula for calculating the ratio is the following: | ||
/// currentNonces - [service multisig nonce at time now (block.timestamp), requests count at time now]; | ||
/// lastNonces - [service multisig nonce at the previous checkpoint or staking time (tsStart), requests count at time tsStart]; | ||
/// Requests count difference must be smaller or equal to the nonce difference: | ||
/// (currentNonces[1] - lastNonces[1]) <= (currentNonces[0] - lastNonces[0]); | ||
/// ratio = (currentNonces[1] - lastNonce[1]) / (block.timestamp - tsStart), | ||
/// where ratio >= livenessRatio. | ||
/// @param curNonces Current service multisig set of nonce and requests count. | ||
/// @param lastNonces Last service multisig set of nonce and requests count. | ||
/// @param ts Time difference between current and last timestamps. | ||
/// @return ratioPass True, if the liveness ratio passes the check. | ||
function _isRatioPass( | ||
uint256[] memory curNonces, | ||
uint256[] memory lastNonces, | ||
uint256 ts | ||
) internal view virtual returns (bool ratioPass) | ||
{ | ||
// If the checkpoint was called in the exact same block, the ratio is zero | ||
// If the current nonce is not greater than the last nonce, the ratio is zero | ||
// If the current requests count is not greater than the last requests count, the ratio is zero | ||
if (ts > 0 && curNonces[0] > lastNonces[0] && curNonces[1] > lastNonces[1]) { | ||
uint256 diffNonces = curNonces[0] - lastNonces[0]; | ||
uint256 diffRequestsCounts = curNonces[1] - lastNonces[1]; | ||
// Requests counts difference must be less or equal to the nonce difference | ||
if (diffRequestsCounts <= diffNonces) { | ||
uint256 ratio = (diffRequestsCounts * 1e18) / ts; | ||
ratioPass = (ratio >= _getLivenessRatio()); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.