Skip to content

Instantly share code, notes, and snippets.

@davidatwhiletrue
Last active January 12, 2023 14:06
Show Gist options
  • Save davidatwhiletrue/b43b72c834385665c6f3775c479ad1aa to your computer and use it in GitHub Desktop.
Save davidatwhiletrue/b43b72c834385665c6f3775c479ad1aa to your computer and use it in GitHub Desktop.

CEP-78 Events - Storage Needs

Gas cost estimations

An attempt to estimate the gas cost for various lengths of data in the event dictionary entry has been done using the CEP-78 contract built from this commit.

The baseline is an event with just one byte of data indicating the event type (aka CEP-78 event type modality).

Event Data / Length Cost for first token minted Δ gas
u8 / 6 bytes 1.817.618.450 motes -
(u8,u8) / 9 bytes 1.820.206.210 motes 2.587.760 motes
(u8,string-len:6) / 18 bytes 1.826.317.300 motes 8.698.850 motes
(u8,string-len:100) / 112 bytes 1.887.685.030 motes 70.066.580 motes
(u8,string-len:50,string-len:50) / 117 bytes 1.891.817.740 motes 74.199.290 motes
(u8,string-len:100,string-len:100) / 217 bytes 1.956.753.980 motes 139.135.530 motes

Length includes the total number of bytes required to encode the data in a CLValue.

Looking at the gas costs defined at chainspec.toml file, each byte of storage costs 630.000 motes. In the table above the cost increment is not equal to Δbytes*630.000 but it's close.

Length approximation using the Casper Event Standardad Proposal

Events are emitted as a new entry in the dictionary stored under the contract named key events. The data contained is a CLValue with type Option<Vec<u8>>. The Vec<u8> contains a sequence of values that identifies the dictionary item as an event and describes it.

Data parts:

  • Event tag: string event: 9 bytes
  • Event type: string with event name: 8-16 bytes
  • Event body:
Event Contents Length
Mint token_id (U64) + recipient (Key) 41 bytes
Transfer token_id (U64) + recipient (Key) + sender (Key) 74 bytes
Burn token_id (U64) 8 bytes
Approve token_id (U64) + operator (Key) 41 bytes
Approve_all owner (Key) + operator (Key) + approve_all (Bool) 67 bytes
Set_metadata token_id (U64) 8 bytes

The total length of the event for each type is then:

Event Length
Mint 58 bytes
Transfer 95 bytes
Burn 25 bytes
Approve 61 bytes
Approve_all 91 bytes
Set_metadata 33 bytes

Looking at the gas estimation table, the cost increment for the additional information included in the event might range between 0.020 CSPR and 0.070 CSPR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment