Questions tagged [solidity-0.8.x]
The solidity-0.8.x tag has no usage guidance.
22
questions
0
votes
1answer
12 views
parser error when trying to make nested structure for creating a new user
contract PersonalInfo{
enum gender {MALE, FEMALE}
struct Pdetails {
string fName;
string lName;
int256 age;
gender Gender;
}
struct ...
0
votes
2answers
12 views
nested struct in solidity
Can someone help me with a nested struct , i am unable to map the nested struct
my problem statement is i need to get a accept a user details name gender etc and his home address as well in a struct , ...
0
votes
1answer
17 views
Receive keyword in solidity
I was making a smart contract in which I wanted to send and receive ether.
My code:
contract coin_transfer_to {
function() public payable {
}
function get_balance() public returns (uint)
...
1
vote
1answer
20 views
Storage arrays with nested mappings do not support .push(<arg>)
I have a struct with a nested mapping which I am instantiating and trying to push to an array, but I'm receiving the following error on the line i try to push:
Storage arrays with nested mappings do ...
2
votes
1answer
20 views
Is the modulo operation cheaper in unchecked arithmetic?
The docs on Solidity v0.8.0 Breaking Changes mention that overflows are now checked by default:
Arithmetic operations revert on underflow and overflow. You can use unchecked { ... } to use the ...
0
votes
0answers
9 views
Truffle test is failling with transferFrom.call
When I run tests with the following code, I get the following error:
Error
Error: Returned error: VM Exception while processing transaction: revert
Tests
it('Handles delegated token transfers', () =...
2
votes
1answer
17 views
Does the unchecked { … } block apply to the current function alone?
Take the following code snippet:
pragma solidity ^0.8.0;
contract MyContract {
function foo() public returns (uint256 result) {
// do unsafe work
}
function bar() public returns (...
0
votes
0answers
12 views
Solidity beginner exercise: Santa'slist
I am trying to implement the following exercise "Santa's list": Build a system for tracking who is on their nice list and who is on their naughty list.
Furthermore, I do not want duplicates ...
0
votes
1answer
7 views
Do the Solidity v0.8 overflow checks apply to assembly operations too?
Since Solidity v0.8, the compiler has checks for {over,under}flow by default for all arithmetic operations.
Do these checks apply to assembly (yul) arithmetic operations too?
0
votes
1answer
43 views
Unary operator - cannot be applied to type uint256
I was trying to compile the mulDiv function, part of the uniswap-v3-core code base, but I am getting the following error:
Unary operator - cannot be applied to type uint256
This is the line where it ...
2
votes
1answer
21 views
Can division underflow or overflow in Solidity?
We know that:
Since Solidity v0.8, the compiler has checks for {over,under}flow by default for all arithmetic operations.
Division is an arithmetic operation that rounds down to the integer part of ...
1
vote
2answers
34 views
How to assign to negative numbers in yul?
Take this code snippet:
function powOfTen(uint256 x) internal pure returns (int256 result) {
assembly {
switch x
case 1 { result := -18 }
}
}
Which doesn't compile:
...
1
vote
0answers
13 views
Is it safe to make a contract call from a giant loop?
I have this function in solidity:
function payPlayers(address[] memory players, uint256[] memory values) public payable returns (bool[] memory result) {
result = new bool[](players.length);
...
1
vote
1answer
11 views
What happens when the result of the shift operation does not fit in the type of the left operand?
For instance, take the following code:
pragma solidity ^0.8.0;
function foo() external pure returns (uint256, uint256, uint256) {
uint256 i1 = uint256(2) << 255;
uint256 i2 = uint256(4) ...
1
vote
1answer
17 views
Why doesn't the shift operation revert on overflow in Solidity ^0.8.0?
Take the following function:
solidity ^0.8.0;
function foo(uint256 x) external pure returns (uint256) {
uint256 y = x << 255;
return y;
}
If you set x = 2, the result is 2**256, which ...
0
votes
1answer
19 views
function not returning a uint256 while using Hardhat testing [duplicate]
Here's the function that's supposed to return a uint256
function initializeToken(string memory name, string memory symbol) public returns (uint256) {
// _creatorIds is a @openzeppelin counter
...
1
vote
1answer
161 views
msg.sender not address payable? (Solidity 0.8.2)
I've switched from Solidity 0.7.2 to 0.8.2
And the addresses declared as payable (owner) are reporting they are "NOT payable" in the contract.
pragma solidity ^0.8.2;
contract MyContract {
...
2
votes
0answers
21 views
How does addition look like at the opcode level in Solidity v0.8 and above?
In Solidity v0.7 and below, addition was a simple opcode:
ADD
Which cost 3 gas units and didn't handle overflows, silently returning the overflown value.
But Solidity v0.8 made addition overflow-safe....
1
vote
1answer
24 views
Explicit type conversion not allowed from “int_const -1” to “uint128”
I am compiling using sol 0.8.0 and the following line is producing the error in the title:
uint256 public constant MASK = uint128(~0);
Error:
Explicit type conversion not allowed from "int_const ...
0
votes
1answer
22 views
Can I create a signature in the contract?
I can use the function ecrecover to verify a signature in the contract, but I want to know how to create a
signature in the contract. What should I do?
2
votes
0answers
43 views
solidity math overflows
function nice(uint8 x) public returns(uint8 z){
uint8 z = 0;
z = z + 240;
require(z = z + x, "overflow");
}
I have been using this code with the solidity versions, ...
0
votes
0answers
65 views
Solidity 0.8 in Production
I am really happy to see that arithmetic operations will revert now on overflow and underflow, since the alternative of using SafeMath library was making code quite harder to read.
However, when is ...