# Questions tagged [safemath]

The tag has no usage guidance.

18 questions
Filter by
Sorted by
Tagged with
24 views

### Round integer down to nearest 10

Is there a good way of floor rounding a number to the nearest 10 in solidity? I have a function that calculates a percentage of a number but I want only to return multiples of 10. e.g. if it is 12% ...
47 views

### Using SafeMath with older Solidity compiler

I've been told SafeMath doesn't matter. Does SafeMath slow things down, cost more ETH, or does it add an extra level of stability? Will SafeMath be unsupported one day? contract SafeMath { function ...
22 views

### How to add three numbers using safemath?

I know this might sound obvious but in solidity you can never be too sure. Let us say I have three numbers 5, 7 and 8. Can I add them like so: using SafeMath for uint256; 5.add(7.add(8)); // or even ...
26 views

### How to make a multiplication and division without overflow and any loss of precision in Vyper

How can I calculate X * Y / Z in vyper uint256 without overflow and any loss of precision? I want to build Vyper FullMath library functions similar to the Uniswap V3 FullMath library written in ...
321 views

i have created a token ....but it gives me error " erc20.sol:94:25: TypeError: Member "add" not found or not visible after argument-dependent lookup in uint256. balances[account] = ...
25 views

### Why is the math code causing transactions to fail

Ok so This is my first time working on solidity contracts and I'm at a loss how to debug this code. This code fails: function claimReturns(address claimant) private { uint otherTotals = ...
32 views

### I want to store decimal value in a storage variable and later use that variable at same precision in the formula later internally

I want to store uint public MINTING_VELOCITY = 0.000002; And later use it in the formula: A x t x MINTING_VELOCITY ,where A = 2000 ,t(staking_duration_time) = 120 Issue is currently MINTING_VELOCITY ...
2k views

### Is the SafeMath library obsolete in solidity 0.8.0?

SafeMath was commonly used to revert the transaction on overflow and underflow, instead of allowing the number to wrap around. The solidity 0.8.0 release notes state: Code Generator: All arithmetic ...
22 views

### calculate exchange rate of WBTC TO WETH in big numbers

i want to calculate how much WETH i will get for a given WBTC amount: const amountsEth = kyber .methods .getExpectedRate( addresses.tokens.wbtc, '...
96 views

### How can I use decimal in solidity

how can i calculate: 1083.83 / 8.25 = 131.37. As I see its not possible in simple way. I have tried a lot of math function but not works. Is there any solution for this?
112 views

### what happens if I do using SafeMath for uint256 but then divide by uint8?

example using SafeMath for uint256; uint8 number8 = 10; uint256 number256 = 1000; function something() { return number256.div(number8); } is it still using safemath even if my number8 is uint8?
448 views

### Chainlink import causing Truffle console to crash

Related issue on GitHub: https://github.com/trufflesuite/truffle/issues/3329 If I compile my contracts with truffle compile and then open the truffle console with truffle develop then this happens: ...
119 views

### Efficient, safe pow using EXP opcode

I recently stumbled across ds-math's rpow() being a O(lg n) safe implementation of exponentiation. Such a function is ultimately created because the EVM EXP opcode is unsafe wrt. overflows. The ...
51 views

### Is there a tool to add SafeMath to production code?

There are a lot of tools to prepare JavaScript/CSS code for production, e.g. to minimize, to convert ES8 code to ES5. Is there a tool to automatically apply SafeMath library to a .sol file? The ...
69 views

### Using Fractions in Leasing contract

I want to create a smart contract that allows people to lend dai stable coin to other or a smart contract at an interest. suppose at 4 % interest I need to calculate (1+0.04/12)^n (n is the period in ...
159 views

### Safemath Library version for Solidity v0.5?

Is there a version of the SafeMath library that is compliant to SOlidity v0.5? Thanks for your inputs in advance