-
Notifications
You must be signed in to change notification settings - Fork 348
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
GPT Review not-so-smart-contracts/algorand #278
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
# (Not So) Smart Contracts | ||
|
||
This repository contains examples of common Algorand smart contract vulnerabilities, including code from real smart contracts. Use Not So Smart Contracts to learn about Algorand vulnerabilities, as a reference when performing security reviews, and as a benchmark for security and analysis tools. | ||
This repository contains examples of common Algorand smart contract vulnerabilities, including code from real smart contracts. Use the Not So Smart Contracts to learn about Algorand vulnerabilities, as a reference when performing security reviews, and as a benchmark for security and analysis tools. | ||
|
||
## Features | ||
|
||
Each _Not So Smart Contract_ includes a standard set of information: | ||
|
||
- Description of the vulnerability type | ||
- Attack scenarios to exploit the vulnerability | ||
- Recommendations to eliminate or mitigate the vulnerability | ||
- Real-world contracts that exhibit the flaw | ||
- Recommendations for eliminating or mitigating the vulnerability | ||
- Real-world contracts exhibiting the flaw | ||
- References to third-party resources with more information | ||
|
||
## Vulnerabilities | ||
|
||
| Not So Smart Contract | Description | Applicable to smart signatures | Applicable to smart contracts | | ||
| ------------------------------------------------------- | ------------------------------------------------------------------------------ | ------------------------------ | ----------------------------- | | ||
| [Rekeying](rekeying) | Attacker rekeys an account | yes | yes | | ||
| [Unchecked Transaction Fees](unchecked_transaction_fee) | Attacker sets excessive fees for smart signature transactions | yes | no | | ||
| [Closing Account](closing_account) | Attacker closes smart signature accounts | yes | no | | ||
| [Closing Asset](closing_asset) | Attacker transfers entire asset balance of a smart signature | yes | no | | ||
| [Group Size Check](group_size_check) | Contract does not check transaction group size | yes | yes | | ||
| [Time-based Replay Attack](time_based_replay_attack) | Contract does not use lease for periodic payments | yes | no | | ||
| [Access Controls](access_controls) | Contract does not enfore access controls for updating and deleting application | no | yes | | ||
| [Asset Id Check](asset_id_check) | Contract does not check asset id for asset transfer operations | yes | yes | | ||
| [Denial of Service](denial_of_service) | Attacker stalls contract execution by opting out of a asset | yes | yes | | ||
| Not So Smart Contract | Description | Applicable to smart signatures | Applicable to smart contracts | | ||
| ------------------------------------------------------- | -------------------------------------------------------------------------------- | ------------------------------ | ----------------------------- | | ||
| [Rekeying](rekeying) | Attacker rekeys an account | yes | yes | | ||
| [Unchecked Transaction Fees](unchecked_transaction_fee) | Attacker sets excessive fees for smart signature transactions | yes | no | | ||
| [Closing Account](closing_account) | Attacker closes smart signature accounts | yes | no | | ||
| [Closing Asset](closing_asset) | Attacker transfers the entire asset balance of a smart signature | yes | no | | ||
| [Group Size Check](group_size_check) | Contract does not check transaction group size | yes | yes | | ||
| [Time-based Replay Attack](time_based_replay_attack) | Contract does not use lease for periodic payments | yes | no | | ||
| [Access Controls](access_controls) | Contract does not enforce access controls for updating and deleting applications | no | yes | | ||
| [Asset Id Check](asset_id_check) | Contract does not check asset id for asset transfer operations | yes | yes | | ||
| [Denial of Service](denial_of_service) | Attacker stalls contract execution by opting out of an asset | yes | yes | | ||
|
||
## Credits | ||
|
||
These examples are developed and maintained by [Trail of Bits](https://www.trailofbits.com/). | ||
|
||
If you have questions, problems, or just want to learn more, then join the #ethereum channel on the [Empire Hacking Slack](https://empireslacking.herokuapp.com/) or [contact us](https://www.trailofbits.com/contact/) directly. | ||
If you have questions, issues, or simply want to learn more, join the #ethereum channel on the [Empire Hacking Slack](https://empireslacking.herokuapp.com/) or [contact us](https://www.trailofbits.com/contact/) directly. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
# Access Controls | ||
|
||
Lack of appropriate checks for application calls of type UpdateApplication and DeleteApplication allows attackers to update application’s code or delete an application entirely. | ||
Inadequate checks for application calls of type UpdateApplication and DeleteApplication can allow attackers to alter an application's code or delete it entirely. | ||
|
||
## Description | ||
|
||
When an application call is successful, additional operations are executed based on the OnComplete field. If the OnComplete field is set to UpdateApplication the approval and clear programs of the application are replaced with the programs specified in the transaction. Similarly, if the OnComplete field is set to DeleteApplication, application parameters are deleted. | ||
This allows attackers to update or delete the application if proper access controls are not enforced in the application. | ||
When an application call is successful, further operations are carried out based on the OnComplete field. If the OnComplete field is set to UpdateApplication, the approval and clear programs of the application get replaced with the programs specified in the transaction. Likewise, if the OnComplete field is set to DeleteApplication, the application parameters get deleted. This can let attackers update or delete the application if proper access controls are not in place. | ||
|
||
## Exploit Scenarios | ||
|
||
A stateful contract serves as a liquidity pool for a pair of tokens. Users can deposit the tokens to get the liquidity tokens and can get back their funds with rewards through a burn operation. The contract does not enforce restrictions for UpdateApplication type application calls. Attacker updates the approval program with a malicious program that transfers all assets in the pool to the attacker's address. | ||
A stateful contract functions as a liquidity pool for two tokens. Users can deposit these tokens to acquire liquidity tokens and can retrieve their funds along with rewards via a burn operation. The contract, however, does not enforce any restrictions for UpdateApplication type application calls. An attacker can update the approval program with a malicious program that transfers all the assets in the pool to their address. | ||
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.
|
||
|
||
## Recommendations | ||
|
||
- Set proper access controls and apply various checks before approving applications calls of type UpdateApplication and DeleteApplication. | ||
- Implement appropriate access controls and conduct various checks before approving application calls of type UpdateApplication and DeleteApplication. | ||
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.
|
||
|
||
- Use [Tealer](https://github.com/crytic/tealer) to detect this issue. | ||
- Utilize [Tealer](https://github.com/crytic/tealer) to identify this issue. | ||
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. This line should be reverted I think |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
# Asset Id Check | ||
# Asset ID Check | ||
|
||
Lack of verification of asset id in the contract allows attackers to transfer a different asset in place of the expected asset and mislead the application. | ||
Failing to verify the asset ID in a contract can allow attackers to transfer a different asset instead of the expected one, potentially misleading the application. | ||
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.
|
||
|
||
## Description | ||
|
||
Contracts accepting and doing operations based on the assets transferred to the contract must verify that the transferred asset is the expected asset by checking the asset Id. Absence of check for expected asset Id could allow attackers to manipulate contract’s logic by transferring a fake, less or more valuable asset instead of the correct asset. | ||
Contracts that accept and perform operations based on assets transferred to them must verify that the transferred asset is indeed the expected asset by checking the asset ID. Neglecting to check the expected asset ID could enable attackers to manipulate the contract's logic by transferring a fake, less valuable, or more valuable asset instead of the correct one. | ||
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.
|
||
|
||
## Exploit Scenarios | ||
|
||
- A liquidity pool contract mints liquidity tokens on deposit of two tokens. Contract does not check that the asset Ids in the two asset transfer transactions are correct. Attacker deposits the same less valuable asset in the two transactions and withdraws both tokens by burning the pool tokens. | ||
- User creates a delegate signature that allows recurring transfers of a certain asset. Attacker creates a valid asset transfer transaction of more valuable assets. | ||
- A liquidity pool contract mints liquidity tokens upon the deposit of two tokens. The contract does not verify that the asset IDs in the two asset transfer transactions are correct. The attacker deposits the same, less valuable asset in both transactions and withdraws both tokens by burning the pool tokens. | ||
- A user creates a delegate signature that permits recurring transfers of a certain asset. The attacker then generates a valid asset transfer transaction involving more valuable assets. | ||
|
||
## Examples | ||
|
||
|
@@ -35,4 +35,4 @@ def withdraw_asset( | |
|
||
## Recommendations | ||
|
||
Verify the asset id to be expected asset for all asset related operations in the contract. | ||
Ensure that the asset ID is verified as the expected asset for all asset-related operations in the contract. |
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.
We should probably stick with previously used
update
instead ofalter an
(?)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.
+1 ,
update
is more appropriated here