Skip to content

Commit

Permalink
Remove reentrancy library (FuelLabs#3698)
Browse files Browse the repository at this point in the history
## Overview

Closes FuelLabs#3217, migrates the reentrancy library to Sway-libs.

> Notice: Awaiting merge and version bump from Sway-libs ([relevant pull
request](FuelLabs/sway-libs#70)).

## Changes

- remove reentrancy library
- remove reentrancy tests
- modifies documentation to point to new reentrancy guard url
- modifies imports of `std::reentrancy::` to `sway_libs::reentrancy`

---------

Co-authored-by: Mohammad Fawaz <[email protected]>
  • Loading branch information
jtriley2p and mohammadfawaz authored Feb 7, 2023
1 parent 776d8ec commit b80283f
Show file tree
Hide file tree
Showing 25 changed files with 16 additions and 456 deletions.
4 changes: 2 additions & 2 deletions docs/book/src/blockchain-development/calling_contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ fn main() {

A common attack vector for smart contracts is [re-entrancy](https://docs.soliditylang.org/en/v0.8.4/security-considerations.html#re-entrancy). Similar to the EVM, the FuelVM allows for re-entrancy.

A _stateless_ re-entrancy guard is included in the Sway standard library. The guard will panic (revert) at run time if re-entrancy is detected.
A _stateless_ re-entrancy guard is included in the [sway-libs](https://github.com/FuelLabs/sway-libs) library. The guard will panic (revert) at run time if re-entrancy is detected.

```sway
contract;
use std::reentrancy::reentrancy_guard;
use reentrancy::reentrancy_guard;
abi MyContract {
fn some_method();
Expand Down
14 changes: 11 additions & 3 deletions docs/reference/src/code/operations/re_entrency/Forc.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
[[package]]
name = 'core'
source = 'path+from-root-6A09A1886494359D'
source = 'path+from-root-F3A20BA79C738864'

[[package]]
name = 're_entrency'
source = 'root'
source = 'member'
dependencies = [
'reentrancy',
'std',
]

[[package]]
name = 'reentrancy'
source = 'git+https://github.com/FuelLabs/sway-libs?tag=v0.6.0#e238aa410e01c5bdccfba1bfd9c86449f9aec832'
dependencies = ['std']

[[package]]
name = 'std'
source = 'git+https://github.com/fuellabs/sway?tag=v0.30.0#37deaee8fccf5804d78a003cf64f14fac654fc41'
source = 'git+https://github.com/fuellabs/sway?tag=v0.33.1#acd4c1e0fbdc406800a06c845430a80dd3560fcc'
dependencies = ['core']
1 change: 1 addition & 0 deletions docs/reference/src/code/operations/re_entrency/Forc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ license = "Apache-2.0"
name = "re_entrency"

[dependencies]
reentrancy = { git = "https://github.com/FuelLabs/sway-libs", tag = "v0.6.0" }
2 changes: 1 addition & 1 deletion docs/reference/src/code/operations/re_entrency/src/main.sw
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
contract;

// ANCHOR: import
use std::reentrancy::reentrancy_guard;
use reentrancy::reentrancy_guard;
// ANCHOR_END: import
abi Vault {
fn deposit();
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/src/documentation/operations/reentrancy.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ To mitigate security concerns there are two approaches that are commonly used:

## Re-entrancy Guard

Sway provides a stateless [re-entrancy](https://github.com/FuelLabs/sway/blob/master/sway-lib-std/src/reentrancy.sw) guard in the [standard library](https://github.com/FuelLabs/sway/tree/master/sway-lib-std) which reverts at run-time when re-entrancy is detected.
Sway provides a stateless [re-entrancy](https://github.com/FuelLabs/sway-libs/blob/master/libs/reentrancy/src/lib.sw) guard, which reverts at run-time when re-entrancy is detected.

To use the guard we must import it.

Expand Down
1 change: 0 additions & 1 deletion sway-lib-std/src/lib.sw
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ dep math;
dep block;
dep token;
dep ecr;
dep reentrancy;
dep vm/mod;
dep flags;
dep u128;
Expand Down
36 changes: 0 additions & 36 deletions sway-lib-std/src/reentrancy.sw

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit b80283f

Please sign in to comment.