Skip to content

Prevent submitting calls to messages marked as immutable#1397

Merged
xermicus merged 4 commits intomasterfrom
cl/prevent-immtuable-message-calls
Nov 13, 2023
Merged

Prevent submitting calls to messages marked as immutable#1397
xermicus merged 4 commits intomasterfrom
cl/prevent-immtuable-message-calls

Conversation

@xermicus
Copy link
Copy Markdown
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 <bigcyrill@hotmail.com>
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Signed-off-by: Cyrill Leutwiler <bigcyrill@hotmail.com>
Co-authored-by: German <german@parity.io>
@xermicus xermicus merged commit e2d9900 into master Nov 13, 2023
@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