Closed liquitious closed 7 hours ago
Thanks for reporting. ill investigate
crashes: u256.fromBytes(sha256(latestRandomSeed.toUint8Array())). both LE and BE fail with error: [OPNetUnit HELP PANIC]: Error: out of memory
This means that your contract is using more memory that what you have specified. Are you using the asconfig file included in the project? This file set the memory at a maximum of 512 memory pages which equals to 32.768mb. This is the maximum a contract can consume.
If your memory is that high, your gas will be very high.
I drew incorrect conclusion that error was due to the u256.fromBytes. It is actually the following Safemath.mod
we do. It seems this method if implemented inefficiently so if we pass a large number in we get a crash. Looks like solidity has optimized the %
operation: https://github.com/polynetwork/eth-contracts/blob/master/contracts/libs/math/SafeMath.sol#L154
Opened new issue here: #42
let latestRandomSeed: u256 = u256.fromU32(sha256(latestRandomSeed.toUint8Array())[0]);
u256.fromBytes(latestRandomSeed.toUint8Array())
(wherelatestRandomSeed
isu256
)u256.fromBytes(sha256(latestRandomSeed.toUint8Array()))
. both LE and BE fail with error:[OPNetUnit HELP PANIC]: Error: out of memory
Note that
sha256(latestRandomSeed.toUint8Array())
works and logging it I get something like:109,8,85,163,53,128,47,11,194,9,70,243,196,140,5,182,185,140,20,181,120,2,13,95,66,161,102,185,127,230,245,159
Easiest way to reproduce that shows issue is not related to
sha256
:even on an array of len 2 bytes or 4 bytes we get this same crash