Skip to content
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

Prevent remove storage flag when there are something stored #1227

Merged
merged 5 commits into from
Nov 14, 2019
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
12 changes: 12 additions & 0 deletions neo.UnitTests/SmartContract/UT_InteropService.NEO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,18 @@ public void TestContract_Update()
engine.CurrentContext.EvaluationStack.Push(manifest.ToString());
engine.CurrentContext.EvaluationStack.Push(script);
InteropService.Invoke(engine, InteropService.Neo_Contract_Update).Should().BeTrue();

// Remove Storage flag with something stored

state.Manifest.Features = ContractFeatures.NoProperty;
mockSnapshot.SetupGet(p => p.Contracts).Returns(new TestDataCache<UInt160, ContractState>(state.ScriptHash, state));
mockSnapshot.SetupGet(p => p.Storages).Returns(new TestDataCache<StorageKey, StorageItem>(storageKey, storageItem));

engine = new ApplicationEngine(TriggerType.Application, null, mockSnapshot.Object, 0);
engine.LoadScript(state.Script);
engine.CurrentContext.EvaluationStack.Push(manifest.ToString());
engine.CurrentContext.EvaluationStack.Push(script);
InteropService.Invoke(engine, InteropService.Neo_Contract_Update).Should().BeFalse();
}

[TestMethod]
Expand Down
1 change: 1 addition & 0 deletions neo/SmartContract/InteropService.NEO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ private static bool Contract_Update(ApplicationEngine engine)
contract = engine.Snapshot.Contracts.GetAndChange(contract.ScriptHash);
contract.Manifest = ContractManifest.Parse(manifest);
if (!contract.Manifest.IsValid(contract.ScriptHash)) return false;
if (!contract.HasStorage && engine.Snapshot.Storages.Find(engine.CurrentScriptHash.ToArray()).Any()) return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @shargon, this looks ok, but is there any need to disable storage? If the user already paid for this feature, why would him disable it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scams or bad intentions...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can create again the contract, and start with information

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain to me a case where disabling the storage can benefit anyone? I believe it is a “ok” change, from a business logic perspective, it seems to make sense.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • ScammerICO create a tx when he create a dummy smart contract.
  • ScammerICO set the storages as he want (ownerAddress.Balance=999999999).
  • He migrate the dummy SC, to the ICO smart contract
  • Change the storage flag in the ICO smart contract
  • Destroy it (remaining the information).
  • Two months later.
  • ScammerICO, start the ICO, creating the SmartContract
  • Automatically, it takes the previous stored information, because was not removed.
  • Investors, and explorer has no idea about what happen, but a new smart contract, without TX, have iregular account, hard to follow, and hard to trace.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

return true;
Expand Down