Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mint multiple NEP11 tokens causes Peek out of bounds: 0/0 #1224

Open
GreenCakes-png opened this issue Nov 5, 2024 · 7 comments · May be fixed by #1230
Open

Mint multiple NEP11 tokens causes Peek out of bounds: 0/0 #1224

GreenCakes-png opened this issue Nov 5, 2024 · 7 comments · May be fixed by #1230
Assignees
Labels

Comments

@GreenCakes-png
Copy link

GreenCakes-png commented Nov 5, 2024

Copied this example "examples/Example.SmartContract.SampleRoyaltyNEP11Token"

I added a method to mint multiple tokens at once like this:

public static void MultiMint(UInt160 to)
{
Mint(to);
Mint(to);
Mint(to);
Mint(to);
}

However when I call this method, the NEO CLI throws "Peak out of bounds..." error

image

Could someone help identify the cause or suggest a solution?
Is it not possible to mint multiple tokens at once?

@Jim8y
Copy link
Contributor

Jim8y commented Nov 6, 2024

I'll take a look

@Jim8y Jim8y self-assigned this Nov 6, 2024
@Hecate2
Copy link
Contributor

Hecate2 commented Nov 6, 2024

Could you provide any contract source code, the compiler version, or the .nef, .manifest.json, .nefdbgnfo, dumpnef?
Also you may try neo-fairy-test.

@Jim8y
Copy link
Contributor

Jim8y commented Nov 6, 2024

@shargon can you please check this logic here, the problem is caused by this check:

if you call a storebacked property twice, you will be able to trigger this problem, cause the first call will initialize the property and make it none null, then the second call to the property will jump all the way to the bottom of the get method.

@Jim8y Jim8y added the bug label Nov 6, 2024
@Jim8y
Copy link
Contributor

Jim8y commented Nov 6, 2024

simply do this will reproduce the issue.

        public static void MultiMint(UInt160 to)
        {
            TotalSupply++;
            TotalSupply++;
        }

@Jim8y Jim8y assigned shargon and unassigned Jim8y Nov 6, 2024
@shargon
Copy link
Member

shargon commented Nov 6, 2024

@shargon can you please check this logic here, the problem is caused by this check:

if you call a storebacked property twice, you will be able to trigger this problem, cause the first call will initialize the property and make it none null, then the second call to the property will jump all the way to the bottom of the get method.

this is supposed to be the instance, and because is static, should be null :S

@Hecate2
Copy link
Contributor

Hecate2 commented Nov 7, 2024

CurrentScriptHash=0x01f31fb35734aa143f1274da79129acf97309561[SampleRoyaltyNEP11Token]
EntryScriptHash=0x1f4435477ad4edeb6affd95bff88714f3ec66809
   at Neo.VM.ExecutionEngine.ExecuteNext() in C:\Users\RhantolkYtriHistoria\NEO\neo-node-mainnet\src\Neo.VM\ExecutionEngine.cs:line 148
	InstructionPointer=63, OpCode , Script Length=63 0x1f4435477ad4edeb6affd95bff88714f3ec66809[]
File test-compiler.cs, line 43: to
	InstructionPointer=937, OpCode LDARG0, Script Length=1929 0x01f31fb35734aa143f1274da79129acf97309561[SampleRoyaltyNEP11Token]
File test-compiler.cs, line 122: }
	InstructionPointer=1030, OpCode RET, Script Length=1929 0x01f31fb35734aa143f1274da79129acf97309561[SampleRoyaltyNEP11Token]
File Nep11Token.cs, line 116: TotalSupply++
	InstructionPointer=908, OpCode DUP, Script Length=1929 0x01f31fb35734aa143f1274da79129acf97309561[SampleRoyaltyNEP11Token]
   at Neo.VM.ExecutionEngine.ExecuteNext() in C:\Users\RhantolkYtriHistoria\NEO\neo-node-mainnet\src\Neo.VM\ExecutionEngine.cs:line 148
Peek out of bounds: 0/0

SampleRoyaltyNEP11Token.nef.txt

@Hecate2
Copy link
Contributor

Hecate2 commented Nov 7, 2024

A bug in the compilation of Neo.SmartContract.Framework.TokenContract.TotalSupply.get

# Method Start Neo.SmartContract.Framework.TokenContract.TotalSupply.get
# Code TokenContract.cs line 28: "[Safe] get;"
0018 LDSFLD0
# Code TokenContract.cs line 28: "[Safe] get;"
0019 ISNULL
# Code TokenContract.cs line 28: "[Safe] get;"
0020 JMPIFNOT 17 # pos: 43 (offset: 23)
...
# Method End Neo.SmartContract.Framework.TokenContract.TotalSupply.get
# Code TokenContract.cs line 28: "[Safe] get;"
0043 RET

Value of static field 0 is not returned.
Related to ConvertStorageBackedProperty in compiler. But the code says:

                // AddInstruction(OpCode.DUP);
                AddInstruction(OpCode.ISNULL);
                // Ensure that no object was sent
                Jump(OpCode.JMPIFNOT_L, endTarget);

I am wondering if it is correct to write DUP ISNULL JMPIFNOT DROP

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

Successfully merging a pull request may close this issue.

4 participants