Skip to content

Why ordering of inputs and outputs can' be deterministic #2

@oacdutra

Description

@oacdutra

I found a bug during the Sonic project review:

I noticed that the GenesisID changes according to the order of data added when issuing a contract.

After investigating, I noticed that the immutable and destructible fields, used in Genesis CommitmentId, are of type SmallVec., i.e, we have no ordering guarantees.

We could use the TinyOrdMap type, for example, to guarantee that regardless of the order of the entries, we will produce the same GenesisID, which consequently makes the same ContractID.

To reproduce the error, use the two YAMLs I added below. In them, I reversed the order of the circulating fields in them.

sealType: BitcoinOpret
codexId: znwQGVhW-rfRa8el-pNaAsUW-UWxXsB_-4UlC~Tf-TERhBm4#mirage-queen-delphi
name: DemoToken
method: issue
timestamp: "2024-12-18T10:32:00-02:00"

global:
  - name: circulating
    verified: 10000
  - name: name
    verified: Demo Token
  - name: ticker
    verified: DEMO
  - name: precision
    verified: centiMilli

owned:
  - name: owned
    seal: b7116550736fbe5d3e234d0141c6bc8d1825f94da78514a3cede5674e9a5eae9:1
    data: 10000
sealType: BitcoinOpret
codexId: znwQGVhW-rfRa8el-pNaAsUW-UWxXsB_-4UlC~Tf-TERhBm4#mirage-queen-delphi
name: DemoToken
method: issue
timestamp: "2024-12-18T10:32:00-02:00"

global:
  - name: name
    verified: Demo Token
  - name: ticker
    verified: DEMO
  - name: precision
    verified: centiMilli
  - name: circulating
    verified: 10000

owned:
  - name: owned
    seal: b7116550736fbe5d3e234d0141c6bc8d1825f94da78514a3cede5674e9a5eae9:1
    data: 10000

Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions