Support Uuid for a clear unique id type.
Usually, Uuidv4 is used the most, but v4 is based on random.
So Use internally Uuidv5 and NAMESPACE_OID.
The name is combined with contract address, block height, and increase-sequential(u16).
Add sha1 crypto native API.
Uuidv5 uses internally sha1.
However, crypto-related calls in the contract usually cost expensive gas.
And As crypto function code is compiled into wasm code, there is a performance degradation compared to native.
So I Change gas to be configurable by adding native like other crypto-related apis.
The set gas is based on benchmark results. It runs significantly faster than other existing crypto APIs (nano sec(ns) vs micro sec(us)), so the gas value is much lower than existed api.
About the larger the hash input, the more overhead it may have than expected.
So put a limit on the hash input, we can relax this later as needed.
Add the example contract 'voting-with-uuid' for usage examples and gas consumption measurement.
As per the table, the gas consumption increased by the using hash function.
This even includes the cost of uuid.to_string() in attributes. Excluding this, the actual cost of uuid is lower.
optimize by rust-optimizer
make seq-id msg
make uuid msg(sha1 via wasm)
make uuid msg(sha1 via native)
make uuid msg without to_string (sha1 via native)
X
35626
52338
49210
44954
O
30885
46475
42848
39030
Types of changes
[ ] Bug fix (changes which fixes an issue)
[x] New feature (changes which adds functionality)
[ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
Changed the input limit from 40bytes to 80bytes as needed.(avg 266ns -> 270ns)
The benchmark results show no significant change in the execution speed of sha1.
Description
Closes #141
Support
Uuid
for a clear unique id type. Usually,Uuidv4
is used the most, but v4 is based on random. So Use internallyUuidv5
andNAMESPACE_OID
. The name is combined withcontract address
,block height
, andincrease-sequential(u16)
.Add
sha1
crypto native API.Uuidv5
uses internallysha1
. However, crypto-related calls in the contract usually cost expensive gas. And As crypto function code is compiled into wasm code, there is a performance degradation compared to native.Add the example contract '
voting-with-uuid
' for usage examples and gas consumption measurement. As per the table, the gas consumption increased by the using hash function. This even includes the cost ofuuid.to_string()
in attributes. Excluding this, the actual cost of uuid is lower.Types of changes
Checklist