Reader small image

You're reading from  Securing Blockchain Networks like Ethereum and Hyperledger Fabric

Product typeBook
Published inApr 2020
Reading LevelExpert
PublisherPackt
ISBN-139781838646486
Edition1st Edition
Languages
Concepts
Right arrow
Author (1)
Alessandro Parisi
Alessandro Parisi
author image
Alessandro Parisi

Alessandro Parisi has been an IT professional for over 20 years, acquiring significant experience as a Security Data Scientist, and as an Artificial Intelligence Cybersecurity and Blockchain specialist. He has experience of operating within organizational and decisional contexts characterized by high complexity. Over the years, he has helped companies to adopt Artificial Intelligence and Blockchain DLT technologies as strategic tools in protecting sensitive corporate assets. He holds a Master Degree in Economics and Statistics.
Read more about Alessandro Parisi

Right arrow

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 page is locked
Previous PageNext Page
You have been reading a chapter from
Securing Blockchain Networks like Ethereum and Hyperledger Fabric
Published in: Apr 2020Publisher: PacktISBN-13: 9781838646486

Author (1)

author image
Alessandro Parisi

Alessandro Parisi has been an IT professional for over 20 years, acquiring significant experience as a Security Data Scientist, and as an Artificial Intelligence Cybersecurity and Blockchain specialist. He has experience of operating within organizational and decisional contexts characterized by high complexity. Over the years, he has helped companies to adopt Artificial Intelligence and Blockchain DLT technologies as strategic tools in protecting sensitive corporate assets. He holds a Master Degree in Economics and Statistics.
Read more about Alessandro Parisi