Hi, does anybody know any good resources on how to design advanced smart contracts? Such as a book with UML diagrams and so forth

Jun 7, 2021, 10:01 AM
As shared by a generous gentleman in this group for exactly the same question, the book "Blockchain in Action" has materials on using UML diagrams.
Jun 7, 2021, 11:08 AM
Thanks
Jun 7, 2021, 11:14 AM
struct Info {
uint16 _a1;
uint16 _b1;
uint16 _c1;
string _name;
address _owner;
address _addr;
}
Hi there, suppose I have a struct with variables given here, I'm wondering if it is better to change uint16 to uint256 when I'm pretty sure `_a1` etc are within the range of an uint16. Is using an uint16 causing more troubles or saving more gas? This is a question since EVM is a 256-bit machine.
Jun 7, 2021, 11:48 AM
https://ethereum.stackexchange.com/questions/3067/why-does-uint8-cost-more-gas-than-uint256
Jun 7, 2021, 11:57 AM
Yes, unfortunately the answer is it's causing more troubles and using more gas. Thanks. @levi_dev
It can be using less gas if they are always put in a struct due to tight variable packing, though
contract A {
uint a = 123456;
uint16 b = 2;

function getVal() public view returns(uint256) {
return a * b;
}
}
@levi_dev What is even more amazing is two uint256 multiply takes less gas than an uint16 and an uint256 multiply.
Jun 7, 2021, 12:12 PM
Variable type changing. Since evm works on 256 bit, that uint16 will first be converted to 256 and then only operations are performed
That conversion is causing the extra gas
Jun 7, 2021, 12:34 PM
@mrrobot3_3 Yes, extra work is needed downsizing an uint256 to uint16. This is another mysterious part of Solidity. Quite counter-intuitive.
Jun 7, 2021, 12:39 PM
This is supposed to reduce fee because of tight packing. But it doesn't?
Jun 7, 2021, 12:41 PM
this has abstracted away many details. just for illustration
at the end, there are pros and cons.
Considering sunk costs, I'll stick to what I already did.
Jun 7, 2021, 12:43 PM

© 2024 Draquery.com All rights reserved.