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

Linter: Unprotected terminate_contract #1965

Open
jubnzv opened this issue Oct 31, 2023 · 0 comments
Open

Linter: Unprotected terminate_contract #1965

jubnzv opened this issue Oct 31, 2023 · 0 comments
Labels
A-linter Issue regarding the ink! linter. B-feature-request A request for a new feature.

Comments

@jubnzv
Copy link
Member

jubnzv commented Oct 31, 2023

The terminate_contract function call must be protected with access controls that check the address of the caller. This is necessary to avoid destructing the contract by malicious third-parties.

Examples:

#[ink(message)]
pub fn bad(&mut self) -> Result<()> {
    self.env().terminate_contract(self.sender); // Error: no access control
}

#[ink(message)]
pub fn good(&mut self) -> Result<()> {
    if self.env().caller() == ALLOWED_USER { // OK: Checks the caller
        self.env().terminate_contract(self.sender);
    }
}

The implementation should check the control flow in MIR, finding if there is a statement with conditional expression that uses self.env().caller() prior to the terminate_contract MIR terminator.

Reference: SWC-106

@jubnzv jubnzv added B-feature-request A request for a new feature. A-linter Issue regarding the ink! linter. labels Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linter Issue regarding the ink! linter. B-feature-request A request for a new feature.
Projects
None yet
Development

No branches or pull requests

1 participant