While we're on topic. Keccak random does only produce numbers right? Never tried with anything else but is there any way to convert to say a randomly generated address or bool value?

Aug 2, 2022, 7:41 PM
bool should be easy right?
Aug 2, 2022, 9:03 PM
I mean literal bool, I usually just limit returns to either 1 or 0 to simulate bool
Aug 2, 2022, 9:05 PM
keccack => uint256 => uint160 => address
Aug 2, 2022, 9:44 PM
How would I implement this? Just add uint160 and address to the argument "keccak(uint256(uint160(address(..))"?
Aug 2, 2022, 9:49 PM
Inside out
Its in the uni v2 pair address prediction
Aug 2, 2022, 10:20 PM
uint256=>uint160 may revert though
keccak random?
Aug 2, 2022, 10:23 PM
It won't, compiler will truncate accordingly
Aug 2, 2022, 10:44 PM
This depends on he version of solidity you are using and on the number
Aug 2, 2022, 10:45 PM
Yeah its for the latest
Older versions supported direct uint to address
Aug 2, 2022, 10:45 PM
If you do uint160(type(uint256).max) pretty sure it reverts on last version of solidity
Aug 2, 2022, 10:45 PM
This is what I use in updated uni v2 code
// calculates the CREATE2 address for a pair without making any external calls
function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
(address token0, address token1) = sortTokens(tokenA, tokenB);
pair = address(uint(keccak256(abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encodePacked(token0, token1)),
hex'96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f' // init code hash
))));
}


This ones from the original code, used to work on solc 0.6
Aug 2, 2022, 10:49 PM
Mhh yeah just tried on remix, I remembered wrong
Aug 2, 2022, 10:49 PM
Breaking changes are a bitch
Aug 2, 2022, 10:50 PM
btw that's not a way to test if that would break
pragma solidity >=0.8.0 <0.9.0;

contract Test {

function test() public pure returns(uint160) {
return uint160(type(uint256).max);
}

function test2() public pure returns(uint160 result) {

unchecked{ result=uint160(type(uint256).max);}
}

}
this answers the question without doubts
Aug 2, 2022, 10:51 PM
or this. wtf!
Aug 2, 2022, 11:26 PM
bbb
Text
bbb
Instead of b put the magical char I put above
Aug 2, 2022, 11:36 PM

© 2024 Draquery.com All rights reserved.