-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add unit test for reentrancy attack (#221)
- Loading branch information
Showing
8 changed files
with
197 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@fuel-bridge/fungible-token': patch | ||
--- | ||
|
||
Add reentrancy unit test for l2 proxy-bridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
packages/fungible-token/bridge-fungible-token/reentrancy-attacker/Forc.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[project] | ||
authors = ["Fuel Labs <contact@fuel.sh>"] | ||
entry = "reentrancy-attacker.sw" | ||
license = "Apache-2.0" | ||
name = "reentrancy-attacker" | ||
|
||
[dependencies] | ||
contract_message_receiver = { path = "../../../message-predicates/contract-message-receiver" } | ||
standards = { git = "https://github.com/FuelLabs/sway-standards", tag = "v0.5.0" } |
53 changes: 53 additions & 0 deletions
53
packages/fungible-token/bridge-fungible-token/reentrancy-attacker/src/reentrancy-attacker.sw
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
contract; | ||
|
||
use std::execution::run_external; | ||
use standards::{src14::SRC14, src5::{AccessError, State}}; | ||
use contract_message_receiver::MessageReceiver; | ||
|
||
abi ReentrancyAttacker { | ||
#[storage(read, write)] | ||
fn process_message(msg_idx: u64); | ||
|
||
#[storage(read)] | ||
fn get_success() -> bool; | ||
} | ||
|
||
pub enum AttackStage { | ||
Attacking: (), | ||
Success: (), | ||
Finished: (), | ||
} | ||
|
||
configurable { | ||
TARGET: ContractId = ContractId::zero(), | ||
} | ||
|
||
#[namespace(SRC14)] | ||
storage { | ||
attacking: bool = false, | ||
success: bool = false, | ||
} | ||
|
||
impl ReentrancyAttacker for Contract { | ||
#[storage(read, write)] | ||
fn process_message(msg_idx: u64) { | ||
if storage.success.read() { | ||
log(AttackStage::Finished); | ||
return; | ||
} | ||
|
||
log(AttackStage::Attacking); | ||
storage.attacking.write(true); | ||
|
||
let target = abi(MessageReceiver, TARGET.into()); | ||
target.process_message(msg_idx); | ||
|
||
storage.success.write(true); | ||
log(AttackStage::Success); | ||
} | ||
|
||
#[storage(read)] | ||
fn get_success() -> bool { | ||
storage.success.read() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters