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

Fix unprotected-update-current-contract-wasm detector #79

Merged
merged 6 commits into from
Feb 27, 2024
Merged
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
16 changes: 13 additions & 3 deletions detectors/unprotected-update-current-contract-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ extern crate rustc_hir;
extern crate rustc_middle;
extern crate rustc_span;

use std::collections::HashSet;

use rustc_hir::{
intravisit::{walk_expr, Visitor},
Expr, ExprKind,
Expand Down Expand Up @@ -82,6 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for UnprotectedUpdateCurrentContractWasm {
BasicBlock::from_u32(0),
false,
&uuf_storage,
&mut HashSet::new(),
);

for span in spans {
Expand All @@ -97,11 +100,12 @@ impl<'tcx> LateLintPass<'tcx> for UnprotectedUpdateCurrentContractWasm {
bb: BasicBlock,
auth_checked: bool,
uuf_storage: &UnprotectedUpdateFinder,
visited: &mut HashSet<BasicBlock>,
) -> Vec<Span> {
let mut ret_vec: Vec<Span> = Vec::<Span>::new();
if bbs[bb].terminator.is_none() {
return ret_vec;
if !visited.insert(bb) || bbs[bb].terminator.is_none() {
return Vec::new();
}
let mut ret_vec: Vec<Span> = Vec::<Span>::new();
let mut checked = auth_checked;
match &bbs[bb].terminator().kind {
TerminatorKind::Call {
Expand Down Expand Up @@ -130,6 +134,7 @@ impl<'tcx> LateLintPass<'tcx> for UnprotectedUpdateCurrentContractWasm {
*utarget,
checked,
uuf_storage,
visited,
));
}
}
Expand All @@ -140,6 +145,7 @@ impl<'tcx> LateLintPass<'tcx> for UnprotectedUpdateCurrentContractWasm {
*target,
checked,
uuf_storage,
visited,
));
}
}
Expand All @@ -151,6 +157,7 @@ impl<'tcx> LateLintPass<'tcx> for UnprotectedUpdateCurrentContractWasm {
*target,
checked,
uuf_storage,
visited,
));
}
TerminatorKind::Yield { resume, .. } => {
Expand All @@ -159,6 +166,7 @@ impl<'tcx> LateLintPass<'tcx> for UnprotectedUpdateCurrentContractWasm {
*resume,
checked,
uuf_storage,
visited,
));
}
TerminatorKind::FalseEdge { real_target, .. }
Expand All @@ -168,6 +176,7 @@ impl<'tcx> LateLintPass<'tcx> for UnprotectedUpdateCurrentContractWasm {
*real_target,
checked,
uuf_storage,
visited,
));
}
TerminatorKind::InlineAsm { destination, .. } => {
Expand All @@ -177,6 +186,7 @@ impl<'tcx> LateLintPass<'tcx> for UnprotectedUpdateCurrentContractWasm {
*udestination,
checked,
uuf_storage,
visited,
));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
soroban-sdk = { version = "20.0.0" }
soroban-sdk = { version = "=20.0.0" }

[dev_dependencies]
soroban-sdk = { version = "20.0.0", features = ["testutils"] }
soroban-sdk = { version = "=20.0.0", features = ["testutils"] }

[features]
testutils = ["soroban-sdk/testutils"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
soroban-sdk = { version = "20.0.0" }
soroban-sdk = { version = "=20.0.0" }

[dev_dependencies]
soroban-sdk = { version = "20.0.0", features = ["testutils"] }
soroban-sdk = { version = "=20.0.0", features = ["testutils"] }

[features]
testutils = ["soroban-sdk/testutils"]
Expand All @@ -27,4 +27,4 @@ lto = true

[profile.release-with-logs]
inherits = "release"
debug-assertions = true
debug-assertions = true
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
soroban-sdk = { version = "20.0.0" }
soroban-sdk = { version = "=20.0.0" }

[dev_dependencies]
soroban-sdk = { version = "20.0.0", features = ["testutils"] }
soroban-sdk = { version = "=20.0.0", features = ["testutils"] }

[features]
testutils = ["soroban-sdk/testutils"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
soroban-sdk = { version = "20.0.0" }
soroban-sdk = { version = "=20.0.0" }

[dev_dependencies]
soroban-sdk = { version = "20.0.0", features = ["testutils"] }
soroban-sdk = { version = "=20.0.0", features = ["testutils"] }

[features]
testutils = ["soroban-sdk/testutils"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
soroban-sdk = { version = "20.0.0" }
soroban-sdk = { version = "=20.0.0" }

[dev_dependencies]
soroban-sdk = { version = "20.0.0", features = ["testutils"] }
soroban-sdk = { version = "=20.0.0", features = ["testutils"] }

[features]
testutils = ["soroban-sdk/testutils"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
soroban-sdk = { version = "20.0.0" }
soroban-sdk = { version = "=20.0.0" }

[dev_dependencies]
soroban-sdk = { version = "20.0.0", features = ["testutils"] }
soroban-sdk = { version = "=20.0.0", features = ["testutils"] }

[features]
testutils = ["soroban-sdk/testutils"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
soroban-sdk = { version = "20.0.0" }
soroban-sdk = { version = "=20.0.0" }

[dev_dependencies]
soroban-sdk = { version = "20.0.0", features = ["testutils"] }
soroban-sdk = { version = "=20.0.0", features = ["testutils"] }

[features]
testutils = ["soroban-sdk/testutils"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
soroban-sdk = { version = "20.0.0" }
soroban-sdk = { version = "=20.0.0" }

[dev_dependencies]
soroban-sdk = { version = "20.0.0", features = ["testutils"] }
soroban-sdk = { version = "=20.0.0", features = ["testutils"] }

[features]
testutils = ["soroban-sdk/testutils"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
soroban-sdk = "20.0.0-rc2"
soroban-sdk = "=20.0.0"

[dev_dependencies]
soroban-sdk = { version = "=20.0.0", features = ["testutils"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
soroban-sdk = "20.0.0-rc2"
soroban-sdk = "=20.0.0"

[dev_dependencies]
soroban-sdk = { version = "=20.0.0", features = ["testutils"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
soroban-sdk = "20.0.0-rc2"
soroban-sdk = "=20.0.0"

[dev_dependencies]
soroban-sdk = { version = "=20.0.0", features = ["testutils"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
soroban-sdk = "20.0.0-rc2"
soroban-sdk = "=20.0.0"

[dev_dependencies]
soroban-sdk = { version = "=20.0.0", features = ["testutils"] }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
soroban-sdk = { version = "=20.0.3" }
soroban-sdk = { version = "=20.3.2" }

[dev_dependencies]
soroban-sdk = { version = "=20.0.3", features = ["testutils"] }
soroban-sdk = { version = "=20.3.2", features = ["testutils"] }

[features]
testutils = ["soroban-sdk/testutils"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
soroban-sdk = "20.0.0-rc2"
soroban-sdk = "=20.0.0"

[dev_dependencies]
soroban-sdk = { version = "=20.0.0", features = ["testutils"] }
Expand All @@ -28,4 +28,4 @@ lto = true

[profile.release-with-logs]
inherits = "release"
debug-assertions = true
debug-assertions = true
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
crate-type = ["cdylib"]

[dependencies]
soroban-sdk = "20.0.0-rc2"
soroban-sdk = "=20.0.0"

[dev_dependencies]
soroban-sdk = { version = "=20.0.0", features = ["testutils"] }
Expand All @@ -28,4 +28,4 @@ lto = true

[profile.release-with-logs]
inherits = "release"
debug-assertions = true
debug-assertions = true
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ impl UpgradeableContract {
}

pub fn upgrade(e: Env, new_wasm_hash: BytesN<32>) {
let admin: Address = e.storage().instance().get(&DataKey::Admin).unwrap();

e.deployer().update_current_contract_wasm(new_wasm_hash);
}
}
Loading