Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Securing Blockchain Networks like Ethereum and Hyperledger Fabric

You're reading from   Securing Blockchain Networks like Ethereum and Hyperledger Fabric Learn advanced security configurations and design principles to safeguard Blockchain networks

Arrow left icon
Product type Paperback
Published in Apr 2020
Publisher Packt
ISBN-13 9781838646486
Length 244 pages
Edition 1st Edition
Languages
Concepts
Arrow right icon
Author (1):
Arrow left icon
Alessandro Parisi Alessandro Parisi
Author Profile Icon Alessandro Parisi
Alessandro Parisi
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Section 1: Blockchain Security Core Concepts
2. Introducing Blockchain Security and Attack Vectors FREE CHAPTER 3. Cryptography Essentials 4. Blockchain Security Assumptions 5. Section 2: Architecting Blockchain Security
6. Trustless Blockchain Networks 7. Securing Hyperledger Fabric 8. Section 3: Securing Decentralized Apps and Smart Contracts
9. Decentralized Apps and Smart Contracts 10. Preventing Threats for DApps and Smart Contracts 11. Section 4: Preserving Data Integrity and Privacy
12. Exploiting Blockchain as an Attack Vector 13. Analyzing Privacy and GDPR Compliance Issues 14. Other Books You May Enjoy

Preventing smart contract attacks

We have seen how many attacks on smart contracts are often due to bugs contained within the source code. To prevent the occurrence of these bugs, it is thus appropriate to use specialized library functions that help the developer in the safe implementation of the most common functions. One of these libraries is the SafeMath library of the OpenZeppelin package (available at https://github.com/OpenZeppelin/openzeppelin-solidity).

By using the SafeMath library, it is possible to prevent bugs such as integer overflows and underflows.

In the following example, we show an excerpt of the implementation of the add() function offered by the SafeMath library:

pragma solidity ^0.4.24;

library SafeMath {

...

/**
* @dev Function to add two numbers
*/
function add(uint256 a, uint256 b)
internal pure returns (uint256 c) {
c = a + b;
assert(c >= a);
...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image