-
Notifications
You must be signed in to change notification settings - Fork 144
Compressed BigInteger format (NeoVM 3) #173
Conversation
Codecov Report
@@ Coverage Diff @@
## master #173 +/- ##
==========================================
+ Coverage 61.8% 62.53% +0.73%
==========================================
Files 16 16
Lines 1411 1412 +1
==========================================
+ Hits 872 883 +11
+ Misses 539 529 -10
Continue to review full report at Codecov.
|
I will try to revise, brother, but I still do not dominate this part as you, @erikzhang @shargon, @lightszero |
This is a very simple, yet powerful change brother. Nothing will really change, arithmetics will still give same results for all existing cases. Yet, this will allow us to have a clear definition of Neo Integers, stored in a very efficient format, and to implement automated garbage collection for NEP-5, etc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is true, I just took some minutes to check.
It is more readble and the push bytes0 different than push0 was a nice change for making it more clear.
Could it have a more clear title? ehwuahah |
@igormcoelho, maybe we could a tag like |
Thanks Vitor, I tried to make the title the simplest as possible hahaha well, as long as @lightszero is well aware of this, we're good on the compiler ;) |
I don't think we need |
The other point is that [EDIT:] I retracted from this position, as this opcode is not strictly necessary, and could over complicate some existing tools, already prepared and well-tested for neo2 opcodes. |
src/neo-vm/OpCode.cs
Outdated
PUSH0 = 0x00, | ||
PUSHF = PUSH0, | ||
PUSHBYTES0 = 0x00, | ||
PUSHF = PUSHBYTES0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can remove PUSHF
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, if it's never used... but I think we need to discuss that on another PR, because it could be used somewhere else (just like PUSHT on witness verifications, an although the same as PUSH1, it would requiring changing many tools just because of the name). I'm reverting all changes not directly connected to the fact that BigInteger 0 needs to be a byte array, proposed here.
@erikzhang I thought about it, and changing PUSH0 will impact many existing tools, so you're right. PUSH0 is not necessary together with a "PUSHBYTES0", both are the same (in practice), so I removed PUSHBYTES0 and put PUSH0 back to its position. |
@shargon @vncoelho @lightszero @erikzhang what do you think now? Change is quite direct now.. do we want VM Integer(0) to be |
if we use 0x, when a balance is 0 will be automatically deleted, so for me is good 0x |
agree |
/// An empty array of bytes is pushed onto the stack. | ||
/// An empty array of bytes is pushed onto the stack. | ||
/// This is equivalent to pushing Integer zero to the stack. | ||
/// This is equivalent to pushing Boolean false to the stack. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bool will be 0x or 0x00? Now is better 0x
This is a simpler reimplementation of #171
The idea is that BigInteger can already be represented as both 0x0000, 0x00 or 0x'' (empty bytearray). So let's adopt the most compressed version.
The gains are huge, because we can use it to automatically Delete entries on NEP-5, as soon as they become zero: neo-project/neo#825
Another gain is a clear different between opcode
0x00
, previously calledPUSH0
, but it usually pushed an empty array instead of number zero (Integer zero didn't have explicitly an empty bytearray as "standard" hex encoding).Now, opcode
0x00
will be calledPUSHBYTES0
, which is a nice name, that implies that an empty byte array is pushed to stack.Position
0x50
was "not used" (officially), but in fact it was implictly used as "PUSH0", pushing the actual Integer zero to the stack, so now it can have its name.