-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Contract redirectiton #1391
Contract redirectiton #1391
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work guy! Congratulations.
@@ -4,5 +4,6 @@ internal class StorageContext | |||
{ | |||
public UInt160 ScriptHash; | |||
public bool IsReadOnly; | |||
public UInt160 PreDataKey; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any other idea for the name of this variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is preFix
well? @vncoelho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about renaming the ScriptHash
to ContractHash
, PreDataKey
to NameSpace
, Preifx
, or StorageKeyPrefix
?
I rethought it a bit. I don't think we should use script hash as a storage key anymore. Maybe we should use GUID from the beginning. This eliminates the need for redirection. |
@erikzhang Hi,大佬. Can you describe the logic for generating the GUID?If you use a random number, it means that when you send the contract TX, you have to add this field to the transaction or contract properties, and you have to do the check. |
The GUID is a local value. It is used in local database, and is not on chain. We can create a GUID when deploying a contract. Each contract has a unique (but not global) GUID, and then the contract's storage is prefixed with that GUID. |
Does it mean that each node generates its own Guid when creating a contract? If so how to ensure that the Guid generated by each node is the same? Otherwise, the state of each Storage will be different, and the state root will be different too. |
I agree with @eryeer , we need to maintain the consistency of each node. If we cannot guarantee that the GUID of each node is consistent, then the influence of GUID needs to be removed in the calculation of stateroot or some other places. @erikzhang |
There are many ways to create deterministic GUIDs. |
But if we use a deterministic GUID, it is not much different from |
Here is an example: #1400 |
The main difference is that with the GUID you don't need to add redirection records, and the contract can be upgraded any times without recording additional information to prevent old contracts from being redeployed. Because if an old contract is deployed, a new GUID is created. |
Maybe it is not safe here.We can attack the storage area of a contract by means of hash collision. |
OK.Got it. |
Contract redirectiton.Draft