Skip to content

Commit

Permalink
a bug in agreement library causing non super app callbacks in IDA case (
Browse files Browse the repository at this point in the history
#246)

* a bug in agreement library causing non super app callbacks in IDA case
  1. due to dividends rights token are no longer part of the test suite, this
regression was not detected.
  2. IDA full test suite should cover this
* bump ethereum-contracts version
  • Loading branch information
hellwolf authored Feb 8, 2021
1 parent 869fd77 commit ec60bf6
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 51 deletions.
106 changes: 58 additions & 48 deletions packages/ethereum-contracts/contracts/agreements/AgreementLibrary.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ library AgreementLibrary {
*************************************************************************/

struct CallbackInputs {
bool isSuperApp;
uint256 noopMask;
ISuperfluidToken token;
address account;
Expand All @@ -73,9 +74,14 @@ library AgreementLibrary {
inputs.account = account;
inputs.agreementId = agreementId;
inputs.agreementData = agreementData;
(bool isSuperApp, bool isJailed, uint256 noopMask) = host.getAppManifest(ISuperApp(account));
// skip the callbacks if the app is already jailed
inputs.noopMask = isSuperApp && !isJailed ? noopMask : type(uint256).max;
{
bool isJailed;
(inputs.isSuperApp, isJailed, inputs.noopMask) = host.getAppManifest(ISuperApp(account));
// skip the callbacks if the app is already jailed
if (isJailed) {
inputs.noopMask = type(uint256).max;
}
}
}

function callAppBeforeCallback(
Expand All @@ -85,25 +91,27 @@ library AgreementLibrary {
internal
returns(bytes memory cbdata)
{
// this will check composit app whitelisting, do not skip!
// otherwise an app could be trapped into an agreement
bytes memory appCtx = _pushCallbackStack(ctx, inputs);
if ((inputs.noopMask & inputs.noopBit) == 0) {
bytes memory callData = abi.encodeWithSelector(
_selectorFromNoopBit(inputs.noopBit),
inputs.token,
address(this) /* agreementClass */,
inputs.agreementId,
inputs.agreementData,
new bytes(0) // placeholder ctx
);
cbdata = ISuperfluid(msg.sender).callAppBeforeCallback(
ISuperApp(inputs.account),
callData,
inputs.noopBit == SuperAppDefinitions.BEFORE_AGREEMENT_TERMINATED_NOOP,
appCtx);
if (inputs.isSuperApp) {
// this will check composit app whitelisting, do not skip!
// otherwise an app could be trapped into an agreement:
bytes memory appCtx = _pushCallbackStack(ctx, inputs);
if ((inputs.noopMask & inputs.noopBit) == 0) {
bytes memory callData = abi.encodeWithSelector(
_selectorFromNoopBit(inputs.noopBit),
inputs.token,
address(this) /* agreementClass */,
inputs.agreementId,
inputs.agreementData,
new bytes(0) // placeholder ctx
);
cbdata = ISuperfluid(msg.sender).callAppBeforeCallback(
ISuperApp(inputs.account),
callData,
inputs.noopBit == SuperAppDefinitions.BEFORE_AGREEMENT_TERMINATED_NOOP,
appCtx);
}
_popCallbackStatck(ctx, 0);
}
_popCallbackStatck(ctx, 0);
}

function callAppAfterCallback(
Expand All @@ -114,33 +122,35 @@ library AgreementLibrary {
internal
returns (ISuperfluid.Context memory appContext, bytes memory appCtx)
{
// this will check composit app whitelisting, do not skip!
// otherwise an app could be trapped into an agreement
appCtx = _pushCallbackStack(ctx, inputs);
if ((inputs.noopMask & inputs.noopBit) == 0) {
bytes memory callData = abi.encodeWithSelector(
_selectorFromNoopBit(inputs.noopBit),
inputs.token,
address(this) /* agreementClass */,
inputs.agreementId,
inputs.agreementData,
cbdata,
new bytes(0) // placeholder ctx
);
appCtx = ISuperfluid(msg.sender).callAppAfterCallback(
ISuperApp(inputs.account),
callData,
inputs.noopBit == SuperAppDefinitions.AFTER_AGREEMENT_TERMINATED_NOOP,
appCtx);

appContext = ISuperfluid(msg.sender).decodeCtx(appCtx);

// adjust allowance used to the range [appAllowanceWanted..appAllowanceGranted]
appContext.appAllowanceUsed = max(0, min(
inputs.appAllowanceGranted.toInt256(),
max(appContext.appAllowanceWanted.toInt256(), appContext.appAllowanceUsed)));

appCtx = _popCallbackStatck(ctx, appContext.appAllowanceUsed);
if (inputs.isSuperApp) {
// this will check composit app whitelisting, do not skip!
// otherwise an app could be trapped into an agreement
appCtx = _pushCallbackStack(ctx, inputs);
if ((inputs.noopMask & inputs.noopBit) == 0) {
bytes memory callData = abi.encodeWithSelector(
_selectorFromNoopBit(inputs.noopBit),
inputs.token,
address(this) /* agreementClass */,
inputs.agreementId,
inputs.agreementData,
cbdata,
new bytes(0) // placeholder ctx
);
appCtx = ISuperfluid(msg.sender).callAppAfterCallback(
ISuperApp(inputs.account),
callData,
inputs.noopBit == SuperAppDefinitions.AFTER_AGREEMENT_TERMINATED_NOOP,
appCtx);

appContext = ISuperfluid(msg.sender).decodeCtx(appCtx);

// adjust allowance used to the range [appAllowanceWanted..appAllowanceGranted]
appContext.appAllowanceUsed = max(0, min(
inputs.appAllowanceGranted.toInt256(),
max(appContext.appAllowanceWanted.toInt256(), appContext.appAllowanceUsed)));

appCtx = _popCallbackStatck(ctx, appContext.appAllowanceUsed);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ethereum-contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@superfluid-finance/ethereum-contracts",
"version": "0.2.4",
"version": "0.2.5",
"description": " Ethereum contracts implementation for the Superfluid Protocol",
"repository": "github:superfluid-finance/protocol-monorepo",
"license": "AGPL-3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ contract("Superfluid Host Contract", accounts => {
);
});

it("#6.24 beforeCreated try to burn just enough gas", async () => {
it("#6.24 beforeCreated try to burn just enough gas [ @skip-on-coverage ]", async () => {
const actionOverhead = 20000; /* some action overhead */
const setNextAction = async () => {
await app.setNextCallbackAction(
Expand Down
2 changes: 1 addition & 1 deletion packages/js-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@ethersproject/contracts": "^5.0.10",
"@ethersproject/providers": "^5.0.21",
"@openzeppelin/test-helpers": "0.5.10",
"@superfluid-finance/ethereum-contracts": "^0.2.4",
"@superfluid-finance/ethereum-contracts": "^0.2.5",
"chai-as-promised": "7.1.1",
"truffle": "5.1.49",
"web3": "^1.3.3",
Expand Down

0 comments on commit ec60bf6

Please sign in to comment.