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

Improve NatSpec documentation #18

Merged
merged 27 commits into from
Mar 11, 2024
Merged

Improve NatSpec documentation #18

merged 27 commits into from
Mar 11, 2024

Conversation

xenoliss
Copy link
Contributor

@xenoliss xenoliss commented Mar 7, 2024

This PR generally improves NatSpec doc on the contracts and replaces PR #17

/// NOTE: `uint256` rather than a smaller uint because it provides flexibility,
/// in that we will practically never run out of indices.
///
/// In the context of checking whether something was signed by an owner this
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not true in the normal ethereum address case because ecrecover returns the address

mapping(bytes => bool) isOwner;
/// @dev Mapping of indices to raw owner bytes, used to idenfitied owners by their
/// uint256 id (to economize calldata).
/// NOTE: `uint256` rather than a smaller uint because it provides flexibility,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's important to explain the "flexibility at little to no cost"

function _addOwnerAtIndex(bytes memory owner, uint256 index) internal virtual {
if (isOwnerBytes(owner)) revert AlreadyOwner(owner);

_getMultiOwnableStorage().isOwner[owner] = true;
_getMultiOwnableStorage().ownerAtIndex[index] = owner;

emit AddOwner(index, owner);
emit AddOwner({index: index, owner: owner});
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the thought here? We don't use type args elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No we don't but I think we should use them more. It helps for readability and increase confidence about writing sound contracts (avoid swapping params).

Copy link
Contributor

Choose a reason for hiding this comment

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

I actually think they are more cluttering than helpful. We should lean on good variable names to avoid swapping params

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah I find it redundant here and we should be consistent with our events

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 understand your point and agree that it might be redundant, so I will remove them.

However, from my experience, using named parameters has the great benefit of ensuring, without any context about what the function does, nor about its parameter names and types, that the call is most likely correct. When conducting code reviews, I find it much easier to read, as I don't have to hop between the function definition and the function call to make sure the developer wrote what they really intended. You don't have to be a skilled auditor to notice that transfer({to: from, from: to, amount: amount}) is incorrect, which I believe is important if we want to provide secure and foolproof open-source code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes thanks @xenoliss, let's file these away for our style guide discussion, after which we can commit to using the same approach in all places

function initCodeHash() public view virtual returns (bytes32 result) {
result = LibClone.initCodeHashERC1967(implementation);
}

/// @dev Returns the salt that will be used for deterministic address
/// @notice Returns the salt that will be / was used to deploy the account (using create2).
Copy link
Contributor

@stevieraykatz stevieraykatz Mar 8, 2024

Choose a reason for hiding this comment

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

I think this reads more clearly:

Suggested change
/// @notice Returns the salt that will be / was used to deploy the account (using create2).
/// @notice Returns the deterministic salt for a specific set of `owners` and `nonce`

src/ERC1271.sol Outdated
/// @notice Validate the `signature` against the given `message`.
///
/// @dev MUST be defined by the implementation.
/// @dev The `signature` content MIGHT NOT necessarily be the usual (r,s,v) values. It is the responsability
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// @dev The `signature` content MIGHT NOT necessarily be the usual (r,s,v) values. It is the responsability
/// @dev The `signature` content MIGHT NOT necessarily be the usual (r,s,v) values. It is the responsibility

0x97e2c6aad4ce5d562ebfaa00db6b9e0fb66ea5d8162ed5b243f51a2e03086f00;

/// @notice Reverted when the sender is not an owner and is trying to call a privileged function.
Copy link
Contributor

Choose a reason for hiding this comment

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

Picking up where the comments ended on the previous pr...

This reads weird to me still. The errors aren't reverting; they are being thrown when reverting. I won't die on this hill but i'm not a fan.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think "thrown when" might be better phrasing :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright going to update to "thrown when".

Copy link
Contributor

Choose a reason for hiding this comment

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

Still thinking about this, given the call is revert error() rather than throw error() maybe @xenoliss had this right 🤔

Although the docs use thrown so let's stick with it

Copy link
Contributor Author

@xenoliss xenoliss Mar 10, 2024

Choose a reason for hiding this comment

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

I'm used to Reverted when XXX so I am defiitely biased but when re-reading the docs it is true that errors are not "reverted"; the state is.

function _addOwnerAtIndex(bytes memory owner, uint256 index) internal virtual {
if (isOwnerBytes(owner)) revert AlreadyOwner(owner);

_getMultiOwnableStorage().isOwner[owner] = true;
_getMultiOwnableStorage().ownerAtIndex[index] = owner;

emit AddOwner(index, owner);
emit AddOwner({index: index, owner: owner});
Copy link
Contributor

Choose a reason for hiding this comment

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

I actually think they are more cluttering than helpful. We should lean on good variable names to avoid swapping params

@xenoliss
Copy link
Contributor Author

I removed the usage of named parameters in the last commit bd548a8. I think we're good to merge.

@wilsoncusack wilsoncusack merged commit 299bc7b into coinbase:main Mar 11, 2024
1 check passed
@xenoliss xenoliss deleted the natspec branch March 11, 2024 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants