GithubHelp home page GithubHelp logo

Comments (4)

shargon avatar shargon commented on June 12, 2024 1

Can we use UNPACK ?

from neo-vm.

igormcoelho avatar igormcoelho commented on June 12, 2024

Very goooooood Shargon! Now it's better... we just use CONVERT and then use UNPACK.
But that will work? Because unpack puts a lot of elements in stack... we would need to somehow unpack [0x01,0x02,0x03] into 0x010203. But you gave me an idea, perhaps we could reuse PACK, if a bytearray is on stack then it just converts it to array, byte to byte:
https://github.com/neo-project/neo-vm/blob/master/src/neo-vm/ExecutionEngine.cs#L699

The thing is, we would need to check the type, to make sure it's a biginteger and not a byte array, and since many codes do PUSH1 - PACK, is this "1" a bytearray with a single element, or number 1?

from neo-vm.

igormcoelho avatar igormcoelho commented on June 12, 2024

Can we use UNPACK ?

Now I got your point Shargon!! I think UNPACK is good to work as a conversor from ByteArray to Array:

StackItem item = context.EvaluationStack.Pop();
if (item is VMArray array)
{
for (int i = array.Count - 1; i >= 0; i--)
context.EvaluationStack.Push(array[i]);
context.EvaluationStack.Push(array.Count);
}

So, it could be:

PUSH10 ababababab...
UNPACK # (new UNPACK function) converts byte[] to Array (of byte) on stack [ab,ab,ab...]
DUP # duplicates Array on stack
REVERSE  # reverse and drop array
???  # convert Array back to byte[] on stack

Now we need to "really unpack" and apply several concats here, to merge them in a single byte array.

======

GOT IT!! Now we use PACK again hahaah but PACK receives an integer usually, if it receives an Array, then it know it has to merge to a single byte[] ;)

PUSH10 ababababab...
UNPACK # (new UNPACK functionality) converts byte[] to Array (of byte) on stack [ab,ab,ab...]
DUP # duplicates Array on stack
REVERSE  # reverse and drop array
PACK  # (new PACK functionality) convert Array back to byte[] on stack

No need for CONVERT xD

from neo-vm.

igormcoelho avatar igormcoelho commented on June 12, 2024

Now I think this breaks semantics, and we have much better options for Neo3.

from neo-vm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.