Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
smonicas committed Jan 24, 2024
1 parent 37884d6 commit 344d96b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
50 changes: 21 additions & 29 deletions tests/detectors/tx_origin.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
#[starknet::interface]
trait ITxOrigin<T> {
fn bad(self: @T) -> bool;
fn bad_indirect(self: @T) -> bool;
fn good(self: @T) -> starknet::ContractAddress;
}

#[starknet::contract]
mod TxOrigin {
use core::box::BoxTrait;
Expand All @@ -15,31 +8,30 @@ mod TxOrigin {
struct Storage {}

#[external(v0)]
impl TxOrigin of super::ITxOrigin<ContractState> {
fn bad(self: @ContractState) -> bool {
let tx_info = get_tx_info().unbox();
let tx_origin = tx_info.account_contract_address;
let owner = contract_address_const::<1>();
tx_origin == owner
}
fn bad(self: @ContractState) -> bool {
let tx_info = get_tx_info().unbox();
let tx_origin = tx_info.account_contract_address;
let owner = contract_address_const::<1>();
tx_origin == owner
}

fn bad_indirect(self: @ContractState) -> bool {
let tx_info = get_tx_info().unbox();
let tx_origin = tx_info.account_contract_address;
self._check_tx_origin(tx_origin)
}
#[external(v0)]
fn bad_indirect(self: @ContractState) -> bool {
let tx_info = get_tx_info().unbox();
let tx_origin = tx_info.account_contract_address;
_check_tx_origin(tx_origin)
}

fn good(self: @ContractState) -> ContractAddress {
let tx_info = get_tx_info().unbox();
tx_info.account_contract_address
}
#[external(v0)]
fn good(self: @ContractState) -> ContractAddress {
let tx_info = get_tx_info().unbox();
tx_info.account_contract_address
}

#[generate_trait]
impl InternalFunctions of InternalFunctionsTrait {
fn _check_tx_origin(self: @ContractState, tx_origin: ContractAddress) -> bool {
let owner = contract_address_const::<1>();
tx_origin == owner
}

fn _check_tx_origin(tx_origin: ContractAddress) -> bool {
let owner = contract_address_const::<1>();
tx_origin == owner
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ input_file: tests/detectors/tx_origin.cairo
impact: High,
name: "dangerous-use-of-transaction-origin",
confidence: Medium,
message: "The transaction origin contract addresses is used in an authentication check in the function tx_origin::tx_origin::TxOrigin::TxOrigin::bad",
message: "The transaction origin contract address is used in an authentication check in the function tx_origin::tx_origin::TxOrigin::bad",
},
Result {
impact: High,
name: "dangerous-use-of-transaction-origin",
confidence: Medium,
message: "The transaction origin contract addresses is used in an authentication check in the function tx_origin::tx_origin::TxOrigin::TxOrigin::bad_indirect",
message: "The transaction origin contract address is used in an authentication check in the function tx_origin::tx_origin::TxOrigin::bad_indirect",
},
]

0 comments on commit 344d96b

Please sign in to comment.