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

(hub): for loops with uint256 save code size not needing overflow checks #72

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/errors/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ interface IHubErrors {
// CirclesErrorNoArgs 3
// error CirclesHubFlowVerticesMustBeSorted();

error CirclesHubFlowEdgeStreamMismatch(uint16 flowEdgeId, uint16 streamId, uint8 code);
error CirclesHubFlowEdgeStreamMismatch(uint256 flowEdgeId, uint256 streamId, uint8 code);

error CirclesHubStreamMismatch(uint16 streamId);
error CirclesHubStreamMismatch(uint256 streamId);

error CirclesHubNettedFlowMismatch(uint16 vertexPosition, int256 matrixNettedFlow, int256 streamNettedFlow);
error CirclesHubNettedFlowMismatch(uint256 vertexPosition, int256 matrixNettedFlow, int256 streamNettedFlow);
}

interface ICirclesDemurrageErrors {
Expand Down
16 changes: 8 additions & 8 deletions src/hub/Hub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ contract Hub is Circles, TypeDefinitions, IHubErrors {
uint16[] memory coordinates = _unpackCoordinates(_packedCoordinates, _flow.length);

// check all senders have the operator authorized
for (uint16 i = 0; i < _streams.length; i++) {
for (uint256 i = 0; i < _streams.length; i++) {
if (!isApprovedForAll(_flowVertices[_streams[i].sourceCoordinate], msg.sender)) {
// Operator not approved for source.
// revert CirclesHubOperatorNotApprovedForSource(
Expand Down Expand Up @@ -777,7 +777,7 @@ contract Hub is Circles, TypeDefinitions, IHubErrors {

{
// check all vertices are valid avatars, groups or organizations
for (uint64 i = 0; i < _flowVertices.length - 1; i++) {
for (uint256 i = 0; i < _flowVertices.length - 1; i++) {
if (uint160(_flowVertices[i]) >= uint160(_flowVertices[i + 1])) {
// Flow vertices must be in ascending order.
// revert CirclesHubFlowVerticesMustBeSorted();
Expand All @@ -802,7 +802,7 @@ contract Hub is Circles, TypeDefinitions, IHubErrors {
// iterate over the coordinate index
uint16 index = uint16(0);

for (uint64 i = 0; i < _flow.length; i++) {
for (uint256 i = 0; i < _flow.length; i++) {
// index: coordinate of Circles identifier avatar address
// index + 1: sender coordinate
// index + 2: receiver coordinate
Expand Down Expand Up @@ -852,7 +852,7 @@ contract Hub is Circles, TypeDefinitions, IHubErrors {
// iterate over the coordinate index
uint16 index = uint16(0);

for (uint16 i = 0; i < _flow.length; i++) {
for (uint256 i = 0; i < _flow.length; i++) {
// index: coordinate of Circles identifier avatar address
// index + 1: sender coordinate
// index + 2: receiver coordinate
Expand Down Expand Up @@ -910,7 +910,7 @@ contract Hub is Circles, TypeDefinitions, IHubErrors {
emit FlowEdgesScopeLastEnded();

// check that all streams are properly defined
for (uint16 i = 0; i < _streams.length; i++) {
for (uint256 i = 0; i < _streams.length; i++) {
if (streamReceivers[i] == address(0) || streamBatchCounter[i] != _streams[i].flowEdgeIds.length) {
// Invalid stream receiver
revert CirclesHubStreamMismatch(i);
Expand All @@ -936,11 +936,11 @@ contract Hub is Circles, TypeDefinitions, IHubErrors {
int256[] memory nettedFlow = new int256[](_flowVertices.length);

// effect the stream transfers with acceptance calls
for (uint16 i = 0; i < _streams.length; i++) {
for (uint256 i = 0; i < _streams.length; i++) {
uint256[] memory ids = new uint256[](_streams[i].flowEdgeIds.length);
uint256[] memory amounts = new uint256[](_streams[i].flowEdgeIds.length);
uint256 streamTotal = uint256(0);
for (uint16 j = 0; j < _streams[i].flowEdgeIds.length; j++) {
for (uint256 j = 0; j < _streams[i].flowEdgeIds.length; j++) {
// the Circles identifier coordinate is the first of three coordinates per flow edge
ids[j] = toTokenId(_flowVertices[_coordinates[3 * _streams[i].flowEdgeIds[j]]]);
amounts[j] = _flow[_streams[i].flowEdgeIds[j]].amount;
Expand Down Expand Up @@ -975,7 +975,7 @@ contract Hub is Circles, TypeDefinitions, IHubErrors {
// revert CirclesArraysLengthMismatch(_streamsNettedFlow.length, _matrixNettedFlow.length, 5);
revert CirclesErrorNoArgs(0xA5);
}
for (uint16 i = 0; i < _streamsNettedFlow.length; i++) {
for (uint256 i = 0; i < _streamsNettedFlow.length; i++) {
if (_streamsNettedFlow[i] != _matrixNettedFlow[i]) {
// Intended flow does not match verified flow.
revert CirclesHubNettedFlowMismatch(i, _matrixNettedFlow[i], _streamsNettedFlow[i]);
Expand Down
Loading