Neo: [Feature Request] Hashing Interop names

Created on 2 Jun 2018  路  16Comments  路  Source: neo-project/neo

Perhaps this is a very bad idea, but I will say it anyway :)
Currently, Interop methods are called by string names "Neo.Input.GetHash" (this is the shorter one), but we have much longer names in the list (including older ones starting with "Antshares." prefix). Since this makes the avm bigger, and there will be a limited number of interop functions, is it reasonable to hash the Interop function name (after the "Neo." and "Antshares." part, so both could get the same hash), and use this hash for invocation in regular Syscall? We could create a much smaller hash (8, 10, 12 bytes?), and collision won't be effectively a problem, because future names can be chosen to avoid collision (if there is any...) and that could be an incentive for using Interop methods in avm (creating less newer opcodes) while not expending too much bytes in avm.

discussion

All 16 comments

Any thoughts on that @shargon , @erikzhang , @localhuman , @canesin ?

You don't need a hash. Only a int32 number. Maybe if we have on the stack a BigInteger we can use it

254

In fact @shargon, the idea of Hash is to simply have a function mapping from String InteropName -> byte[]. We can have a hash function mapping from String to int32, although more than 4 bytes may be wanted, to avoid future collisions perhaps, and still it would be nice to have a fixed limited amount, to make it easier to identify it for appcalls (and provide a big compression for avm).

Ok, lets reactivate this :) I think 6 bytes are enough, and I suggest we split the hash in two parts: prefix and operation. Example, prefix could be the 3byte hashing of "Neo.Storage", and operation would be the 3byte hash of "Put". The reason is that we could posdibly have unified prices for different prefix, and just by looking at first three bytes we could possibly take a decision. It could also be 8 bytes total: 4+4, if you think more options are needed, but if 6 (or less) is reasonable, that would be nice to save most bytes here. Or, without any prefix, we can just read a bigint on stack as you proposed Shargon, if lenght is less than X bytes (otherwise its string).

If we use 4 bytes hash, each SYSCALL would be 6 bytes length. 1 byte opcode + 1 byte length + 4 bytes hash.

More than a hash, is better a Dictionary of ushort like this

0x01,0x01 -> Storage.X
0x01,0x02 -> Storage.Y
0x01,0x03 -> Storage.Z

0x02,0x01 -> Runtime.X
0x02,0x02 -> Runtime.Y
0x02,0x03 -> Runtime.Z

Then with 3 bytes we can call a SYSCALL

Ok, if we limit to 255 functions of a specific prefix, that's fine for me one byte. I agree with you both, a dictionary structure is fine, and quite short... perhaps we need another byte for "Neo", or "Antshares", or "Ontology", or any other blockchain that could be attached to the ecosystem.
So, perhaps:
0x01(System), 0x01,0x01 -> System.Storage.X
0x02(Neo), 0x01,0x02 -> Neo.Storage.Y
0x03(Antshares), 0x01,0x03 -> Antshares.Storage.Z

We could do something very short, like SYSCALL 03 010203.

I still suggest that numbers are given in the table by the first byte of a SHA256, it's simple an easy to use:
```
System.Runtime.Platform => 67 10 c7
System.Runtime.GetTrigger => 67 10 e9
System.Runtime.CheckWitness => 67 10 74
System.Runtime.Notify => 67 10 f4
System.Runtime.Log => 67 10 21
System.Runtime.GetTime => 67 10 88
System.Runtime.Serialize => 67 10 be
System.Runtime.Deserialize => 67 10 18
Array(8) [ "18", "21", "74", "88", "be", "c7", "e9", "f4" ]

System.Blockchain.GetHeight => 67 62 4f
System.Blockchain.GetHeader => 67 62 d9
System.Blockchain.GetBlock => 67 62 c3
System.Blockchain.GetTransaction => 67 62 c0
System.Blockchain.GetTransactionHeight => 67 62 f8
System.Blockchain.GetContract => 67 62 2c
Array(6) [ "2c", "4f", "c0", "c3", "d9", "f8" ]

System.Header.GetIndex => 67 ba cb
System.Header.GetHash => 67 ba 0b
System.Header.GetPrevHash => 67 ba a7
System.Header.GetTimestamp => 67 ba 72
Array(4) [ "0b", "72", "a7", "cb" ]

System.Block.GetTransactionCount => 67 21 f5
System.Block.GetTransactions => 67 21 db
System.Block.GetTransaction => 67 21 c0
Array(3) [ "c0", "db", "f5" ]

System.Transaction.GetHash => 67 ee 0b
Array [ "0b" ]

System.Contract.Destroy => 67 a6 ea
System.Contract.GetStorageContext => 67 a6 b3
Array [ "b3", "ea" ]

System.Storage.GetContext => 67 a6 1e
System.Storage.GetReadOnlyContext => 67 a6 5d
System.Storage.Get => 67 a6 5f
System.Storage.Put => 67 a6 65
System.Storage.Delete => 67 a6 e2
Array(5) [ "1e", "5d", "5f", "65", "e2" ]

System.StorageContext.AsReadOnly => 67 f8 f7
Array [ "f7" ]

Neo.Runtime.GetTrigger => ef 10 e9
Neo.Runtime.CheckWitness => ef 10 74
Neo.Runtime.Notify => ef 10 f4
Neo.Runtime.Log => ef 10 21
Neo.Runtime.GetTime => ef 10 88
Neo.Runtime.Serialize => ef 10 be
Neo.Runtime.Deserialize => ef 10 18
Array(7) [ "18", "21", "74", "88", "be", "e9", "f4" ]

Neo.Blockchain.GetHeight => ef 62 4f
Neo.Blockchain.GetHeader => ef 62 d9
Neo.Blockchain.GetBlock => ef 62 c3
Neo.Blockchain.GetTransaction => ef 62 c0
Neo.Blockchain.GetTransactionHeight => ef 62 f8
Neo.Blockchain.GetAccount => ef 62 47
Neo.Blockchain.GetValidators => ef 62 66
Neo.Blockchain.GetAsset => ef 62 b3
Neo.Blockchain.GetContract => ef 62 2c
Array(9) [ "2c", "47", "4f", "66", "b3", "c0", "c3", "d9", "f8" ]

Neo.Header.GetHash => ef ba 0b
Neo.Header.GetVersion => ef ba 4b
Neo.Header.GetPrevHash => ef ba a7
Neo.Header.GetMerkleRoot => ef ba 91
Neo.Header.GetTimestamp => ef ba 72
Neo.Header.GetIndex => ef ba cb
Neo.Header.GetConsensusData => ef ba f9
Neo.Header.GetNextConsensus => ef ba 5e
Array(8) [ "0b", "4b", "5e", "72", "91", "a7", "cb", "f9" ]

Neo.Block.GetTransactionCount => ef 21 f5
Neo.Block.GetTransactions => ef 21 db
Neo.Block.GetTransaction => ef 21 c0
Array(3) [ "c0", "db", "f5" ]

Neo.Transaction.GetHash => ef ee 0b
Neo.Transaction.GetType => ef ee 51
Neo.Transaction.GetAttributes => ef ee a0
Neo.Transaction.GetInputs => ef ee 7d
Neo.Transaction.GetOutputs => ef ee 4a
Neo.Transaction.GetReferences => ef ee 69
Neo.Transaction.GetUnspentCoins => ef ee ec
Neo.Transaction.GetWitnesses => ef ee b3
Array(8) [ "0b", "4a", "51", "69", "7d", "a0", "b3", "ec" ]

Neo.InvocationTransaction.GetScript => ef 06 f8
Array [ "f8" ]

Neo.Witness.GetInvocationScript => ef 54 d6
Neo.Witness.GetVerificationScript => ef 54 39
Array [ "39", "d6" ]

Neo.Attribute.GetUsage => ef 1d 0f
Neo.Attribute.GetData => ef 1d 27
Array [ "0f", "27" ]

Neo.Input.GetHash => ef 36 0b
Neo.Input.GetIndex => ef 36 cb
Array [ "0b", "cb" ]

Neo.Output.GetAssetId => ef b2 72
Neo.Output.GetValue => ef b2 ab
Neo.Output.GetScriptHash => ef b2 60
Array(3) [ "60", "72", "ab" ]

Neo.Account.GetScriptHash => ef 7e 60
Neo.Account.GetVotes => ef 7e ad
Neo.Account.GetBalance => ef 7e d1
Neo.Account.IsStandard => ef 7e 96
Array(4) [ "60", "96", "ad", "d1" ]

Neo.Asset.Create => ef 80 47
Neo.Asset.Renew => ef 80 90
Neo.Asset.GetAssetId => ef 80 72
Neo.Asset.GetAssetType => ef 80 ed
Neo.Asset.GetAmount => ef 80 13
Neo.Asset.GetAvailable => ef 80 66
Neo.Asset.GetPrecision => ef 80 32
Neo.Asset.GetOwner => ef 80 81
Neo.Asset.GetAdmin => ef 80 33
Neo.Asset.GetIssuer => ef 80 e5
Array(10) [ "13", "32", "33", "47", "66", "72", "81", "90", "e5", "ed" ]

Neo.Contract.Create => ef a6 47
Neo.Contract.Migrate => ef a6 f9
Neo.Contract.Destroy => ef a6 ea
Neo.Contract.GetScript => ef a6 f8
Neo.Contract.IsPayable => ef a6 29
Neo.Contract.GetStorageContext => ef a6 b3
Array(6) [ "29", "47", "b3", "ea", "f8", "f9" ]

Neo.Storage.GetContext => ef a6 1e
Neo.Storage.GetReadOnlyContext => ef a6 5d
Neo.Storage.Get => ef a6 5f
Neo.Storage.Put => ef a6 65
Neo.Storage.Delete => ef a6 e2
Neo.Storage.Find => ef a6 82
Array(6) [ "1e", "5d", "5f", "65", "82", "e2" ]

Neo.StorageContext.AsReadOnly => ef f8 f7
Array [ "f7" ]

Neo.Enumerator.Create => ef b0 47
Neo.Enumerator.Next => ef b0 1f
Neo.Enumerator.Value => ef b0 8e
Neo.Enumerator.Concat => ef b0 4d
Array(4) [ "1f", "47", "4d", "8e" ]

Neo.Iterator.Create => ef b0 47
Neo.Iterator.Key => ef b0 99
Neo.Iterator.Keys => ef b0 f0
Neo.Iterator.Values => ef b0 53
Neo.Iterator.Next => ef b0 1f
Neo.Iterator.Value => ef b0 8e
Array(6) [ "1f", "47", "53", "8e", "99", "f0" ]

AntShares.Runtime.CheckWitness => 96 10 74
```
In the future, we just need to avoid colisions in names, and change them slightly if one ever appears.

Just an example: SYSCALL System.Storage.Put would become SYSCALL 03 67 a6 65. 5 bytes total.
Good thing of the SHA256 is that any neo-compiler will know how to convert any Interop automatically, even when new ones are created in the future (numbering will become automatic).
Do you agree @erikzhang @shargon ?

I agree that using hash is a better option, but if the length of the hash is too short, a collision may occur. A length of 4 bytes may be more appropriate.

Auto SHA256 is easy to collide, i agree with 4 bytes is better. And is easy to convert it to int32 for Dictionaries

Ok, remade the structure for 4 bytes. There are two proposals here: (i) Hashing the full name as 4 bytes (ii) hashing the prefix as 2 bytes + final part as 2 bytes
A believe the second one is more flexible, because we could accelerate future instruction recognition on switch-case by first looking at prefix, then the rest of the instruction. It's also slightly easier for us to visually determine the nature of the instruction, even if it's a 4 bytes hash. One last benefit, even Neo.XXX and Antshares.XXX will have the same hash ending, although different prefixes.

No colisions were created in any case... SHA256 is good :)

System.Runtime.Platform => (b279fcf6) uint:4143741362 System.Runtime(ef9e) Platform(c78f) 
System.Runtime.GetTrigger => (e97d38a0) uint:2688056809 System.Runtime(ef9e) GetTrigger(e98d) 
System.Runtime.CheckWitness => (f827ec8c) uint:2364286968 System.Runtime(ef9e) CheckWitness(740a) 
System.Runtime.Notify => (95016f61) uint:1634664853 System.Runtime(ef9e) Notify(f4e2) 
System.Runtime.Log => (cfe74796) uint:2521294799 System.Runtime(ef9e) Log(21e4) 
System.Runtime.GetTime => (b7c38803) uint:59294647 System.Runtime(ef9e) GetTime(8817) 
System.Runtime.Serialize => (ee83bbc8) uint:3367732206 System.Runtime(ef9e) Serialize(be34) 
System.Runtime.Deserialize => (dfedd7bf) uint:3218599391 System.Runtime(ef9e) Deserialize(1827) 
Array(8) [ "1827", "21e4", "740a", "8817", "be34", "c78f", "e98d", "f4e2" ]

System.Blockchain.GetHeight => (7ef5721f) uint:527627646 System.Blockchain(d284) GetHeight(4f40) 
System.Blockchain.GetHeader => (74445bf6) uint:4133176436 System.Blockchain(d284) GetHeader(d96a) 
System.Blockchain.GetBlock => (8347922d) uint:764561283 System.Blockchain(d284) GetBlock(c37e) 
System.Blockchain.GetTransaction => (e6558d48) uint:1217222118 System.Blockchain(d284) GetTransaction(c02b) 
System.Blockchain.GetTransactionHeight => (4a3288b1) uint:2978493002 System.Blockchain(d284) GetTransactionHeight(f8eb) 
System.Blockchain.GetContract => (a9c54b41) uint:1095484841 System.Blockchain(d284) GetContract(2c36) 
Array(6) [ "2c36", "4f40", "c02b", "c37e", "d96a", "f8eb" ]

System.Header.GetIndex => (de2e7958) uint:1484336862 System.Header(db41) GetIndex(cb27) 
System.Header.GetHash => (b80639a1) uint:2704869048 System.Header(db41) GetHash(0b51) 
System.Header.GetPrevHash => (fabe7210) uint:275955450 System.Header(db41) GetPrevHash(a77c) 
System.Header.GetTimestamp => (15abc264) uint:1690479381 System.Header(db41) GetTimestamp(72ee) 
Array(4) [ "0b51", "72ee", "a77c", "cb27" ]

System.Block.GetTransactionCount => (14d36a25) uint:627757844 System.Block(8e80) GetTransactionCount(f55f) 
System.Block.GetTransactions => (c0d9af6f) uint:1873795520 System.Block(8e80) GetTransactions(dbc4) 
System.Block.GetTransaction => (362b8107) uint:125905718 System.Block(8e80) GetTransaction(c02b) 
Array(3) [ "c02b", "dbc4", "f55f" ]

System.Transaction.GetHash => (ba9e3027) uint:657497786 System.Transaction(9a5e) GetHash(0b51) 
Array [ "0b51" ]

System.Contract.Destroy => (c69f1df0) uint:4028473286 System.Contract(6ed1) Destroy(ea9b) 
System.Contract.GetStorageContext => (6531220c) uint:203567461 System.Contract(6ed1) GetStorageContext(b381) 
Array [ "b381", "ea9b" ]

System.Storage.GetContext => (9bf667ce) uint:3462919835 System.Storage(cc6d) GetContext(1e84) 
System.Storage.GetReadOnlyContext => (f6b46be2) uint:3798709494 System.Storage(cc6d) GetReadOnlyContext(5d2f) 
System.Storage.Get => (925de831) uint:837311890 System.Storage(cc6d) Get(5fb9) 
System.Storage.Put => (e63f1884) uint:2216181734 System.Storage(cc6d) Put(6568) 
System.Storage.PutEx => (73e19b3a) uint:983294323 System.Storage(cc6d) PutEx(150b) 
System.Storage.Delete => (2f58c5ed) uint:3989133359 System.Storage(cc6d) Delete(e2d0) 
Array(6) [ "150b", "1e84", "5d2f", "5fb9", "6568", "e2d0" ]

System.StorageContext.AsReadOnly => (1abdce13) uint:332315930 System.StorageContext(18b1) AsReadOnly(f7d5) 
Array [ "f7d5" ]

Neo.Runtime.GetTrigger => (75c893e3) uint:3818113141 Neo.Runtime(0817) GetTrigger(e98d) 
Neo.Runtime.CheckWitness => (efdfe694) uint:2498158575 Neo.Runtime(0817) CheckWitness(740a) 
Neo.Runtime.Notify => (05079216) uint:378668805 Neo.Runtime(0817) Notify(f4e2) 
Neo.Runtime.Log => (36d35206) uint:106091318 Neo.Runtime(0817) Log(21e4) 
Neo.Runtime.GetTime => (420111be) uint:3188785474 Neo.Runtime(0817) GetTime(8817) 
Neo.Runtime.Serialize => (c3b04461) uint:1631891651 Neo.Runtime(0817) Serialize(be34) 
Neo.Runtime.Deserialize => (59e9c3ee) uint:4005816665 Neo.Runtime(0817) Deserialize(1827) 
Array(7) [ "1827", "21e4", "740a", "8817", "be34", "e98d", "f4e2" ]

Neo.Blockchain.GetHeight => (a230d210) uint:282210466 Neo.Blockchain(0077) GetHeight(4f40) 
Neo.Blockchain.GetHeader => (a1696268) uint:1751280033 Neo.Blockchain(0077) GetHeader(d96a) 
Neo.Blockchain.GetBlock => (5f8f0674) uint:1946586975 Neo.Blockchain(0077) GetBlock(c37e) 
Neo.Blockchain.GetTransaction => (cdcf172c) uint:739758029 Neo.Blockchain(0077) GetTransaction(c02b) 
Neo.Blockchain.GetTransactionHeight => (45221c0f) uint:253502021 Neo.Blockchain(0077) GetTransactionHeight(f8eb) 
Neo.Blockchain.GetAccount => (18d3077f) uint:2131219224 Neo.Blockchain(0077) GetAccount(4702) 
Neo.Blockchain.GetValidators => (eb02981b) uint:462947051 Neo.Blockchain(0077) GetValidators(6612) 
Neo.Blockchain.GetAsset => (01c2f0e0) uint:3773874689 Neo.Blockchain(0077) GetAsset(b3c4) 
Neo.Blockchain.GetContract => (a16ba92e) uint:782855073 Neo.Blockchain(0077) GetContract(2c36) 
Array(9) [ "2c36", "4702", "4f40", "6612", "b3c4", "c02b", "c37e", "d96a", "f8eb" ]

Neo.Header.GetHash => (8098580d) uint:223910016 Neo.Header(a379) GetHash(0b51) 
Neo.Header.GetVersion => (d0d84bd9) uint:3645626576 Neo.Header(a379) GetVersion(4b8b) 
Neo.Header.GetPrevHash => (f0ca16f7) uint:4145466096 Neo.Header(a379) GetPrevHash(a77c) 
Neo.Header.GetMerkleRoot => (15d6cc1b) uint:466408981 Neo.Header(a379) GetMerkleRoot(91e9) 
Neo.Header.GetTimestamp => (b817997d) uint:2107185080 Neo.Header(a379) GetTimestamp(72ee) 
Neo.Header.GetIndex => (14d682fe) uint:4269987348 Neo.Header(a379) GetIndex(cb27) 
Neo.Header.GetConsensusData => (359b68de) uint:3731397429 Neo.Header(a379) GetConsensusData(f97b) 
Neo.Header.GetNextConsensus => (b57e5b55) uint:1432059573 Neo.Header(a379) GetNextConsensus(5e18) 
Array(8) [ "0b51", "4b8b", "5e18", "72ee", "91e9", "a77c", "cb27", "f97b" ]

Neo.Block.GetTransactionCount => (89ab2960) uint:1613343625 Neo.Block(7e04) GetTransactionCount(f55f) 
Neo.Block.GetTransactions => (155dd73b) uint:1003969813 Neo.Block(7e04) GetTransactions(dbc4) 
Neo.Block.GetTransaction => (b64bc65e) uint:1590053814 Neo.Block(7e04) GetTransaction(c02b) 
Array(3) [ "c02b", "dbc4", "f55f" ]

Neo.Transaction.GetHash => (8d64b059) uint:1504732301 Neo.Transaction(c48b) GetHash(0b51) 
Neo.Transaction.GetType => (bab953f2) uint:4065573306 Neo.Transaction(c48b) GetType(5107) 
Neo.Transaction.GetAttributes => (b55c2048) uint:1210080437 Neo.Transaction(c48b) GetAttributes(a037) 
Neo.Transaction.GetInputs => (17a588c1) uint:3246957847 Neo.Transaction(c48b) GetInputs(7d22) 
Neo.Transaction.GetOutputs => (c6c50886) uint:2248721862 Neo.Transaction(c48b) GetOutputs(4a6d) 
Neo.Transaction.GetReferences => (30111110) uint:269553968 Neo.Transaction(c48b) GetReferences(6908) 
Neo.Transaction.GetUnspentCoins => (b73cdaf2) uint:4074388663 Neo.Transaction(c48b) GetUnspentCoins(ecfd) 
Neo.Transaction.GetWitnesses => (f70147d8) uint:3628532215 Neo.Transaction(c48b) GetWitnesses(b368) 
Array(8) [ "0b51", "4a6d", "5107", "6908", "7d22", "a037", "b368", "ecfd" ]

Neo.InvocationTransaction.GetScript => (4105c33d) uint:1036191041 Neo.InvocationTransaction(48ae) GetScript(f81d) 
Array [ "f81d" ]

Neo.Witness.GetInvocationScript => (3deda914) uint:346680637 Neo.Witness(126e) GetInvocationScript(d6df) 
Neo.Witness.GetVerificationScript => (efcaaa6d) uint:1839909615 Neo.Witness(126e) GetVerificationScript(3989) 
Array [ "3989", "d6df" ]

Neo.Attribute.GetUsage => (6a99470d) uint:222796138 Neo.Attribute(9758) GetUsage(0fa1) 
Neo.Attribute.GetData => (19c1a332) uint:849592601 Neo.Attribute(9758) GetData(270f) 
Array [ "0fa1", "270f" ]

Neo.Input.GetHash => (6f6c6e8d) uint:2372824175 Neo.Input(2119) GetHash(0b51) 
Neo.Input.GetIndex => (b794c5e9) uint:3922039991 Neo.Input(2119) GetIndex(cb27) 
Array [ "0b51", "cb27" ]

Neo.Output.GetAssetId => (84848b74) uint:1955300484 Neo.Output(70c2) GetAssetId(7219) 
Neo.Output.GetValue => (9304570f) uint:257361043 Neo.Output(70c2) GetValue(aba8) 
Neo.Output.GetScriptHash => (1f846c63) uint:1668056095 Neo.Output(70c2) GetScriptHash(60ea) 
Array(3) [ "60ea", "7219", "aba8" ]

Neo.Account.GetScriptHash => (1ccd5bb6) uint:3059469596 Neo.Account(c7da) GetScriptHash(60ea) 
Neo.Account.GetVotes => (c1ea2f1a) uint:439347905 Neo.Account(c7da) GetVotes(ad83) 
Neo.Account.GetBalance => (981a11b1) uint:2970688152 Neo.Account(c7da) GetBalance(d1c2) 
Neo.Account.IsStandard => (b542794c) uint:1283015349 Neo.Account(c7da) IsStandard(962a) 
Array(4) [ "60ea", "962a", "ad83", "d1c2" ]

Neo.Asset.Create => (83c5c61f) uint:533120387 Neo.Asset(b041) Create(4759) 
Neo.Asset.Renew => (78849071) uint:1905296504 Neo.Asset(b041) Renew(90c1) 
Neo.Asset.GetAssetId => (b8ecf6af) uint:2952195256 Neo.Asset(b041) GetAssetId(7219) 
Neo.Asset.GetAssetType => (12daadeb) uint:3954039314 Neo.Asset(b041) GetAssetType(eddf) 
Neo.Asset.GetAmount => (1e037b7f) uint:2138768158 Neo.Asset(b041) GetAmount(1304) 
Neo.Asset.GetAvailable => (9b09ee94) uint:2498627995 Neo.Asset(b041) GetAvailable(66c8) 
Neo.Asset.GetPrecision => (97ed725e) uint:1584590231 Neo.Asset(b041) GetPrecision(329e) 
Neo.Asset.GetOwner => (8c62a3f2) uint:4070793868 Neo.Asset(b041) GetOwner(815d) 
Neo.Asset.GetAdmin => (e034d3f7) uint:4157813984 Neo.Asset(b041) GetAdmin(3328) 
Neo.Asset.GetIssuer => (49cdede0) uint:3773680969 Neo.Asset(b041) GetIssuer(e52c) 
Array(10) [ "1304", "329e", "3328", "4759", "66c8", "7219", "815d", "90c1", "e52c", "eddf" ]

Neo.Contract.Create => (f66ca56e) uint:1856335094 Neo.Contract(86c0) Create(4759) 
Neo.Contract.Migrate => (471b6290) uint:2422348615 Neo.Contract(86c0) Migrate(f988) 
Neo.Contract.Destroy => (90d58c79) uint:2039272848 Neo.Contract(86c0) Destroy(ea9b) 
Neo.Contract.GetScript => (791581b6) uint:3061912953 Neo.Contract(86c0) GetScript(f81d) 
Neo.Contract.IsPayable => (77fd08c8) uint:3356032375 Neo.Contract(86c0) IsPayable(2920) 
Neo.Contract.GetStorageContext => (746534fc) uint:4231292276 Neo.Contract(86c0) GetStorageContext(b381) 
Array(6) [ "2920", "4759", "b381", "ea9b", "f81d", "f988" ]

Neo.Storage.GetContext => (8418d60d) uint:232134788 Neo.Storage(f216) GetContext(1e84) 
Neo.Storage.GetReadOnlyContext => (2e3cc04d) uint:1304443950 Neo.Storage(f216) GetReadOnlyContext(5d2f) 
Neo.Storage.Get => (1f2e7b07) uint:125513247 Neo.Storage(f216) Get(5fb9) 
Neo.Storage.Put => (52a141f5) uint:4114719058 Neo.Storage(f216) Put(6568) 
Neo.Storage.PutEx => (cc7fb2d4) uint:3568467916 Neo.Storage(f216) PutEx(150b) 
Neo.Storage.Delete => (ef7cef5d) uint:1575976175 Neo.Storage(f216) Delete(e2d0) 
Neo.Storage.Find => (881908e9) uint:3909622152 Neo.Storage(f216) Find(822b) 
Array(7) [ "150b", "1e84", "5d2f", "5fb9", "6568", "822b", "e2d0" ]

Neo.StorageContext.AsReadOnly => (04ff9b6c) uint:1822162692 Neo.StorageContext(14a0) AsReadOnly(f7d5) 
Array [ "f7d5" ]

Neo.Enumerator.Create => (4eaada58) uint:1490725454 Neo.Enumerator(6e2e) Create(4759) 
Neo.Enumerator.Next => (42298fe0) uint:3767478594 Neo.Enumerator(6e2e) Next(1ff5) 
Neo.Enumerator.Value => (ab5b018e) uint:2382453675 Neo.Enumerator(6e2e) Value(8e37) 
Neo.Enumerator.Concat => (3eae34cb) uint:3409227326 Neo.Enumerator(6e2e) Concat(4d27) 
Array(4) [ "1ff5", "4759", "4d27", "8e37" ]

Neo.Iterator.Create => (24ef3dbf) uint:3208507172 Neo.Iterator(f484) Create(4759) 
Neo.Iterator.Key => (813425bc) uint:3156554881 Neo.Iterator(f484) Key(99a5) 
Neo.Iterator.Keys => (0aef6adf) uint:3748327178 Neo.Iterator(f484) Keys(f0d6) 
Neo.Iterator.Values => (257e13d9) uint:3641933349 Neo.Iterator(f484) Values(53b0) 
Neo.Iterator.Next => (73286276) uint:1986144371 Neo.Iterator(f484) Next(1ff5) 
Neo.Iterator.Value => (e1cb652e) uint:778423265 Neo.Iterator(f484) Value(8e37) 
Array(6) [ "1ff5", "4759", "53b0", "8e37", "99a5", "f0d6" ]

AntShares.Runtime.CheckWitness => (b6d1cc62) uint:1657590198 AntShares.Runtime(d655) CheckWitness(740a)

Remaking the example. SYSCALL System.Storage.Put
Case (i) with full hashing would become SYSCALL 04 e63f1884. 6 bytes total.
Case (ii) with prefix hashing would become SYSCALL 04 cc6d 6568. 6 bytes total.

I think that hashing the full name as 4 bytes is better. The reason is that we only need to do the hash calculation once, instead of having to calculate it twice each time (one for the prefix and one for the name). Moreover, when the API function is searched through the hash table, only one table is needed.

Well then, let's use 4 bytes uint32 :)
I created a draft on neo-vm part. For the neo pricing part, I wonder if we can have Hash256 as static const function... so we could perhaps use it directly on the strings, and that to be computed on compile time, e.g., here inside the switch-case: https://github.com/neo-project/neo/blob/master/neo/SmartContract/ApplicationEngine.cs#L509
Perhaps:

case "System.Runtime.CheckWitness":

becomes:

case Encoding.ASCII.GetBytes("System.Runtime.CheckWitness").Sha256().ToUInt32(0):

@igormcoelho according to https://github.com/neo-project/neo-vm/pull/61/files#diff-a1bfef913b4278d1098838f31820f791R43 is only one Sha256, and in your example you put a double Sha256.

You are correct Shargon.. let's use sha256. I still need to figure out how to compute this in compile time, to make it faster. I'll try to improve C# compiler now: https://github.com/neo-project/neo-compiler/pull/135

Was this page helpful?
0 / 5 - 0 ratings