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 submitting calls to messages marked as immutable #1397

Merged
merged 4 commits into from
Nov 13, 2023

Conversation

xermicus
Copy link
Contributor

@xermicus xermicus commented Nov 13, 2023

Summary

Related issue: use-ink/ink#1969

ink! can't properly prevent messages supposed to be immutable from changing state regardless. Instead, we rely on the client and tooling to honor the mutates field in the metadata.

Description

Without this change, cargo contract will happily execute messages like the one below. This message receives &self which signals it should be immutable. Other contract languages, e.g. Solidity, would refuse to compile this. Instead, we rely on the client to prevent it. The rogue balance transfer is just an illustration; Things like that might come from a rogue snippet or sit inside a rogue library.

        #[ink(message)]
        pub fn get(&self) -> bool {
            // oops
            self.env()
                .transfer(self.env().caller(), self.env().balance())
                .unwrap();

            self.value
        }

Checklist before requesting a review

  • My code follows the style guidelines of this project
  • I have added an entry to CHANGELOG.md
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

Signed-off-by: Cyrill Leutwiler <[email protected]>
Signed-off-by: Cyrill Leutwiler <[email protected]>
crates/extrinsics/src/call.rs Outdated Show resolved Hide resolved
@xermicus xermicus merged commit e2d9900 into master Nov 13, 2023
10 checks passed
@xermicus xermicus deleted the cl/prevent-immtuable-message-calls branch November 13, 2023 13:19
@smiasojed smiasojed mentioned this pull request Nov 30, 2023
@smiasojed smiasojed mentioned this pull request Mar 4, 2024
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.

2 participants