Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Compressed BigInteger format (NeoVM 3) #173

Merged
merged 7 commits into from
Jun 15, 2019

Conversation

igormcoelho
Copy link
Contributor

@igormcoelho igormcoelho commented Jun 13, 2019

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 called PUSH0, 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 called PUSHBYTES0, 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.

@igormcoelho igormcoelho requested review from erikzhang, shargon, lightszero and vncoelho and removed request for shargon June 13, 2019 15:46
@codecov-io
Copy link

codecov-io commented Jun 13, 2019

Codecov Report

Merging #173 into master will increase coverage by 0.73%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
src/neo-vm/Types/Integer.cs 68.75% <100%> (+1%) ⬆️
src/neo-vm/ExecutionEngine.cs 57.28% <0%> (+1.38%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1282c92...db35233. Read the comment docs.

@vncoelho
Copy link
Member

I will try to revise, brother, but I still do not dominate this part as you, @erikzhang @shargon, @lightszero

@igormcoelho
Copy link
Contributor Author

igormcoelho commented Jun 13, 2019

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.
This is also necessary for another very nice change that I'm working on neo PR 820 ;)

vncoelho
vncoelho previously approved these changes Jun 13, 2019
Copy link
Member

@vncoelho vncoelho left a 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.

@vncoelho
Copy link
Member

Could it have a more clear title? ehwuahah
Or more descriptive?

@vncoelho
Copy link
Member

@igormcoelho, maybe we could a tag like port-to-devpack, right?

@igormcoelho
Copy link
Contributor Author

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 ;)

@erikzhang
Copy link
Member

I don't think we need 0x50.

@igormcoelho
Copy link
Contributor Author

igormcoelho commented Jun 14, 2019

0x50 is only necessary to force push StackItem Integer 0. There's no other direct way to push Integer 0 into the stack (but you calculate like PUSH1 DEC). I see that Integer 0 is equivalent to an empty byte array, but it's still different stack item types. In my opinion, PUSHBYTES0 could be kept for byte array computation (such as CATs), and PUSH0 for int computation.

The other point is that 0x50 can only be used for this... since it's after 4f and before 51 to 60, if you try to put any other opcode in this position, it will complicate many other direct calculations. So the option is either letting it unused or use like this.I prefer to formally activate it... but if you think it's a bad idea, we can leave it as it was (no 0x50).

[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.

PUSH0 = 0x00,
PUSHF = PUSH0,
PUSHBYTES0 = 0x00,
PUSHF = PUSHBYTES0,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove PUSHF

Copy link
Contributor Author

@igormcoelho igormcoelho Jun 14, 2019

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.

shargon
shargon previously approved these changes Jun 14, 2019
@igormcoelho igormcoelho dismissed stale reviews from shargon and vncoelho via cec3884 June 14, 2019 14:30
@igormcoelho
Copy link
Contributor Author

igormcoelho commented Jun 14, 2019

@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.

@igormcoelho
Copy link
Contributor Author

igormcoelho commented Jun 14, 2019

@shargon @vncoelho @lightszero @erikzhang what do you think now? Change is quite direct now.. do we want VM Integer(0) to be 0x00 in hex or 0x''?

@igormcoelho igormcoelho requested review from shargon and vncoelho June 14, 2019 14:35
@shargon
Copy link
Member

shargon commented Jun 14, 2019

if we use 0x, when a balance is 0 will be automatically deleted, so for me is good 0x

@lightszero
Copy link
Member

agree

shargon
shargon previously approved these changes Jun 15, 2019
/// 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.
Copy link
Member

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

@shargon shargon merged commit b4382aa into neo-project:master Jun 15, 2019
@igormcoelho igormcoelho deleted the feat_3x_std_integer2 branch June 15, 2019 13:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants