Skip to content

Soroban Unsafe Operations Detection Rule#516

Open
onajidavid87-web wants to merge 4 commits into
MDTechLabs:mainfrom
onajidavid87-web:main
Open

Soroban Unsafe Operations Detection Rule#516
onajidavid87-web wants to merge 4 commits into
MDTechLabs:mainfrom
onajidavid87-web:main

Conversation

@onajidavid87-web

Copy link
Copy Markdown

Created new files like packages/rules/src/stellar/unsafe_operations/mod.rs — UnsafeOperationsRule implementing SorobanLintRule with 5 detection categories:

  1. Panic operations — .unwrap(), .expect(), panic!(), unreachable!(), todo!(), unimplemented!()
  2. Unsafe blocks — unsafe { }
  3. Unprotected invocations — invoke_contract / env.invoke() without prior require_auth
  4. Unchecked arithmetic — raw +, -, *, / without checked_/saturating_ methods
  5. Unbounded loops — loop { } without break/return Each detection produces a RuleViolation with severity, description, and remediation suggestions. Includes 10 inline test cases (#[cfg(test)]). Modified files
  • packages/rules/src/stellar/mod.rs — added pub mod unsafe_operations; and pub use unsafe_operations::*;
  • packages/rules/src/stellar/linting/mod.rs — registered UnsafeOperationsRule in the default SorobanLinter rules list

Closes #496

Created new files like packages/rules/src/stellar/unsafe_operations/mod.rs — UnsafeOperationsRule implementing SorobanLintRule with 5 detection categories:
1. Panic operations — .unwrap(), .expect(), panic!(), unreachable!(), todo!(), unimplemented!()
2. Unsafe blocks — unsafe { }
3. Unprotected invocations — invoke_contract / env.invoke() without prior require_auth
4. Unchecked arithmetic — raw +, -, *, / without checked_/saturating_ methods
5. Unbounded loops — loop { } without break/return
Each detection produces a RuleViolation with severity, description, and remediation suggestions. Includes 10 inline test cases (#[cfg(test)]).
Modified files
- packages/rules/src/stellar/mod.rs — added pub mod unsafe_operations; and pub use unsafe_operations::*;
- packages/rules/src/stellar/linting/mod.rs — registered UnsafeOperationsRule in the default SorobanLinter rules list

Closes MDTechLabs#496
@mijinummi

Copy link
Copy Markdown
Collaborator

Hi @onajidavid87-web kindly fix the remaining 2 ci that are failing. Thanks for your contribution.

@mijinummi

Copy link
Copy Markdown
Collaborator

Hi @onajidavid87-web , you may pull from main update your branch fix the contract by cargo fmt, cargo test then push back. Well done!

@mijinummi

Copy link
Copy Markdown
Collaborator

Hello @onajidavid87-web , you'll be unassigned in the 12hrs if you didn't fix the errors as requested.

Thank you

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.

Implement Soroban Unsafe Operation Detector

2 participants