Skip to content
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

Hash collision #58

Merged
merged 7 commits into from
Jun 6, 2024
Merged

Hash collision #58

merged 7 commits into from
Jun 6, 2024

Conversation

indeqs
Copy link
Contributor

@indeqs indeqs commented Jun 1, 2024

Related Issue

Checklist

Describe the changes you've made:

Addition of a vulnerability shading light on the dangers of using abi.encodePacked() with multiple variable-length arguments that could potentially led to a hash collision. This specific vulnerability can lead to security issues in smart contracts, particularly in signature verification scenarios, allowing attackers to bypass authorization mechanisms.

The added information includes:

  • Description of the Vulnerability: Detailed explanation of how abi.encodePacked() can lead to hash collisions and the potential impact on smart contract security.
  • Examples and Code Analysis: Concrete examples and analysis of vulnerable code, demonstrating how an attacker might exploit this vulnerability.
  • Remediation Strategies: Clear guidance on how to fix the vulnerability, including using abi.encode() instead of abi.encodePacked() and using fixed-length arrays.
  • References: Links to official Solidity documentation and relevant security resources.

Type of change

  • Bug fix (fixing an issue with existing vulnerability data)
  • [✅] New feature (adding a new vulnerability or category)
  • Documentation update (improving existing information)

Copy link
Owner

@kadenzipfel kadenzipfel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good one! If we wanna make the vuln focused on hash collisions I think would be good to include other possible ways for them to occur. Otherwise it could be good to just make the vuln focus on hash collisions due to variable length arguments with encodePacked

vulnerabilities/hash-collision.md Show resolved Hide resolved

## Understanding the vulnerability

When `abi.encodePacked()` is used with multiple variable-length arguments (such as arrays), the packed encoding does not include information about the boundaries between different arguments. This can lead to situations where different combinations of arguments result in the same encoded output, causing hash collisions.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also note that strings fall under this umbrella which seems to be lesser known


To prevent this type of hash collision, the below remediation strategies can be employed:

1. **Avoid Variable-Length Arguments**: Avoid using `abi.encodePacked()` with variable-length arguments. Instead, use fixed-length arrays to ensure the encoding is unique and unambiguous.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should also indicate here that strings should be avoided with encodePacked

vulnerabilities/hash-collision.md Show resolved Hide resolved
## Key Concepts

- **Hash Collision**: A situation where two different sets of inputs produce the same hash output. In this context, a hash collision can occur when using `abi.encodePacked()` with multiple variable-length arguments, allowing an attacker to craft different inputs that produce the same hash.
- **Signature Verification**: A common method for authentication and authorization in smart contracts, where a message signed by a private key is verified using the corresponding public key.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not clear how this plays into this vuln

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do agree that with it included, the text looks like a blogpost explaining what seems like common knowledge.
I put it in there for context to cater for devs, junior security researchers and generally people who may not be that familiar with above said concepts.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's clear here but I'm just referring to "Signature Verification" being included here because I don't actually think it's a relevant concept for this vulnerability

@indeqs
Copy link
Contributor Author

indeqs commented Jun 2, 2024

Good one! If we wanna make the vuln focused on hash collisions I think would be good to include other possible ways for them to occur. Otherwise it could be good to just make the vuln focus on hash collisions due to variable length arguments with encodePacked

Regarding this @kadenzipfel, it would be better to just focus on a single instance of hash collisions and publish a new one when another instance of hash collision is found. Like what is done with DoS vulnerabilities. All situations that can lead to DoS are not in one file but rather separate. Cause I am thinking if we do what you suggest with hash collisions, then we have to do the same for DoS for consistency :)

@rakesh0x7 rakesh0x7 mentioned this pull request Jun 4, 2024
2 tasks
@indeqs
Copy link
Contributor Author

indeqs commented Jun 6, 2024

How is it looking now?

@kadenzipfel kadenzipfel merged commit 0f7c26a into kadenzipfel:master Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants