Open altafan opened 2 years ago
casting from smaller to bigger, should add 00 bytes, meanwhile the opposite should truncate?
yes
All these types were inspired from caschscript but the Bytes type is just enough for this fork of Ivy.
Casting to bytesN would just mean dropping some trailing bytes from a given one but still a Bytes type can be returned.
Adding BytesN types would mean giving more context to the literal type by making sure the inner value does not exceed a fixed length. I think the effort for this does not stand the real usefulness of these types.
@tiero @bordalix what do you think? We might want to close this for now?
there are occasions when you are doing a binaryExpression between an element pushed by an opcode and something on the stack (ie. provider by the developer)
Like OP_INSPECTVERSION
pushes a a bytes4
, passing 8 bytes in the stack and compare them (OP_EQUAL) will make to return false.
ie.
bytes(2) === tx.version
It should implicitly transform/truncate to 4 bytes, knowing the right operator result type.
So it's fine to only expose bytes
to the develper, but internally we must known the lenght of the bytes to perform proper comparisons operations.
I would postpone this, for several reasons:
If the purpose of Ionio is to help people better understand Script, adding these types will increase the complexity for the end user. The beauty of it is that it has the bare minimum for people to experiment with Script. I would keep it as simple as possible.
It not reflects the underlaying tech, since, from what I know from Script, the stack stores byte vectors of up to 520 bytes, but opcodes which take integers and bools off the stack require that they be no more than 4 bytes long. So it seems at the stack layer we only have bytes, integers and bools.
While reading about Script to answer this, I found this, which means we would have to check if a bytes4 + bytes4 is still a bytes4 or a bytes8. Again, is adding complexity without obvious gains:
Just my 2 satoshis.
We need to add the built-in type for bytes to Ionio: