Skip to content

Commit

Permalink
docs(protocol): add rules about for-loop in solidity (taikoxyz#16264)
Browse files Browse the repository at this point in the history
Co-authored-by: d1onys1us <[email protected]>
  • Loading branch information
dantaik and dionysuzx authored Mar 3, 2024
1 parent 4224546 commit e8f9ac8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,25 @@ struct Some {
}
```

#### For-loop
The variable in the for-loop shall not be initialized with 0, and we enforce using `++var` instead of `var++``.

This is **correct**:

```
for (uint256 i; i < 100; ++i) {
}
```

This is **wrong**:

```
for (uint256 i = 0; i < 100; i++) {
}
```

#### Mentioning other files in the repo

To mention another contract file in the repo use the standard like this:
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/contracts/L1/provers/Guardians.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ abstract contract Guardians is EssentialContract {
delete guardians;

// Set the new guardians
for (uint256 i = 0; i < _newGuardians.length; ++i) {
for (uint256 i; i < _newGuardians.length; ++i) {
address guardian = _newGuardians[i];
if (guardian == address(0)) revert INVALID_GUARDIAN();
// This makes sure there are not duplicate addresses
Expand Down

0 comments on commit e8f9ac8

Please sign in to comment.