Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions crates/checks/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::util::{
use crate::{Check, Finding, Severity};
use syn::spanned::Spanned;
use syn::visit::{self, Visit};
use syn::{Block, ExprIf, ExprMethodCall, File, Visibility};
use syn::{Block, Expr, ExprIf, ExprMethodCall, File, Visibility};

const CHECK_NAME: &str = "unprotected-admin";

Expand Down Expand Up @@ -131,7 +131,10 @@ fn expr_diverges(expr: &Expr) -> bool {
Expr::Return(_) => true,
Expr::Macro(expr) => expr.mac.path.is_ident("panic"),
Expr::MethodCall(expr) => {
matches!(expr.method.to_string().as_str(), "require_auth" | "require_auth_for_args")
matches!(
expr.method.to_string().as_str(),
"require_auth" | "require_auth_for_args"
)
}
Expr::Block(expr) => block_diverges(&expr.block),
Expr::If(expr) => {
Expand Down Expand Up @@ -197,7 +200,12 @@ impl<'ast> Visit<'ast> for AuthGateScan {
fn visit_expr_if(&mut self, i: &'ast ExprIf) {
let had_tracked_var = !self.storage_read_vars.is_empty();
visit::visit_expr_if(self, i);
if had_tracked_var && !self.storage_read_and_conditional {
let branch_diverges = block_diverges(&i.then_branch)
|| i
.else_branch
.as_ref()
.is_some_and(|(_, branch)| expr_diverges(branch));
if had_tracked_var && branch_diverges && !self.storage_read_and_conditional {
let all_names: Vec<String> = self
.storage_read_vars
.iter()
Expand Down Expand Up @@ -230,7 +238,10 @@ fn expr_references_any(expr: &syn::Expr, names: &std::collections::HashSet<Strin
visit::visit_expr_path(self, node);
}
}
let mut v = RefVisitor { names, found: false };
let mut v = RefVisitor {
names,
found: false,
};
visit::visit_expr(&mut v, expr);
v.found
}
Expand Down
11 changes: 4 additions & 7 deletions crates/checks/src/missing_nonce.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::util::{contractimpl_functions_excluding_test, receiver_chain_contains_storage};
use crate::util::{contractimpl_functions_excluding_test, is_storage_mutation_call};
use crate::{Check, Finding, Severity};
use syn::visit::{self, Visit};
use syn::FnArg;
Expand Down Expand Up @@ -61,11 +61,7 @@ struct StorageWriteVisitor {

impl<'ast> Visit<'ast> for StorageWriteVisitor {
fn visit_expr_method_call(&mut self, node: &'ast syn::ExprMethodCall) {
if matches!(
node.method.to_string().as_str(),
"set" | "remove" | "append" | "push" | "push_back"
) && receiver_chain_contains_storage(&node.receiver)
{
if is_storage_mutation_call(node) {
self.found_write = true;
}
visit::visit_expr_method_call(self, node);
Expand Down Expand Up @@ -273,7 +269,8 @@ impl C {
let findings = check.run(&file, src);
assert!(
findings.is_empty(),
"tx_nonce should be recognised as nonce protection, got: {:?}", findings
"tx_nonce should be recognised as nonce protection, got: {:?}",
findings
);
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion docs/checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ Soroban contracts run under a fixed compute-budget cap. An unbounded loop can ex
Public methods in `#[contractimpl]` that:

1. Accept at least one `Address` parameter, and
2. Perform a storage write (`set`, `remove`, `append`, `push`, or `push_back`), and
2. Perform a storage write (`set`, `remove`, or `append`), and
3. Contain no reference to a nonce or replay-protection identifier — specifically, no identifier matching `nonce`, `sequence`, `seq_num`, or `replay` in the function body.

**Why it matters**
Expand Down