MystenLabs / sui

Sui, a next-generation smart contract platform with high throughput, low latency, and an asset-oriented programming model powered by the Move programming language
https://sui.io
Apache License 2.0
6.22k stars 11.2k forks source link

Linter: prevent orphaning of dynamic fields #13816

Open awelc opened 1 year ago

awelc commented 1 year ago

Description

Why: The values bound to these dynamic fields will get orphaned when the struct value goes out of scope

Severity: High. Orphaning objects loses $$ because the storage rebate associated with the orphaned object can never be recovered

awelc commented 1 year ago

Another variant of this.

A struct may have multiple IDs:

struct X { 
  id: UID
  id2: UID
  id3: UID
}

or

struct Y {
  ids: vector<vector<UID>>
}

or

struct Z {
  ids: Table<String, UID>
}

We could try to figure out which UIDs have dynamic fields attached to them (step 1) and yell if you object::deleted on on of these UIDs.

awelc commented 1 year ago

Possible implementation strategy: