Skip to content

Commit

Permalink
Merge pull request #153 from CirclesUBI/20240518-change-FlowEdge-Amou…
Browse files Browse the repository at this point in the history
…nt-uint192

(FlowEdge): change amount to uint192
  • Loading branch information
jaensen authored Jun 7, 2024
2 parents 10cb6b1 + f3409ad commit 9bf366d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/hub/TypeDefinitions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract TypeDefinitions {

struct FlowEdge {
uint16 streamSinkId;
uint240 amount; // todo: set this to uint192 (align with demurrage), and leave it to compiler to pad
uint192 amount; // todo: set this to uint192 (align with demurrage), and leave it to compiler to pad
}

struct Stream {
Expand Down
17 changes: 8 additions & 9 deletions src/operators/SignedPathOperator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,19 @@ contract SignedPathOperator is BaseOperator, TypeDefinitions {
FlowEdge[] calldata _flow,
Stream[] calldata _streams,
bytes calldata _packedCoordinates,
uint256 _sourceIndex
uint256 _sourceCoordinate
) external {
// Extract the alleged source vertex from the flow vertices
uint16 sourceCoordinate = _extractSource(_packedCoordinates, _sourceIndex);
address source = _flowVertices[sourceCoordinate];
address source = _flowVertices[_sourceCoordinate];
// Ensure the source is the caller
if (msg.sender != source) {
revert CirclesInvalidFunctionCaller(msg.sender, source, 0);
}

// check that for every stream the source of the stream matches the alleged single source
for (uint256 i = 0; i < _streams.length; i++) {
if (_streams[i].sourceCoordinate != sourceCoordinate) {
revert CirclesOperatorInvalidStreamSource(i, sourceCoordinate, _streams[i].sourceCoordinate);
if (_streams[i].sourceCoordinate != _sourceCoordinate) {
revert CirclesOperatorInvalidStreamSource(i, _sourceCoordinate, _streams[i].sourceCoordinate);
}
}

Expand All @@ -46,8 +45,8 @@ contract SignedPathOperator is BaseOperator, TypeDefinitions {

// Internal functions

function _extractSource(bytes calldata _packedCoordinates, uint256 _sourceIndex) internal pure returns (uint16) {
return
uint16(uint8(_packedCoordinates[_sourceIndex])) << 8 | uint16(uint8(_packedCoordinates[_sourceIndex + 1]));
}
// function _extractSource(bytes calldata _packedCoordinates, uint256 _sourceIndex) internal pure returns (uint16) {
// return
// uint16(uint8(_packedCoordinates[_sourceIndex])) << 8 | uint16(uint8(_packedCoordinates[_sourceIndex + 1]));
// }
}
2 changes: 1 addition & 1 deletion test/hub/PathTransferHub.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ contract HubPathTransferTest is Test, TimeCirclesSetup, HumanRegistration, Appro
// for each row in the flow matrix specify the coordinates and amount
for (uint256 i = 0; i < M - 1; i++) {
// flow is the amount of Circles to send, here constant for each edge
flow[i].amount = uint240(5 * CRC);
flow[i].amount = uint192(5 * CRC);
flow[i].streamSinkId = uint16(0);
// first index indicates which Circles to use
// for our example, we use the Circles of the sender
Expand Down

0 comments on commit 9bf366d

Please sign in to comment.