Skip to content

Commit

Permalink
(hub): remove optout from consented flow to protect users
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminbollen committed Aug 5, 2024
1 parent ef8f90f commit 539b9aa
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions src/hub/Hub.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ contract Hub is Circles, TypeDefinitions, IHubErrors {
*/
address private constant SENTINEL = address(0x1);

bytes32 private constant ADVANCED_FLAG_OPTOUT_CONSENTEDFLOW = bytes32(uint256(1));

// State variables

// /**
Expand Down Expand Up @@ -107,12 +105,6 @@ contract Hub is Circles, TypeDefinitions, IHubErrors {
*/
mapping(address => address) public treasuries;

/**
* @notice By default the advanced usage flags should remain set to zero.
* Only for advanced purposes people can consider enabling flags.
*/
mapping(address => bytes32) public advancedUsageFlags;

/**
* @notice The iterable mapping of directional trust relations between avatars and
* their expiry times.
Expand Down Expand Up @@ -561,14 +553,6 @@ contract Hub is Circles, TypeDefinitions, IHubErrors {
_matchNettedFlows(streamsNettedFlow, matrixNettedFlow);
}

function setAdvancedUsageFlag(bytes32 _flag) external {
if (avatars[msg.sender] == address(0)) {
// Only registered avatars can set advanced usage flags.
revert CirclesAvatarMustBeRegistered(msg.sender, 3);
}
advancedUsageFlags[msg.sender] = _flag;
}

// Public functions

/**
Expand Down Expand Up @@ -606,15 +590,18 @@ contract Hub is Circles, TypeDefinitions, IHubErrors {
return uint256(trustMarkers[_truster][_trustee].expiry) >= block.timestamp;
}

/**
* @notice Returns true if the flow to the receiver is permitted.
* The receiver must trust the Circles being sent, and the Circles avatar associated with
* the Circles must trust the receiver.
* @param _to Address of the receiver
* @param _circlesAvatar Address of the Circles avatar of the Circles being sent
* @return permitted true if the flow is permitted, false otherwise
*/
function isPermittedFlow(address _to, address _circlesAvatar) public view returns (bool) {
// if receiver does not trust the Circles being sent, then the flow is not consented regardless
if (uint256(trustMarkers[_to][_circlesAvatar].expiry) < block.timestamp) return false;
// if the advanced usage flag is set to opt-out of consented flow,
// then the uni-directional trust is sufficient
if (advancedUsageFlags[_circlesAvatar] & ADVANCED_FLAG_OPTOUT_CONSENTEDFLOW != bytes32(0)) {
return true;
}
// however, by default the consented flow requires bi-directional trust from center to receiver
// however, consented flow also requires bi-directional trust from center to receiver
return uint256(trustMarkers[_circlesAvatar][_to].expiry) >= block.timestamp;
}

Expand Down

0 comments on commit 539b9aa

Please sign in to comment.