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

Clone structs on PICKITEM #63

Closed
dicarlo2 opened this issue Nov 13, 2018 · 1 comment
Closed

Clone structs on PICKITEM #63

dicarlo2 opened this issue Nov 13, 2018 · 1 comment

Comments

@dicarlo2
Copy link

We use structs heavily in NEO-ONE TypeScript smart contracts and we depend on the fact that structs are cloned from PICKITEM. So, we'd like to implement #49 again, however this time with a simple logic switch such that old contracts use the old buggy behavior and new contracts use the corrected behavior.

Ideally, we could just turn this feature on using the height the contract was created at, but we don't store this information anywhere. So we'll need an alternate way to determine if a given contract should use the new behavior or old. I suggest that we add a new contract property similar to payable, dynamic invoke, etc. which when present means that the contract uses the new behavior.

This is blocking for NEO-ONE TypeScript smart contracts.

@erikzhang
Copy link
Member

erikzhang commented Dec 6, 2019

PICKITEM should not clone the struct.

Let's say we have an array A[], and a struct B[]. We append B to A, so we got A[B].

Then we use the PICKITEM to push B onto the stack and try to modity it. But B is a struct, if we clone it, we will never be able to modify its value.

I describe this scenario in C#:

struct TestStruct
{
    public int Field1;
    public int Field2;
}

void Main()
{
    TestStruct[] array = { new TestStruct() };
    array[0].Field1 = 100; //It's impossible if `PICKITEM` clone the struct
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants