Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ergo namespace (CAIP2, CAIP10, CAIP19) #98

Merged
merged 19 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions ergo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
namespace-identifier: ergo
title: Ergo Ecosystem
author: Yuriy Gagarin (@gagarin55)
discussions-to: https://github.com/ChainAgnostic/namespaces/pull/98
status: Draft
type: Informational
created: 2023-11-02
requires: ["CAIP-2", "CAIP-10", "CAIP-19"]
---

# Namespace for Ergo Blockchains

This document defines the applicability of CAIP schemes to the blockchains of
the Ergo ecosystem.
Ergo uses a variant of the UTXO addressing model that introduces an abstraction called a [box], which can be helpful to understand before attempting interoperability with either account-model or classic UTXO namespaces.

## Syntax

The namespace "ergo" refers to the Ergo open-source blockchain platform.

## References

- [Official website](https://ergoplatform.org/)
- [Ergo Documentation](https://docs.ergoplatform.com/)

[box]: https://docs.ergoplatform.com/dev/data-model/box/

## Copyright

Copyright and related rights waived via CC0.
87 changes: 87 additions & 0 deletions ergo/caip10.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
namespace-identifier: ergo-caip10
title: Ergo Namespace - Addresses
author: Yuriy Gagarin (@gagarin55)
discussions-to: https://github.com/ChainAgnostic/namespaces/pull/98
status: Draft
type: Standard
created: 2023-11-02
updated: 2023-11-09
requires: ["CAIP-2", "CAIP-10"]
---

# CAIP-10

*For context, see the [CAIP-10][] specification.*

## Rationale

A given Ergo "address" changes completely depending on the network identifier segment.
Different address types in the Ergo-specific UTXO model, like the network identifier used to encode the network on which the address can be dereferenced, can only be determined by decoding the string and inspecting the initial prefix byte.
This prevents unintentional transfers across Ergo blockchains.

Constructing an address:

- **Prefix byte** = `network identifier + address type discriminant`
- **checksum** = `leftmost_4_bytes (blake2b256 (prefix byte || content bytes))`
- **address** = `prefix byte || content bytes || checksum`

Network type is 8-bit unsigned integer in which lower 4 bits are zeros.

Possible values:
* Mainnet - 0 (in hex `0x00`)
* Testnet - 16 (in hex `0x10`)


Address types are (semantics described below):

* 0x01 - Pay-to-PublicKey(P2PK) address
* 0x02 - Pay-to-Script-Hash(P2SH)
* 0x03 - Pay-to-Script(P2S)

For an address type, we form `content bytes` as follows:

- **P2PK** - serialized (compressed) public key
- **P2SH** - first 192 bits of the Blake2b256 hash of serialized script bytes
gagarin55 marked this conversation as resolved.
Show resolved Hide resolved
- **P2S** - serialized script

gagarin55 marked this conversation as resolved.
Show resolved Hide resolved
The checksum is calculated after concatenating prefix byte to content bytes, and then postpended to form a full Ergo standard address notation.

## Syntax

The syntax of Ergo addresses:

```
caip10-like address: namespace + ":" chainId + ":" + address
namespace: ergo
chain Id: 32-character prefix from the hash of the genesis block
address: Ergo address represented as a [Base58btc][]-encoded string
```



## Test Cases

```
# Namespace-wide Public Key:
gagarin55 marked this conversation as resolved.
Show resolved Hide resolved
# 0x0202f2b96aa59e6f37fc978883f78e54fd319fa37dcf971d8e69f9e9225376bcf1

# P2PK Address on Ergo Mainnet
ergo:b0244dfc267baca974a4caee06120321:9eYMpbGgBf42bCcnB2nG3wQdqPzpCCw5eB1YaWUUen9uCaW3wwm

# P2PK Address on Ergo Testnet
ergo:e7553c9a716bb3983ac8b0c21689a1f3:3WvdWQMfUeKFcsQudPM4zqTCcncSAtYZgi96Vr3zLJqYQVn2qmaw
```

## Links

- [About addresses in Ergo Documentation][address format]
- [Conversion between binary and Base58btc representation][base58btc]

[address format]: https://docs.ergoplatform.com/dev/wallet/address/address_types
[base58btc]: https://en.bitcoin.it/wiki/Base58Check_encoding#Base58_symbol_chart
gagarin55 marked this conversation as resolved.
Show resolved Hide resolved

## Copyright

Copyright and related rights waived via
[CC0](https://creativecommons.org/publicdomain/zero/1.0/).
65 changes: 65 additions & 0 deletions ergo/caip19.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
namespace-identifier: ergo-caip19
title: Ergo Namespace - Assets
author: Yuriy Gagarin (@gagarin55)
discussions-to: https://github.com/ChainAgnostic/namespaces/pull/98
status: Draft
type: Standard
created: 2023-11-04
updated: 2023-11-09
requires: ["CAIP-2", "CAIP-19"]
---

## Rationale

Ergo supports custom tokens as first-class citizens as outlined in [EIP-0004].

A transaction can create tokens from thin air in its outputs if the Asset ID matches the ID of the transaction's first input ([box]).
Since the box identifier is cryptographically unique, it's impossible to have a second asset with the same identifier.
This rule also implies that only one new asset can be created per transaction.

The ID format for fungible (ERC20-equivalent) and non-fungible (ERC-721 equivalent) tokens is the same.
The process for issuance of either is also the same.
The only difference is that NFTs must have specific values for certain properties.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where are these values expressed, though? can you tell from looking at a CAIP-19 expression (or a native expression) which one it is? note that in the EVM profile of CAIP-19 this extra value is tacked onto the URI using a /, which seems handy enough if that info would be public anyways to all queriers?

Copy link
Contributor Author

@gagarin55 gagarin55 Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, when you see at Ergo Token ID you can't say what kind of token it is. Ethereum has particular ERC for each token standard. But Ergo has only EIP-4 standard which describes additional registers for NFT-tokens. I think this is application task to receive token info from blockchain (or store it somewhere).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, there's a few other namespaces like that. I guess what I am trying to tease out (and suggesting you make explicit in the doc for future implementers with little context) is whether they can append, e.g. /1234 for #1234 in a serial NFT series like in eip155/caip-19 when your application has already retrieved that info from the blockchain before passing that CAIP-19 identifier to another application/counterparty, and conversely when a CAIP-19 received from a trusted counterparty with those additional registers/segments can be trusted versus when they should be validated by checking on-chain context. not blocking, just suggesting, since CAIP-19 strings are often passed around by folks in contexts quite distant from chains and deducing a lot from the strings themselves, like, for example, in dashboard dapps that aggregate data from various sources while minimizing the required roundtrips to nodes for onchain data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand what you are speaking about, but in Ergo there is no well defined NFT standard and particular it is unclear how to implement NFT Collections. There is no Collection/Series ID as we have contract address in Ethereum.

I suggest to proceed further. If someday the NFT problem in Ergo will have solid solution we are able to update specs.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gagarin55, there is this EIP-34, please check if it is suitable here. If not, please feel free to file a PR with the extension.

## Specification of Asset ID

Asset ID is a 32 byte array encoded as a hex string.
When issued, it is equal to the ID of the transaction's first input that issued this asset.

## Syntax

The syntax of Ergo Asset ID:

```
address: namespace + ":" chainId + ":" + reference
namespace: ergo
chain ID: 32-character prefix from the hash of the genesis block
reference: Ergo Asset ID represented as hex string
```

## Examples

```
# Ergo Mainnet
ergo:b0244dfc267baca974a4caee06120321:56d89fdb0c92605d6c80f06a4c6a217f62bdc5695776f916daeabd708683f60d

# Ergo Testnet
ergo:e7553c9a716bb3983ac8b0c21689a1f3:0160b869f30a5424e59cb3453e8a726b81fe83761d02ab41829cb7b2e4b624bc

```

## Links

- [Token][token] overview
- [Ergo Box][box] overview
- [About addresses in Ergo Documentation][address format]

[box]: https://docs.ergoplatform.com/dev/data-model/box/
[token]: https://docs.ergoplatform.com/dev/data-model/box/tokens/
[address format]: https://docs.ergoplatform.com/dev/wallet/address/address_types
[EIP-0004]: https://github.com/ergoplatform/eips/blob/master/eip-0004.md

## Copyright

Copyright and related rights waived via [CC0](../LICENSE).
76 changes: 76 additions & 0 deletions ergo/caip2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
namespace-identifier: ergo-caip2
title: Ergo Blockchain ID Specification
author: Yuriy Gagarin (@gagarin55)
discussions-to: https://github.com/ChainAgnostic/namespaces/pull/98
status: Draft
type: Standard
created: 2023-11-02
updated: 2023-11-09
---


## Abstract

In CAIP-2 a general blockchain identification scheme is defined.
This is the implementation of CAIP-2 for Ergo network.

## Specification

Blockchains in the "ergo" namespace are identified by their chain ID.

Chain ID is 32-character prefix from the hash of the genesis block of a given chain, in lowercase hex representation.


### Syntax

The `chain_id` is a case-sensitive string in the form

```
chain_id: namespace + ":" + reference
namespace: ergo
reference: 32-character prefix from the hash of the genesis block
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 32 characters? If you're already substringing out a prefix, you might be using up valuable characters that you could need for the address types (CAIP-10, CAIP-19) and possible paths or query parameters tacked on at the end. If you check out other CAIP-2 profiles that substring a hash, they tend to opt for 8 characters or even 4, if they're not anticipating too much collision-risk between hundreds of thousands of private networks and testnets :D

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(This is not to say 8 or 4 is optimal, just recommending you add a small ### Rationale section if there is, in fact, a meaning to using a 32char reference! )

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, if there are only 16 possible chainIDs in the prefixes (half an 8bit unsigned --> 0-15, right?), chainId could also just that prefix? just a thought, no strong preference here just pointing out that 0 and 15 are both equally good values here, if you want to economize or use them as a checksum against the prefix in the CAIP-10/19 reference that follows!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I borrowed the concept of using a 32-character identifier from another blockchain's CAIP-2.

Allow me to clarify the concept. In Ergo addresses, we should view the network type prefix not merely as a specific chain ID, but rather as a designation of the blockchain type—whether it's a testnet, mainnet, etc.
For example, if we were to fork the mainnet, we would create another chain with the same blockchain type but a different chain ID (similar to Bitcoin forks).
Alternatively, consider a scenario where someone decides to launch a new testnet with a new genesis block but the same address scheme.

I am not an Ergo core developer, so the current situation stands as described.

```

### Resolution method

One can resolve chain ID by request `info` method on Ergo node API (see [RPC Endpoints][]):
```
curl https://node.ergo.watch/info
```

JSON Response contains `genesisBlockId` field:
```
{
...
"genesisBlockId" : "b0244dfc267baca974a4caee06120321562784303a8a688976ae56170e4d175b",
...
}
```
So chain ID for Mainnet is `b0244dfc267baca974a4caee06120321`.


## Test Cases

This is a list of manually composed examples

```
# Ergo mainnet
ergo:b0244dfc267baca974a4caee06120321

# Ergo testnet
ergo:e7553c9a716bb3983ac8b0c21689a1f3

```

## References
- [Address][] - Address Encoding scheme on Ergo blockchain
- [RPC Endpoints][] - Ergo full node RPC API

[Address]:https://docs.ergoplatform.com/assets/py/Ergo_Address_Encoding/
[RPC Endpoints]:https://docs.ergoplatform.com/node/swagger/


## Copyright

Copyright and related rights waived via [CC0](../LICENSE).