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

Fixing Audit Findings #67

Merged
merged 26 commits into from
Jul 3, 2024
Merged

Fixing Audit Findings #67

merged 26 commits into from
Jul 3, 2024

Conversation

zeroknots
Copy link
Member

No description provided.

fixed threshold finding

using associated storage to store attesters to be 4337 compliant
@@ -41,7 +41,7 @@ struct TrustedAttesterRecord {
uint8 attesterCount; // number of attesters in the linked list
uint8 threshold; // minimum number of attesters required
address attester; // first attester in linked list. (packed to save gas)
mapping(address attester => address linkedAttester) linkedAttesters; // linked list
mapping(address attester => mapping(address account => address linkedAttester)) linkedAttesters;
Copy link
Member Author

@zeroknots zeroknots May 28, 2024

Choose a reason for hiding this comment

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

NOTE: using associated storage to comply with 4337

@@ -119,7 +119,17 @@ abstract contract TrustManager is IRegistry {
// use this condition to save gas
else if (threshold == 1) {
AttestationRecord storage $attestation = $getAttestation({ module: module, attester: attester });
$attestation.enforceValid(moduleType);
if ($attestation.checkValid(moduleType)) return;
Copy link
Member Author

@zeroknots zeroknots May 28, 2024

Choose a reason for hiding this comment

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

NOTE: added this routine, to handle the case that threshold == 1, but the first attester doesnt have an attestation

* ⚡️ Adding msg.sender separation for factory calls
* In order to separate msg.sender context from registry,
* interactions with external Factories are done with this Trampoline contract.
*/
contract FactoryTrampoline {
Copy link
Member Author

Choose a reason for hiding this comment

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

NOTE: added factory call trampoline, so calls made to factory dont come from msg.sender == registry

if ($getAttestation(module, attesters[i]).checkValid(ZERO_MODULE_TYPE)) {
address attester = attesters[i];
if (attester < _attesterCache) revert InvalidTrustedAttesterInput();
else _attesterCache = attester;
Copy link
Member Author

Choose a reason for hiding this comment

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

NOTE: adding check here to ensure provided list is sorted and unique. thus deduped

src/core/TrustManager.sol Outdated Show resolved Hide resolved
// if attesters array has duplicates, revert
if (attestersLength == 0) revert InvalidTrustedAttesterInput();
// if attesters array has duplicates or is too large revert
if (attestersLength == 0 || attestersLength > type(uint8).max) revert InvalidTrustedAttesterInput();
Copy link
Member Author

Choose a reason for hiding this comment

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

NOTE: adding check to prevent attester length to be over uint8 thus preventing cast issue

@@ -48,7 +80,7 @@ abstract contract ModuleManager is IRegistry, ResolverManager {
returns (address moduleAddress)
{
ResolverRecord storage $resolver = $resolvers[resolverUID];
if ($resolver.resolverOwner == ZERO_ADDRESS) revert InvalidResolver($resolver.resolver);
if ($resolver.resolverOwner == ZERO_ADDRESS) revert InvalidResolverUID(resolverUID);
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: making revert message consistent

@@ -73,7 +105,7 @@ abstract contract ModuleManager is IRegistry, ResolverManager {
ResolverRecord storage $resolver = $resolvers[resolverUID];

// ensure that non-zero resolverUID was provided
if ($resolver.resolverOwner == ZERO_ADDRESS) revert InvalidResolver($resolver.resolver);
if ($resolver.resolverOwner == ZERO_ADDRESS) revert InvalidResolverUID(resolverUID);
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: making revert message consistent

@@ -149,12 +159,15 @@ abstract contract TrustManager is IRegistry {
uint256 count = $trustedAttesters.attesterCount;
address attester0 = $trustedAttesters.attester;

// return if no trusted attesters are set
if (count == 0) return attesters;
Copy link
Member Author

Choose a reason for hiding this comment

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

NOTE: prevent revert in view function if no attesters were set

…orted array, and not sort in in memory to safe gas
if (attesters.length != attestersLength) revert InvalidTrustedAttesterInput();
// revert if the first attester is the zero address
// other attesters can not be zero address, as the array was sorted
if (attesters[0] == ZERO_ADDRESS) revert InvalidTrustedAttesterInput();
Copy link
Member Author

Choose a reason for hiding this comment

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

NOTE: checking address(0)

@@ -96,7 +96,7 @@ library TrustLib {
*/

assembly {
let mask := 0xffffffffffff
Copy link
Member Author

Choose a reason for hiding this comment

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

NOTE: fixing bitmask

@@ -75,12 +75,12 @@ type SchemaUID is bytes32;
using { schemaEq as == } for SchemaUID global;
using { schemaNotEq as != } for SchemaUID global;

function schemaEq(SchemaUID uid1, SchemaUID uid) pure returns (bool) {
return SchemaUID.unwrap(uid1) == SchemaUID.unwrap(uid);
function schemaEq(SchemaUID uid1, SchemaUID uid2) pure returns (bool) {
Copy link
Member Author

Choose a reason for hiding this comment

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

NOTE: fixing inconsistent param namings

Copy link

openzeppelin-code bot commented Jun 14, 2024

Fixing Audit Findings

Generated at commit: aaa9ce117b9cf1c9871ba4d940438f7a72d7a2ec

🚨 Report Summary

Severity Level Results
Contracts Critical
High
Medium
Low
Note
Total
2
1
0
5
25
33
Dependencies Critical
High
Medium
Low
Note
Total
0
0
0
0
0
0

For more details view the full report in OpenZeppelin Code Inspector

@kopy-kat kopy-kat merged commit 4c29657 into main Jul 3, 2024
4 checks passed
@kopy-kat kopy-kat deleted the audit/fix branch July 3, 2024 09:19
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