Marigold
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    1
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    # Proposal for Tezos eventlog **Authors**: Xiang Fei Ding, YunYan Chi **Target Protocol**: K **Summary**: Add capability of on-chain event logging to Tezos contracts that is similar to Ethereum virtual machine event support **Previous proposal**: [Eduardo](https://gitlab.com/tezos/tzip/-/blob/e36c5d8115ee646a4484de0dc37ee9f6ebf9c5bd/drafts/current/draft-onchain-events.md) # Abstract On-chain events enables external applications to respond to custom notification from smart contracts and triggers effects in other software systems. # Motivation We intend to enable native event logging in Tezos. This proposal will introduce a minimal support for contract events in Tezos, allowing Tezos-interfacing external applications and services to respond to change in contract states. The primary motivation behind introduction of event is to allow contracts to trigger visible events with type safety. Event logging is an important tool in smart contract ecosystem. This is a widely known pattern that applications interfacing with smart contracts should react to the change in contract states. The simplest use of events is to emit an on-chain event by a smart contract to trigger a change in the front end of a web application, which passively observing a stream of transaction submitted to the target smart contract. A more involved example could be cross-chain communication where an actively observing node watching on Tezos and other blockchains react and trigger further action in response to events on Tezos to support cross-chain operations. Following the spirit of the event logging from EVM, we also make the following observation. - There is a need to indexing the events by tags and a subset of data fields. While this proposal does not address this issue unfortunately, there is a possibility to extend this proposal to support indexing as well in a separate draft. - EVM identifies event variants via a hash digest of event topic and data types, which makes event discovery harder. This proposal improves the event logging story in this aspect by clear event tagging and event type declaration, without hashing. This proposal also aims to provide a standard interface to event logging patterns. Our implementation of event logs will serve as an answer to the coordination problem when the indexers and the contract need to agree on the channel of delivery of events and the format of event data. For more detailed discussion, we shall refer the reader to the discussion on [alternative solutions](#Comparison-with-alternatives) below. # Specification The idea is to introduce a new Michelson instruction, `EMIT`, to allow contracts to log information into the transaction receipt. ## Anatomy of event data attachment Events consist of two data fields. The first will be of the address of the event. The second will be a data item of a *packable* type. ## Sending events A contract may use a new Michelson instruction `EMIT` to emit events. This new Michelson primitive node accepts one argument and one annotation. The annotation shall be the string tag of the emitted event and the argument shall be the type of the data attachment. For instance, `EMIT %tag ty` indicates that this instruction will emit an event associated with the tag `tag` and the data attachment shall be of a *packable* type `ty`. `EMIT` pops one data item off the stack and pushes one internal `operation` onto the stack. Therefore, the typing rule of `EMIT` is specified as follows. EMIT %tag 'ty :: 'ty : 'S -> operation : 'S EMIT %tag :: 'ty : 'S -> operation : 'S To actually send out the events, most importantly, the produced `operation`s must be included into the list of operations that the main contract code returns along with other `operation`s that this contract wants to effect. ## Locating events Events can be found as internal operation results. Event tags are stored as `entrypoint`s and event data as `value`s in the `parameters` fields. Here is an example. { "protocol": "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK", "hash": "opNX59asPwNZGu2kFiHFVJzn7QwtyaExoLtxdZSm3Q3o4jDdSmo", // ... fields elided for brevity "contents": [ { "kind": "transaction", // ... fields elided for brevity "metadata": { // ... fields elided for brevity "internal_operation_results": [ { "kind": "event", "source": "KT1X4TgGdDMUTxG4i7xQKgZ7Fo5nQghTRdvj", "nonce": 0, "type": <Michelson data type>, "tag": "<tag>", "payload": <Michelson value>, "result": { "status": "applied", "consumed_milligas": "<gas value>" } } ] } } ] } ## Runtime specification At the end of a successful contract execution, the list of operations are inspected. The event emitting internal operations are plucked out and the corresponding event entries are instead written into the successful transaction operation receipt. *From the Michelson's point of view*, the contract writer may declare `event` to be record types or enums. Here is an example of Michelson type declaration and use of that event type. ``` parameter unit; storage unit; code { DROP ; UNIT ; PUSH string "right" ; RIGHT nat ; EMIT %tag1 (or (nat %int) (string %str)) ; PUSH nat 2 ; LEFT string ; EMIT ; NIL operation ; SWAP ; CONS ; SWAP ; CONS ; PAIR } ``` ## Economic model The fee chargeable for emitting events shall intuitively be proportional to the size of the data of the emitted events. Specifically, the gas cost for obtaining a handle to the "event sink" is free; the standard `TRANSFER_TOKEN` gas cost applies for "sending" event data to the "event sink." The only other gas cost will incur after the successful contract evaluation when the event address is realized and event emission operations were plucked out and type-checked. ## Sink contract There is a proposal to implement event logs on the contract level. The idea is to have one or a pool of contracts, or so called `sink contract`s, ready to accept calls. Those calls will naturally be recorded on-chain with event tags and data. One issue with this arrangement is that it requires either the toolchain or the contract developers to originate and manage these sidecar contracts diligently. Meanwhile, these sidecars are trivial yet they need to be created separately for each event schema. The addresses of the sidecars need to be recorded correctly for origination of main contracts later. This process incurs great operational costs and risks. On top of this, there remains the issue of coordination of event logging schema. While sink contracts are one of those schema as the basis of event communication, there is a lot of room for variation in implementation, leaving indexers to decide precise details in interpretation of sink contract calls. This event MVP serves as a canonical basis for communicating events to indexers, which is to read them off the transaction receipt and expect them to have the formats as specified here. ## Use of Global Table of Constants There is a proposal to replace the arbitrary event tag with Global Table of Constants. As a recap, the Global Table of Constants, also known as GTOC, is a registration table of constant Michelson expressions. When the contract is selected for execution, the `H_constant` nodes are replaced with an actual Michelson value by looking up the constant expression hash in GTOC. Note that `H_constant` nodes can occur in any place of the contract Michelson, including the top-level type definitions and the contract code node. The transformed contract code will then be passed on for interpretation with the constant expressions properly substituted. # Appendix ## A brief summary of EVM event logs The primary source of the following information will be taken from the [Ethereum Yellow Paper](https://ethereum.github.io/yellowpaper/paper.pdf). ### EVM event features According to the yellow paper, EVM supports the following event features. - Uniquely identify events with zero to four topic fields and types of data fields - Up to four topic slots assigned to each event type - Event logs are stored directly into transaction receipt.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully