Skip to content

Commit 7312731

Browse files
committed
rollback modified, more verbose comments instead. More robust argument checking for pool-only methods.
1 parent 0db855d commit 7312731

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

packages/ethereum-contracts/contracts/agreements/gdav1/GeneralDistributionAgreementV1.sol

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,11 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
370370
bool doConnect,
371371
bytes memory ctx
372372
)
373-
// _poolIsTrustedByItsSuperToken(pool) // TODO
374373
internal
375374
returns (bool success)
376375
{
377376
ISuperfluidToken token = pool.superToken();
377+
// TODO: convert to modifier `poolIsTrustedByItsSuperToken(pool)`
378378
if (!token.isPool(this, address(pool))) {
379379
revert GDA_ONLY_SUPER_TOKEN_POOL();
380380
}
@@ -452,9 +452,12 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
452452

453453
newCtx = ctx;
454454

455-
if (token.isPool(this, address(pool)) == false || // TODO: with _poolIsTrustedByItsSuperToken
455+
// TODO: convert to modifier `poolIsTrustedByItsSuperToken(pool)`
456+
if (
457+
token.isPool(this, address(pool)) == false ||
456458
// Note: we do not support multi-tokens pools
457-
pool.superToken() != token) {
459+
pool.superToken() != token)
460+
{
458461
revert GDA_ONLY_SUPER_TOKEN_POOL();
459462
}
460463

@@ -518,9 +521,12 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
518521
int96 requestedFlowRate,
519522
bytes calldata ctx
520523
) external override returns (bytes memory newCtx) {
521-
if (token.isPool(this, address(pool)) == false || // TODO _poolIsTrustedByItsSuperTokne
524+
// TODO: convert to modifier `poolIsTrustedByItsSuperToken(pool)`
525+
if (
526+
token.isPool(this, address(pool)) == false ||
522527
// Note: we do not support multi-tokens pools
523-
pool.superToken() != token) {
528+
pool.superToken() != token)
529+
{
524530
revert GDA_ONLY_SUPER_TOKEN_POOL();
525531
}
526532
if (requestedFlowRate < 0) {
@@ -804,28 +810,49 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
804810

805811
//
806812
// Pool-only operations
807-
//
813+
// Can only be called (`msg.sender`) by legitimate pool contracts.
814+
// If `token` is legitimate, `token.isPool()` can return true only if the pool was created by this agreement.
815+
// "false positives" (does not revert for illegitimate caller) could occur if `token`:
816+
// 1. is lying (claims the pool was registered by this agreement when it was not)
817+
// or
818+
// 2. is not associated to the same host (and agreements).
819+
// In both cases, pre-conditions are not met and no state this agreement is responsible for can be manipulated.
808820

809821
function appendIndexUpdateByPool(ISuperfluidToken token, BasicParticle memory p, Time t)
810822
external
811-
senderIsTrustedPool
812823
returns (bool)
813824
{
814825
address poolAddress = msg.sender;
815826

827+
// TODO: convert to modifier `poolIsTrustedByItsSuperToken(pool)`
828+
if (
829+
token.isPool(this, msg.sender) == false ||
830+
ISuperfluidPool(poolAddress).superToken() != token
831+
) {
832+
revert GDA_ONLY_SUPER_TOKEN_POOL();
833+
}
834+
816835
bytes memory eff = abi.encode(token);
817836
_setUIndex(eff, msg.sender, _getUIndex(eff, poolAddress).mappend(p));
818837
_setPoolAdjustmentFlowRate(eff, poolAddress, true, /* doShift? */ p.flow_rate(), t);
819838
return true;
820839
}
821840

841+
// succeeds only if `msg.sender` is a pool trusted by `token`
822842
function poolSettleClaim(ISuperfluidToken token, address claimRecipient, int256 amount)
823843
external
824-
senderIsTrustedPool
825844
returns (bool)
826845
{
827846
address poolAddress = msg.sender;
828847

848+
// TODO: convert to modifier `poolIsTrustedByItsSuperToken(pool)`
849+
if (
850+
token.isPool(this, msg.sender) == false ||
851+
ISuperfluidPool(poolAddress).superToken() != token
852+
) {
853+
revert GDA_ONLY_SUPER_TOKEN_POOL();
854+
}
855+
829856
_doShift(abi.encode(token), poolAddress, claimRecipient, Value.wrap(amount));
830857
return true;
831858
}
@@ -981,20 +1008,4 @@ contract GeneralDistributionAgreementV1 is AgreementBase, TokenMonad, IGeneralDi
9811008
token, subscriber, _POOL_SUBS_BITMAP_STATE_SLOT_ID, _POOL_CONNECTIONS_DATA_STATE_SLOT_ID_START
9821009
);
9831010
}
984-
985-
// This check passing means that either the pool is legitimate, or the associated token is not legitimate.
986-
// if the token is legitimate, `token.isPool()` can return true only if the pool was created by this agreement.
987-
// The following "false positives" could occur if the associated token:
988-
// 1. is lying (claims the pool was registered by this agreement when it was not)
989-
// or
990-
// 2. is not associated to the same host (and agreements).
991-
// In both cases, pre-conditions are not met and no state this agreement is responsible for can be manipulated.
992-
modifier senderIsTrustedPool() {
993-
ISuperfluidPool pool = ISuperfluidPool(msg.sender);
994-
995-
if (pool.superToken().isPool(this, address(pool)) == false) {
996-
revert GDA_ONLY_SUPER_TOKEN_POOL();
997-
}
998-
_;
999-
}
10001011
}

0 commit comments

Comments
 (0)