You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem is in ProtoBufRuntime.sol while getting size of number to be encoded in probuf.
Because realSize(sz) is zero, it runs (base << (0*BYTE_SIZE - BYTE_SIZE)) which is actually (base << -BYTE_SIZE).
This code cannot be run in solidity because it doesn't support minus shift.
/**
* @dev Get the actual size needed to encoding an unsigned integer
* @param x The unsigned integer to be encoded
* @param sz The maximum number of bytes used to encode Solidity types
* @return The number of bytes needed for encoding `x`
*/
function _get_real_size(uint256 x, uint256 sz)
internal
pure
returns (uint256)
{
uint256 base = 0xff;
uint256 realSize = sz;
while (
x & (base << (realSize * BYTE_SIZE - BYTE_SIZE)) == 0 && realSize > 0 // This line has the problem
) {
realSize -= 1;
}
if (realSize == 0) {
realSize = 1;
}
return realSize;
}
The text was updated successfully, but these errors were encountered:
innim98
pushed a commit
to innim98/solidity-protobuf
that referenced
this issue
Dec 20, 2023
"_get_real_size" function fails when sz == 0
The problem is in ProtoBufRuntime.sol while getting size of number to be encoded in probuf.
Because realSize(sz) is zero, it runs (base << (0*BYTE_SIZE - BYTE_SIZE)) which is actually (base << -BYTE_SIZE).
This code cannot be run in solidity because it doesn't support minus shift.
The text was updated successfully, but these errors were encountered: