Skip to content

Audit: [X01] Subgraph deployment not updated when no signal #523

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

Merged
merged 1 commit into from
Dec 1, 2021
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
13 changes: 7 additions & 6 deletions contracts/discovery/GNS.sol
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ contract GNS is GNSV2Storage, GraphUpgradeable, IGNS, Multicall {
// NOTE: We will only do this as long as there is signal on the subgraph
if (subgraphData.nSignal > 0) {
// Burn all version signal in the name pool for tokens (w/no slippage protection)
// Sell all signal from the old deployment
uint256 tokens = curation.burn(
subgraphData.subgraphDeploymentID,
subgraphData.vSignal,
Expand All @@ -306,12 +307,9 @@ contract GNS is GNSV2Storage, GraphUpgradeable, IGNS, Multicall {
);

// Update pool: constant nSignal, vSignal can change (w/no slippage protection)
subgraphData.subgraphDeploymentID = _subgraphDeploymentID;
(subgraphData.vSignal, ) = curation.mint(
subgraphData.subgraphDeploymentID,
tokensWithTax,
0
);
// Buy all signal from the new deployment
(subgraphData.vSignal, ) = curation.mint(_subgraphDeploymentID, tokensWithTax, 0);

emit SubgraphUpgraded(
_subgraphID,
subgraphData.vSignal,
Expand All @@ -320,6 +318,9 @@ contract GNS is GNSV2Storage, GraphUpgradeable, IGNS, Multicall {
);
}

// Update target deployment
subgraphData.subgraphDeploymentID = _subgraphDeploymentID;

emit SubgraphVersionUpdated(_subgraphID, _subgraphDeploymentID, _versionMetadata);
}

Expand Down
20 changes: 12 additions & 8 deletions test/gns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,9 @@ describe('GNS', () => {

// Check what selling all nSignal, which == selling all vSignal, should return for tokens
// NOTE - no tax on burning on nSignal
const { 1: tokensReceivedEstimate } = await gns.nSignalToTokens(
subgraphID,
beforeSubgraph.nSignal,
)
const tokensReceivedEstimate = beforeSubgraph.nSignal.gt(0)
? (await gns.nSignalToTokens(subgraphID, beforeSubgraph.nSignal))[1]
: toBN(0)
// Example:
// Deposit 100, 5 is taxed, 95 GRT in curve
// Upgrade - calculate 5% tax on 95 --> 4.75 GRT
Expand All @@ -211,10 +210,10 @@ describe('GNS', () => {
const totalAdjustedUp = totalWithOwnerTax.mul(MAX_PPM).div(MAX_PPM - curationTaxPercentage)

// Re-estimate amount of signal to get considering the owner tax paid by the owner
const { 0: newVSignalEstimate, 1: newCurationTaxEstimate } = await curation.tokensToSignal(
newSubgraph.subgraphDeploymentID,
totalAdjustedUp,
)

const { 0: newVSignalEstimate, 1: newCurationTaxEstimate } = beforeSubgraph.nSignal.gt(0)
? await curation.tokensToSignal(newSubgraph.subgraphDeploymentID, totalAdjustedUp)
: [toBN(0), toBN(0)]

// Send tx
const tx = gns
Expand Down Expand Up @@ -620,6 +619,11 @@ describe('GNS', () => {
await publishNewVersion(me, subgraph.id, newSubgraph1)
})

it('should publish a new version on an existing subgraph with no current signal', async function () {
const emptySignalSubgraph = await publishNewSubgraph(me, buildSubgraph())
await publishNewVersion(me, emptySignalSubgraph.id, newSubgraph1)
})

it('should reject a new version with the same subgraph deployment ID', async function () {
const tx = gns
.connect(me.signer)
Expand Down