Skip to content

Commit af5f8a5

Browse files
authored
Merge pull request #523 from graphprotocol/audit/gns-ownership-x01
Audit: [X01] Subgraph deployment not updated when no signal
2 parents 6a86c16 + 3482568 commit af5f8a5

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

contracts/discovery/GNS.sol

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ contract GNS is GNSV2Storage, GraphUpgradeable, IGNS, Multicall {
290290
// NOTE: We will only do this as long as there is signal on the subgraph
291291
if (subgraphData.nSignal > 0) {
292292
// Burn all version signal in the name pool for tokens (w/no slippage protection)
293+
// Sell all signal from the old deployment
293294
uint256 tokens = curation.burn(
294295
subgraphData.subgraphDeploymentID,
295296
subgraphData.vSignal,
@@ -306,12 +307,9 @@ contract GNS is GNSV2Storage, GraphUpgradeable, IGNS, Multicall {
306307
);
307308

308309
// Update pool: constant nSignal, vSignal can change (w/no slippage protection)
309-
subgraphData.subgraphDeploymentID = _subgraphDeploymentID;
310-
(subgraphData.vSignal, ) = curation.mint(
311-
subgraphData.subgraphDeploymentID,
312-
tokensWithTax,
313-
0
314-
);
310+
// Buy all signal from the new deployment
311+
(subgraphData.vSignal, ) = curation.mint(_subgraphDeploymentID, tokensWithTax, 0);
312+
315313
emit SubgraphUpgraded(
316314
_subgraphID,
317315
subgraphData.vSignal,
@@ -320,6 +318,9 @@ contract GNS is GNSV2Storage, GraphUpgradeable, IGNS, Multicall {
320318
);
321319
}
322320

321+
// Update target deployment
322+
subgraphData.subgraphDeploymentID = _subgraphDeploymentID;
323+
323324
emit SubgraphVersionUpdated(_subgraphID, _subgraphDeploymentID, _versionMetadata);
324325
}
325326

test/gns.test.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,9 @@ describe('GNS', () => {
190190

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

213212
// Re-estimate amount of signal to get considering the owner tax paid by the owner
214-
const { 0: newVSignalEstimate, 1: newCurationTaxEstimate } = await curation.tokensToSignal(
215-
newSubgraph.subgraphDeploymentID,
216-
totalAdjustedUp,
217-
)
213+
214+
const { 0: newVSignalEstimate, 1: newCurationTaxEstimate } = beforeSubgraph.nSignal.gt(0)
215+
? await curation.tokensToSignal(newSubgraph.subgraphDeploymentID, totalAdjustedUp)
216+
: [toBN(0), toBN(0)]
218217

219218
// Send tx
220219
const tx = gns
@@ -620,6 +619,11 @@ describe('GNS', () => {
620619
await publishNewVersion(me, subgraph.id, newSubgraph1)
621620
})
622621

622+
it('should publish a new version on an existing subgraph with no current signal', async function () {
623+
const emptySignalSubgraph = await publishNewSubgraph(me, buildSubgraph())
624+
await publishNewVersion(me, emptySignalSubgraph.id, newSubgraph1)
625+
})
626+
623627
it('should reject a new version with the same subgraph deployment ID', async function () {
624628
const tx = gns
625629
.connect(me.signer)

0 commit comments

Comments
 (0)