btc-vision / btc-runtime

Assemblyscript btc runtime
MIT License
5 stars 4 forks source link

SafeMath.mod is inefficient and will lead to crashes when run with large numbers #42

Closed liquitious closed 1 month ago

liquitious commented 1 month ago

https://github.com/btc-vision/btc-runtime/blob/6375653d6b38dd75974bf1937aa385115d7d24ae/runtime/types/SafeMath.ts#L39

Compare this to how it is done in EVM: https://github.com/polynetwork/eth-contracts/blob/097214982454bb2e225c2bfba81d28f4852c2203/contracts/libs/math/SafeMath.sol#L154

I expect this will result in high fees/costs and if evm contracts are ported as-is this would result in unexpected behavior. eg the system we port does Safemath.mod on the output of sha256

Reproduce by trying: SafeMath.mod(u256.from(Blockchain.timestamp)), u256.from(4));

BlobMaster41 commented 1 month ago

@impredmet

impredmet commented 1 month ago

i just submitted a PR that addresses this issue: #43