neo icon indicating copy to clipboard operation
neo copied to clipboard

BigInteger in Neo.Json

Open shargon opened this issue 2 years ago • 29 comments

Close https://github.com/neo-project/neo/issues/3036

shargon avatar Dec 27 '23 09:12 shargon

During this PR an error was found, a number greater than MAX_SAFE_INTEGER or less than MIN_SAFE_INTEGER could be parsed before.

Open question: We want this restriction only for serialize?

shargon avatar Dec 27 '23 09:12 shargon

This will change the behavior of existing contracts as well.

Jim8y avatar Dec 27 '23 10:12 Jim8y

I was expecting something other than the double type; for example all integer and floating point types. Why are we using double only anyways?

cschuchardt88 avatar Dec 27 '23 11:12 cschuchardt88

This will change the behavior of existing contracts as well.

Yes, we need a fork, but currently we allow integers out of the range

shargon avatar Dec 27 '23 12:12 shargon

Yes, we need a fork, but currently we allow integers out of the range

Its not about a fork, it is that you have changed the behavior of existing contract. Which means the logic in existing contract may become invalid or different, and cause unexpected execution result.

Jim8y avatar Dec 27 '23 12:12 Jim8y

This PR isnt going to work seeing how big integers can be 256-bits. double isn't that big.

cschuchardt88 avatar Dec 27 '23 13:12 cschuchardt88

Yes, we need a fork, but currently we allow integers out of the range

Its not about a fork, it is that you have changed the behavior of existing contract. Which means the logic in existing contract may become invalid or different, and cause unexpected execution result.

Any idea? currently we allow bigger values than expected

shargon avatar Dec 27 '23 14:12 shargon

Any idea? currently we allow bigger values than expected

We need to track the version or the deploy or latest update block of contracts, if it is before your fix, it should run as before, otherwise, it can adopt new logic. Otherwise, a bug should be a bug,,,, we should not fix it.

Jim8y avatar Dec 27 '23 15:12 Jim8y

we should not fix it

What do you mean not fix it? The bug?

cschuchardt88 avatar Dec 27 '23 16:12 cschuchardt88

we should not fix it

What do you mean not fix it? The bug?

We should not fix a bug that is already there in the chain, at least not in a way that can change the behavior of existing contract. Cause our update may cause unexpected behavior of those contracts. Take this one for example, it changed the behavior of the deserialize interface, if a contract uses it to deserialize a very large number, it works in the past, so he just write the contract that way and core logics rely on the deserialize operation, what will happen when this pr is patched? his contract may fail, may also have who knows behavior cause he might have wrapped it in a try block.

Jim8y avatar Dec 27 '23 16:12 Jim8y

But take this in to count image

Im sure no one has reached the max value yet, but see what can happen. so needs to be fixed.

cschuchardt88 avatar Dec 27 '23 17:12 cschuchardt88

Again, you dont fix it in a way that change the existing contract behavior. And you dont ensure someone has reached the maximum or not cause you dont know all contracts deployed. If you keep make changes like this, the neo project will be ruined one day cause you keep changing the existing contact behavior.

Jim8y avatar Dec 28 '23 01:12 Jim8y

You playing with people's potential money they have invested. This could be bad if a contract is doing StdLib.JsonSerialize and StdLib.JsonDeserialize for objects that deal with real funds or NFTs. Now developers use string as the json output, mostly. This will break oracle transactions, which are now bugged. I know this isn't a good solution, hints I said This PR isn't going to work.

This should of been developed correctly from the begin, the whole reason why we don't use floating points on the blockchain.

cschuchardt88 avatar Dec 28 '23 08:12 cschuchardt88

@Jim8y is right, a fork don't solve that the contract was not updated, maybe we need to store in the contract the last updated/deploy height, and use it as a fork height

shargon avatar Dec 28 '23 09:12 shargon

You playing with people's potential money they have invested. This could be bad if a contract is doing StdLib.JsonSerialize and StdLib.JsonDeserialize for objects that deal with real funds or NFTs. Now developers use string as the json output, mostly. This will break oracle transactions, which are now bugged. I know this isn't a good solution, hints I said This PR isn't going to work.

This should of been developed correctly from the begin, the whole reason why we don't use floating points on the blockchain.

We are not playing around, it is a very serious problem. The very fundamental bottom line is we do not change the behavior of existing contracts, we must defence it firmly. Determinastic is one of the key feature of the blockchain, you break it, you break everything. I am not saying we should ignore it, but we should not fix it in a way that can potentially destroy the whole project. Reputation is the key in blokchain world, not a single project will want to exist in a chain that can change its contract's behavior arbitarily.

Jim8y avatar Dec 28 '23 09:12 Jim8y

I understand now. I didn't know what you meant by not fix it. Now I do. Thx for clearing that up.

cschuchardt88 avatar Dec 28 '23 09:12 cschuchardt88

@Jim8y is right, a fork don't solve that the contract was not updated, maybe we need to store in the contract the last updated/deploy height, and use it as a fork height

Perhaps this is a possible solution @shargon. If a field is added to all deployed contracts and they keep calling the "legacy" version. A mechanism can be created for those that want to remove this "legacy" flag. Maybe "ContractManagement" could handle that.

vncoelho avatar Dec 28 '23 10:12 vncoelho

Let's not forget about oracle service as well. This would of affected any variable in the contract that they set a valid too.

cschuchardt88 avatar Dec 28 '23 10:12 cschuchardt88

@superboyiii, please check the state compatibility.

Jim8y avatar Feb 15 '24 09:02 Jim8y

@shargon format not a thing i can update, please check it.

Jim8y avatar Feb 15 '24 09:02 Jim8y

@shargon @Jim8y Something is incompatible. Blockchain stopped syncing at block 1528989 on mainnet. 1708423247018 1708423292017

superboyiii avatar Feb 20 '24 10:02 superboyiii

@shargon @Jim8y Something is incompatible. Blockchain stopped syncing at block 1528989 on mainnet. 1708423247018 1708423292017

Please consider close this pr. @shargon

Jim8y avatar Jun 01 '24 01:06 Jim8y

@shargon @Jim8y Something is incompatible. Blockchain stopped syncing at block 1528989 on mainnet. 1708423247018 1708423292017

Please consider close this pr. @shargon

But it can't be related to this pr

shargon avatar Jun 01 '24 07:06 shargon

@shargon do you can start working on this again? If I remember we needed to change the vm as well. Since we are working on the vm now.

cschuchardt88 avatar Nov 06 '24 23:11 cschuchardt88

@shargon conflicts, lets add hardfork if possible and make it merged into the hardfork pr. Such that no more conflict to maintain.

Jim8y avatar Nov 19 '24 16:11 Jim8y

@shargon @superboyiii can we add this in 3.9.0?

cschuchardt88 avatar Aug 03 '25 13:08 cschuchardt88

@shargon @superboyiii can we add this in 3.9.0?

First we need to

@shargon @superboyiii can we add this in 3.9.0?

If it's added I can move this PR to a new one, cleaner

shargon avatar Aug 04 '25 16:08 shargon

@shargon @superboyiii can we add this in 3.9.0?

First we need to

Is it confirmed we need this in v3.9.0? If so, I will add it.

superboyiii avatar Oct 10 '25 03:10 superboyiii

@shargon @superboyiii can we add this in 3.9.0?

First we need to

Is it confirmed we need this in v3.9.0? If so, I will add it.

In our meeting, it will be in 3.10.0 or whatever version after 3.9.0

cschuchardt88 avatar Oct 10 '25 16:10 cschuchardt88