OneSwap Series 8 — The Evil Has a Name: Re-entrancy

contract C{
function deposit() external{
....
}
function withdraw() external {
uint256 amount = balances[msg.sender];
require(msg.sender.call.value(amount)());
balances[msg.sender] = 0;
}
}
contract C{
bool unlocked;
modifier onlyUnlocked{
require(unlocked,"contract is already locked");
unlocked = false;
_;
unlocked = true;
}
function deposit() external{
....
}
function withdraw() external onlyUnlocked{
uint256 amount = balances[msg.sender];
require(msg.sender.call.value(amount)());
balances[msg.sender] = 0;
}
}
contract C{
function deposit() external{
....
}
function withdraw() external {
uint256 amount = balances[msg.sender];
require(amount != 0,"account balance is zero");
balances[msg.sender] = 0;
require(msg.sender.call.value(amount)());
}
}

Summary

--

--

--

CoinEx Ambassador

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

KlimaDAO: a catalyst for innovation within the Voluntary Carbon Market

Yield Farms launched in collaboration with GYSR, Tutorial

Reddcoin and Musards are singing a duet

HodlerToken current & future

“Ethereum Is the Backbone of the New Internet”

NerveNework & DMEX Collaboration

Blockchain Mining

Plutus DeFi AMA with Arnie Hill and Ali Hararwala

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Coinex India

Coinex India

CoinEx Ambassador

More from Medium

At midnight the Vietnam jungle was starting to quiet down when the whistling of the artillery…

JavaScript’s fetch() and the importance of Asynchronous Execution

CS373 Spring 2022: Mara Manskie

“Enter Shitman”