Skip to content

Commit

Permalink
Merge pull request #79 from CoinFabrik/78-fix-unprotected_update_curr…
Browse files Browse the repository at this point in the history
…ent_contract_wasm-detector

Fix unprotected-update-current-contract-wasm detector
  • Loading branch information
tenuki authored Feb 27, 2024
2 parents 589dbc3 + e535b13 commit 650de17
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 32 deletions.
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);
}
}

0 comments on commit 650de17

Please sign in to comment.