Skip to content

Latest commit

 

History

History
150 lines (112 loc) · 7.75 KB

cip-19.md

File metadata and controls

150 lines (112 loc) · 7.75 KB
CIP No. Title Author Status Type Created
19
KeyValue EventLog Standard
Haizhou Wang <Haizhou@confluxnetwork.org>
Draft
Backward Compatible
2020-08-10

Simple Summary

A key value event log standard.

Abstract

The following standard specifies a key value format event log which include "announcer", "address", "key", "value" fields. The standard makes it easy for users to use the block chain consensus mechanism to solve the identity and content verification problems of information publishers.

Motivation

Although smart contract using block chain solves information distribution, validation and storage at the same time. But for some DApp, storage are not strict requirements, using memory to store data is very expensive and these DApp could storage them self. This standard is proposed to standardize the format of such information in EventLog.

Specification

event Announce(address indexed announcer, bytes indexed keyHash, bytes key, bytes value);
  • 1.Event MUST be Announce(address,bytes,bytes,bytes) , which signature MUST be 0x14cb751d0950ff2788201931c45f715f7472443bc197311d9e3a7a0ba566b7e6
  • 2.Event MUST NOT be anonymous
  • 3.Event announcer and keyHash MUST be indexed, key and value MUST NOT be indexed
  • 4.Event keyHash MUST be keccak256 hash of key

Note: The standard only specifies the format, but not the specific implementation method.

Rationale

  • Data structure

Announce event log:

{
  "epochNumber": 1652588,
  "logIndex": 0,
  "transactionIndex": 0,
  "transactionLogIndex": 0,
  "address": "0x8bf8f3d98519dc933a0105356d080237a2e939a7",
  "blockHash": "0xda45520d27897c164306e8f2e20e18e1f83d74f5015fbea663069767da65af71",
  "data": "0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000036b65790000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000576616c7565000000000000000000000000000000000000000000000000000000",
  "topics": [
    "0x14cb751d0950ff2788201931c45f715f7472443bc197311d9e3a7a0ba566b7e6",
    "0x0000000000000000000000001bd9e9be525ab967e633bcdaeac8bd5723ed4d6b",
    "0x07855b46a623a8ecabac76ed697aa4e13631e3b6718c8a0d342860c13c30d2fc"
  ],
  "transactionHash": "0xca05ebc9c8eb6c1f03ae82f008335f4e76c9f2a275f87c08defd448167790c8a"
}

explanation:

address: smart contract address
topics[0]: event log signature
topics[1]: address of announcer
topics[2]: keccak256 hash of key field
data: encode of key and value data, decoded as {key:0x6b6579, value:0x76616c7565}, which is {key:"key", value:"value"} in utf8 code.
  • Gas cost

EventLog only stays in block chain node for a period of time, and the timeout information will not be found, nor will it occupy the node's storage resources indefinitely. This standard does not need to occupy storageCollateralized and the transaction costs can be minimized to include only the gas portion.

  • Application scenarios

Information distribution and validation for DApp. Real time chat application. News or stream media.

Backwards Compatibility

TBD

Test Cases

TBD

Implementation

  • mini implement of Announce:
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.10;

contract Announcement {
    event Announce(address indexed announcer, bytes indexed keyHash, bytes key, bytes value);

    function announce(bytes calldata key, bytes calldata value) external {
        emit Announce(msg.sender, key, key, value);
    }
}

call announce() with key, value and contract set msg.sender to announcer

  • The standard allows multiple Announce event log from one transaction, contract could generate multiple Announce to reduce transaction as follows.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma abicoder v2;

contract Announcement {
    struct Entry {
        bytes key;
        bytes value;
    }

    event Announce(address indexed announcer, bytes indexed keyHash, bytes key, bytes value);

    function announce(Entry[] calldata array) external {
        for (uint i = 0; i < array.length; i++) {
            emit Announce(msg.sender, array[i].key, array[i].key, array[i].value);
        }
    }
}
  • Standard can be embedded in other contracts, also can be extended.

Security Considerations

  • Conflux Transaction data length is limited, large key and value may cause the transaction fail.
  • Standard not require announcer must be msg.sender.

Copyright

Copyright and related rights waived via CC0.