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

[sui-mode][move-compiler] Greatly improve shared_owned lint accuracy #19330

Merged
merged 5 commits into from
Sep 12, 2024

Conversation

tnowacki
Copy link
Contributor

Description

  • The share_owned lint now uses type information to try to determine if an object is "fresh"
    • It assumes an object is fresh if it it comes from a function with not reachable UID inputs. Since in that case, the object could wrapped or coming from a dynamic field
  • Improved filtering to skip this analysis in some cases

Test plan

  • New tests

Release notes

Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required.

For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates.

  • Protocol:
  • Nodes (Validators and Full nodes):
  • Indexer:
  • JSON-RPC:
  • GraphQL:
  • CLI:
  • Rust SDK:
  • REST API:

@tnowacki tnowacki requested a review from a team September 11, 2024 23:22
Copy link

vercel bot commented Sep 11, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sui-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 12, 2024 9:45pm
3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Sep 12, 2024 9:45pm
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Sep 12, 2024 9:45pm
sui-typescript-docs ⬜️ Ignored (Inspect) Visit Preview Sep 12, 2024 9:45pm

// utils
//**************************************************************************************************

pub fn calls_special_function(special: &[(&str, &str, &str)], cfg: &ImmForwardCFG) -> bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These will be generalized a bit in the next PR

@@ -0,0 +1,106 @@
// object is re shared, but it is never transferred and doesn't have public transfer
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there an .exp file missing for this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, they are negative cases so they do not trigger the lint

@@ -95,11 +110,14 @@ impl SimpleAbsIntConstructor for ShareOwnedVerifier {
{
return None;
}
Some(ShareOwnedVerifierAI)
if !calls_special_function(SHARE_FUNCTIONS, cfg) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this an optimization or it actually helps with accuracy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Optimization

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it's worth an entirely separate visit and visitor modifications, but certainly a non-blocking issue for me

@awelc awelc self-requested a review September 12, 2024 18:29
Copy link
Contributor

@awelc awelc left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +258 to +266
if self.sui_info().uid_holders.contains_key(&(m, n)) {
return true;
}
let phantom_positions = phantom_positions(self.info, &m, &n);
phantom_positions
.into_iter()
.zip(targs)
.filter(|(is_phantom, _)| !*is_phantom)
.any(|(_, t)| self.can_hold_obj_base(t))
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be better to do this filtering step when building uid_holders, disregarding phantom types when building it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't really since I need to do this per-type instantiation.

f: &ModuleCall,
args: Vec<Value>,
) {
let Value::NotFreshObj(not_fresh_loc) = &args[0] else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can args[0] here ever panic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not at this point, but maybe above. I'll change

else {
return;
};
let Some(transferred_kind) = self.sui_info().transferred.get(&tn).copied() else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the copy here necessary, or can we get away with a borrow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll immediately copy it below, but doing so brings it inline with the other Loc usages here, so I'll do that, thanks!

@tnowacki tnowacki enabled auto-merge (squash) September 12, 2024 21:44
@tnowacki tnowacki merged commit 8656e4a into MystenLabs:main Sep 12, 2024
44 checks passed
suiwombat pushed a commit that referenced this pull request Sep 16, 2024
…19330)

## Description 

- The share_owned lint now uses type information to try to determine if
an object is "fresh"
- It assumes an object is fresh if it it comes from a function with not
reachable UID inputs. Since in that case, the object could wrapped or
coming from a dynamic field
- Improved filtering to skip this analysis in some cases 

## Test plan 

- New tests 

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants