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

Validate serialization during Contract deploy and Update #2948

Merged
merged 18 commits into from
Nov 10, 2023
Merged

Conversation

shargon
Copy link
Member

@shargon shargon commented Nov 7, 2023

Close #2899
Close #2829

@shargon shargon requested a review from Jim8y November 7, 2023 12:39
Jim8y
Jim8y previously approved these changes Nov 7, 2023
@Jim8y
Copy link
Contributor

Jim8y commented Nov 7, 2023

Can you put 0 before others?

Jim8y
Jim8y previously approved these changes Nov 7, 2023
@shargon
Copy link
Member Author

shargon commented Nov 7, 2023

Cloud you check it @cschuchardt88 ? I'm not sure if this solve the problem, because it seems to be serialized as NULL

@cschuchardt88
Copy link
Member

cschuchardt88 commented Nov 7, 2023

{
    "code": -2147467262,
    "name": "InvalidCastException",
    "message": "Specified cast is not valid."
}
if (skip < 1 || take < 1 || take > RestServerSettings.Current.MaxPageSize)
    throw new InvalidParameterRangeException();
var contracts = NativeContract.ContractManagement.ListContracts(_neosystem.StoreView);
if (contracts.Any() == false)
    return NoContent();
var contractRequestList = contracts.OrderBy(o => o.Manifest.Name).Skip((skip - 1) * take).Take(take); // crashes with Manifest.Name
if (contractRequestList.Any() == false)
    return NoContent();
return Ok(contractRequestList);

But ill resync to make sure.

@shargon
Copy link
Member Author

shargon commented Nov 7, 2023

@cschuchardt88 is this your request? to which server?

{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "getstorage",
    "params": ["0x12fbec62fb765ce3f55845106ccf3717716723ad"]
}

@cschuchardt88
Copy link
Member

cschuchardt88 commented Nov 7, 2023

My localhost with your changes and http://seed1t5.neo.org:20332/

But im resyncing to see if still erroring... so be sometime.

@shargon shargon added the Bug Used to tag confirmed bugs label Nov 7, 2023
@cschuchardt88
Copy link
Member

cschuchardt88 commented Nov 7, 2023

I get

{
    "jsonrpc": "2.0",
    "id": 1,
    "error": {
        "code": -2146233086,
        "message": "Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')",
        "data": "   at Neo.Json.JArray.get_Item(Int32 index)\r\n   at Neo.Plugins.RpcServer.GetStorage(JArray _params)\r\n   at Neo.Plugins.RpcServer.ProcessRequestAsync(HttpContext context, JObject request)"
    }
}

But its not crashing now for var contractRequestList = contracts.OrderBy(o => o.Manifest.Name).Skip((skip - 1) * take).Take(take);

I would say fixed

@shargon
Copy link
Member Author

shargon commented Nov 7, 2023

@cschuchardt88 mmm looks like there are a manifest that it can't deserialize...

@shargon shargon mentioned this pull request Nov 8, 2023
Jim8y
Jim8y previously approved these changes Nov 8, 2023
@Jim8y
Copy link
Contributor

Jim8y commented Nov 8, 2023

@shargon

@shargon
Copy link
Member Author

shargon commented Nov 8, 2023

@shargon

We need to find why it fault, I tried to detect it with UT, but @cschuchardt88 still receiving an error.

"error": {
        "code": -2146233086,
        "message": "Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')",
        "data": "   at Neo.Json.JArray.get_Item(Int32 index)\r\n   at Neo.Plugins.RpcServer.GetStorage(JArray _params)\r\n   at Neo.Plugins.RpcServer.ProcessRequestAsync(HttpContext context, JObject request)"
    }

@cschuchardt88
Copy link
Member

cschuchardt88 commented Nov 8, 2023

sorry was an error on my part with the RPC method. Its working now.

@shargon
Copy link
Member Author

shargon commented Nov 8, 2023

{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "getstorage",
    "params": ["0x12fbec62fb765ce3f55845106ccf3717716723ad"]
}

@cschuchardt88 is this your request?

I receive {"jsonrpc":"2.0","id":1,"error":{"code":-2147467262,"message":"Specified cast is not valid."}}

@cschuchardt88
Copy link
Member

cschuchardt88 commented Nov 8, 2023

You have to call it like this: You have to provide the storage key. But storage key is invalid which is fine. Because its calling ListContracts before it returns error.

{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "getstorage",
    "params": ["0x12fbec62fb765ce3f55845106ccf3717716723ad", "MHgxMmZiZWM2MmZiNzY1Y2UzZjU1ODQ1MTA2Y2NmMzcxNzcxNjcyM2Fk"]
}

@Jim8y
Copy link
Contributor

Jim8y commented Nov 8, 2023

You have to call it like this: You have to provide the storage key. But storage key is invalid which is fine. Because its calling ListContracts before it returns error.

{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "getstorage",
    "params": ["0x12fbec62fb765ce3f55845106ccf3717716723ad", "MHgxMmZiZWM2MmZiNzY1Y2UzZjU1ODQ1MTA2Y2NmMzcxNzcxNjcyM2Fk"]
}

Then i guess we should update the execption messgae then.

@shargon
Copy link
Member Author

shargon commented Nov 8, 2023

getstorage

using https://sync.ngd.network/ testnet data I get:

{
"jsonrpc":"2.0","id":1,"error":{"code":-100,
"message":"Unknown storage",
"data":"   at Neo.Plugins.RpcServer.GetStorage(JArray _params) in C:\\Red4Sec\\Neo\\neo-modules\\src\\RpcServer\\RpcServer.Blockchain.cs:line 204\r\n   at Neo.Plugins.RpcServer.ProcessRequestAsync(HttpContext context, JObject request) in C:\\Red4Sec\\Neo\\neo-modules\\src\\RpcServer\\RpcServer.cs:line 245"}
}

@shargon
Copy link
Member Author

shargon commented Nov 8, 2023

You have to call it like this: You have to provide the storage key. But storage key is invalid which is fine. Because its calling ListContracts before it returns error.

{
    "id": 1,
    "jsonrpc": "2.0",
    "method": "getstorage",
    "params": ["0x12fbec62fb765ce3f55845106ccf3717716723ad", "MHgxMmZiZWM2MmZiNzY1Y2UzZjU1ODQ1MTA2Y2NmMzcxNzcxNjcyM2Fk"]
}

where it calls ListContracts for getStorage? I can't find it...

@shargon
Copy link
Member Author

shargon commented Nov 8, 2023

I can read all of them manually
image

@cschuchardt88
Copy link
Member

cschuchardt88 commented Nov 8, 2023

https://github.com/neo-project/neo-modules/blob/2d7fb2778ca7ad11815e438534916103859e36ac/src/RpcServer/RpcServer.Blockchain.cs#L188-L206

Looks like it calls GetContract.

But I use ListContracts, In RestServer, that's where i found the problem to begin with. It crashed on ContractState manifest.name. So it's working now.

@shargon
Copy link
Member Author

shargon commented Nov 8, 2023

@superboyiii could you check that tx:0x154f30d743c97d22fb17c5d363040ac4c9d351a1068b77b3ca6a71f91dfdcfc1 fail after this update, the contract is not stored, and no balances are affected?

Copy link
Member

@AnnaShaleva AnnaShaleva left a comment

Choose a reason for hiding this comment

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

The PR LGTM, and #2829 should be finally fixed with these changes. However, it may affect not only the 0x154f30d743c97d22fb17c5d363040ac4c9d351a1068b77b3ca6a71f91dfdcfc1, but also some other transactions in mainnet, because serialization checks were added everywhere including RuntimeNotify, and we need to check how it affects mainnet.

I'm a little bit worried about 3.6.2. This release supposed to be a quick stabilizing release without significant changes. I would suggest to postpone this PR until 3.7.0 and release 3.6.2 as it is now.

src/Neo/SmartContract/Native/ContractManagement.cs Outdated Show resolved Hide resolved
src/Neo/SmartContract/Native/ContractManagement.cs Outdated Show resolved Hide resolved
@roman-khimov
Copy link
Contributor

@AnnaShaleva, if we can test it in a few days (for example, before #2829 could celebrate its first year) and finally deal with #2829, it's worth doing that in 3.6.2.

@Jim8y
Copy link
Contributor

Jim8y commented Nov 9, 2023

@AnnaShaleva, if we can test it in a few days (for example, before #2829 could celebrate its first year) and finally deal with #2829, it's worth doing that in 3.6.2.

Took me a few seconds to understand the first year.

@@ -36,7 +36,7 @@ public ReadOnlyMemory<byte> Value
return !value.IsEmpty ? value : value = cache switch
{
BigInteger bi => bi.ToByteArrayStandard(),
IInteroperable interoperable => BinarySerializer.Serialize(interoperable.ToStackItem(null), 1024 * 1024),
IInteroperable interoperable => BinarySerializer.Serialize(interoperable.ToStackItem(null), ExecutionEngineLimits.Default),
Copy link
Member Author

Choose a reason for hiding this comment

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

This could affect to other txs

@superboyiii
Copy link
Member

@superboyiii could you check that tx:0x154f30d743c97d22fb17c5d363040ac4c9d351a1068b77b3ca6a71f91dfdcfc1 fail after this update, the contract is not stored, and no balances are affected?

Sure

@superboyiii
Copy link
Member

superboyiii commented Nov 10, 2023

@shargon Only 1 storage differed by this PR on Block 2506873
Seems the contract updated by txid 0x154f30d743c97d22fb17c5d363040ac4c9d351a1068b77b3ca6a71f91dfdcfc1 is failed by this PR.
image
contract: 0xccf264e2e0e3772945146a6f7af268377237186f
But yes, other storage before or after has not been influenced
1699604121085

@shargon
Copy link
Member Author

shargon commented Nov 10, 2023

@shargon Only 1 storage differed by this PR on Block 2506873 Seems the contract updated by txid 0x154f30d743c97d22fb17c5d363040ac4c9d351a1068b77b3ca6a71f91dfdcfc1 is failed by this PR. image contract: 0xccf264e2e0e3772945146a6f7af268377237186f But yes, other storage before or after has not been influenced 1699604121085

That is the expected one, isn't it?
For me we can merge and release 3.6.2 @neo-project/core ?

@shargon shargon added the Critical Issues (bugs) that need to be fixed ASAP label Nov 10, 2023
@shargon shargon merged commit 07a1810 into master Nov 10, 2023
2 checks passed
@shargon shargon deleted the fix-2899 branch November 10, 2023 10:29
AnnaShaleva added a commit to nspcc-dev/neo-go that referenced this pull request Nov 18, 2023
We already have tests for Permission deserialisation, so port the first
part of neo-project/neo#2948.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
AnnaShaleva added a commit to nspcc-dev/neo-go that referenced this pull request Nov 22, 2023
Follow the notion of neo-project/neo#2948.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
AnnaShaleva added a commit to nspcc-dev/neo-go that referenced this pull request Nov 22, 2023
Port the restrictive part of neo-project/neo#2948.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
AnnaShaleva added a commit to nspcc-dev/neo-go that referenced this pull request Nov 22, 2023
Follow the notion of neo-project/neo#2948.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
AnnaShaleva added a commit to nspcc-dev/neo-go that referenced this pull request Nov 22, 2023
Port the restrictive part of neo-project/neo#2948.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
Jim8y added a commit to Jim8y/neo that referenced this pull request Dec 31, 2023
* master: (30 commits)
  Set project as nullable (neo-project#3042)
  Fix: fix equal (neo-project#3028)
  Added README to packages (neo-project#3026)
  Nuget MyGet Fix (neo-project#3031)
  Add: print out the stack (neo-project#3033)
  fixed myget (neo-project#3029)
  Fixed MyGet Workflow (neo-project#3027)
  Package icons - hotfix (neo-project#3022)
  Nuget Package Icon & Symbols (neo-project#3020)
  Fix warning (neo-project#3021)
  Neo-node Migration (neo-project#2990)
  Remove unnecessary default seedlist (neo-project#2980)
  Fix Neo VM target frameworks (neo-project#2989)
  Update Neo.VM location in README.md (neo-project#2988)
  Migrating Neo VM (neo-project#2970)
  3.6.2 (neo-project#2962)
  fix ut (neo-project#2959)
  Validate serialization during Contract deploy and Update (neo-project#2948)
  code optimization (neo-project#2958)
  check null scriptcontainer (neo-project#2953)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Used to tag confirmed bugs Critical Issues (bugs) that need to be fixed ASAP
Projects
None yet
6 participants