Skip to content

Commit

Permalink
Add Alephium (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
bumblefudge authored Aug 15, 2024
2 parents 5bafba2 + 56f1970 commit c4305e9
Show file tree
Hide file tree
Showing 4 changed files with 262 additions and 0 deletions.
41 changes: 41 additions & 0 deletions alephium/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
namespace-identifier: alephium
title: Alephium Ecosystem
author: Hongchao Liu (@h0ngcha0)
discussions-to: https://github.com/ChainAgnostic/namespaces/pull/117
status: Draft
type: Informational
created: 2024-06-19
requires: ["CAIP-2", "CAIP-10", "CAIP-19"]
---

# Namespace for Alephium Blockchains

This document defines the applicability of CAIP schemes to the
blockchains of the Alephium ecosystem.

Alephium uses the stateful UTXO model where assets are managed by
UTXOs while contract states are managed using account-based
model. Alephium is also a sharded blockchain, its state is divided
into groups, with separate chains responsible for processing
transactions from one group to another. Alephium's mainnet currently
has 4 groups and 16 blockchains, more groups and blockchains can be
added to increase the throughput.

Understanding these concepts is helpful for interoperability with
other account-based or classic UTXO namespaces.

## Syntax

The namespace `alephium` refers to the Alephium blockchain platform.

## References

- [Official website](https://alephium.org/)
- [Alephium Documentation](https://docs.alephium.org/)
- [Stateful UTXO](https://medium.com/@alephium/an-introduction-to-the-stateful-utxo-model-8de3b0f76749)
- [Blockflow](https://medium.com/@alephium/an-introduction-to-blockflow-alephiums-sharding-algorithm-bbbf318c3402)

## Copyright

Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).
96 changes: 96 additions & 0 deletions alephium/caip10.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
---
namespace-identifier: alephium-caip10
title: Alephium Namespace - Addresses
author: Hongchao Liu (@h0ngcha0)
discussions-to: https://github.com/ChainAgnostic/namespaces/pull/117
status: Draft
type: Standard
created: 2024-06-19
updated: 2024-06-19
requires: ["CAIP-2", "CAIP-10"]
---

# CAIP-10

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

## Rationale

An address on Alephium is a unique identifier that represents an
account or a contract. All networks share the same address format.

There are 4 different address types on Alephium:

* 0x00 - Pay to public key hash (P2PKH)
* 0x01 - Pay to multiple public key Hash (P2MPKH)
* 0x02 - Pay to script hash (P2SH)
* 0x03 - Pay to contract (P2C)

For each address type, `content bytes` are defined as follows:

- **P2PKH** - serialized public key hash
- **P2MPKH** - serialized public key hashes and multisig threshold
- **P2SH** - serialized script hash
- **P2C** - serialized contract id

Hash algorithm used is blake2b.

Constructing an address:

- **address** = `address type || content bytes`

Each address on Alephium belongs to a group, which can be derived
deterministically from the address.

The algorithm for deriving group information from `P2PKH`, `P2MPKH`
and `P2SH` address are similar:

1. Take the relevant bytes from the address. For `P2PKH` and `P2SH`
address, take the `content bytes` directly. For `P2MPKH` address,
take the part of the `content bytes` corresponding to the first
public key hash.
2. Hash the relevant bytes from step 1 using the `djb2` hash algorithm
and perform a bitwise OR operation to the hashed value with `1`.
3. Take the result from step 2, perform bitwise XOR operation on its
last 4 bytes to get an one byte integer.
4. The group number is the remainder of this one byte integer dividing
the total number of groups, which is currently `4` on Alephium.

For `P2C` address, group number is encoded directly as its last byte
of its `content bytes`.

A Typescript implementation of the logic to derive group information
from address can be found
[here](https://github.com/alephium/alephium-web3/blob/b4df0f2858778dec3767a9d23737b7995d3673cb/packages/web3/src/address/address.ts#L88-L104).

## Syntax

The native Alephium address encoding is a [Base58][]-encoded string of the type defined above.
[CAIP-10][] simply uses an entire native address as the `account_address` component.

## Test Cases

```
# P2PKH address
alephium:0_mainnet:15EM5rGtt7dPRZScE4Z9oL2EDfj84JnoSgq3NNgdcGFyu
# P2MPKH address
alephium:0_testnet:2jW1n2icPtc55Cdm8TF9FjGH681cWthsaZW3gaUFekFZepJoeyY3ZbY7y5SCtAjyCjLL24c4L2Vnfv3KDdAypCddfAY
# P2C address
alephium:2_mainnet:26j4viXkBzJd5SaDtQzyGM6joqoECmajncT4QS3tmT9hb
# P2SH address
alephium:0_testnet:ibsc1yJLJxxVcsPfSDJoR3mzrasrZq2Rn63dFQGcDAYE
```

## References

- [Alephium Documentation](https://docs.alephium.org/)
- [base58btc](https://en.bitcoin.it/wiki/Base58Check_encoding#Base58_symbol_chart)

[CAIP-10]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-10.md

## Copyright

Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).
47 changes: 47 additions & 0 deletions alephium/caip19.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
namespace-identifier: alephium-caip19
title: Alephium Namespace - Assets
author: Hongchao Liu (@h0ngcha0)
discussions-to: https://github.com/ChainAgnostic/namespaces/pull/117
status: Draft
type: Standard
created: 2024-06-20
updated: 2024-06-20
requires: ["CAIP-2", "CAIP-19"]
---

## Rationale

Tokens are first class citizens on Alephium. Just like the native
token `ALPH`, all tokens on Alephium are managed by UTXOs, which is
battle tested for secure asset management.

New tokens are deployed through the deployment of new contracts, with
token's id matching the id of the issuing contract. The process of
token issuance is the same for both fungible and non-fungible tokens.

## Specification of token id

Token's id is the same as its issuing contract's id, which is a 32
bytes blake2b hash encoded as a hex string. It is not specific to a
network or a group.

## Syntax

Alephium token id represented as 32 byte array encoded as hex string.

## Examples

```
alephium:universal:383bc735a4de6722af80546ec9eeb3cff508f2f68e97da19489ce69f3e703200
```

## References

- [Token](https://docs.alephium.org/dapps/concepts/tokens)
- [Fungible token standard](https://docs.alephium.org/dapps/standards/fungible-tokens)
- [Non-fungible token standard](https://docs.alephium.org/dapps/standards/non-fungible-tokens)

## Copyright

Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).
78 changes: 78 additions & 0 deletions alephium/caip2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
namespace-identifier: alephium-caip2
title: Alephium Blockchain ID Specification
author: Hongchao Liu (@h0ngcha0)
discussions-to: https://github.com/ChainAgnostic/namespaces/pull/117
status: Draft
type: Standard
created: 2024-06-19
updated: 2024-06-19
---

## Abstract

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

## Rationale

Alephium is a sharded blockchain that organizes addresses and states
into distinct groups. The blockchain id includes both the network id
and the group information.

Each transaction has an origin and destination group. All transactions
from by addresses in group `G1` to addresses in group `G2` will be
included in chain `G1 -> G2`. If there are `G` groups on Alephium,
there will be `G`*`G` chains inside of it. In Alephium, groups are
like cities and chains are like roads connecting them.

Both contract and address belong to a group. A contract deployed in
one group can only be interacted with directly with an address from
the same group. Therefore it is common for a dApp deployed in one
group to request connection to an address within the same
group. However a dApp deployed in all groups might request connection
with an address from any group.

The Network id can be one of three values: `mainnet`, `testnet` and
`devnet`.

Currently, Alephium has 4 groups. The group component of the
blockchain id can take one of five values: `0`, `1`, `2` and `3` which
correspond to groups `0` through `3`, and `-1` which represents any
group.

### Syntax

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

```
chain_id: alephium + ":" + group + "_" + network_id
chain_id: alephium + ":" + network_id + "/" + group
network_id: mainnet, testnet or devnet
group: 0, 1, 2, 3 or -1
```

For information that is not network or group specific, there is a
special chain id `alephium:universal`.

## Test Cases

This is a list of manually composed examples

```
# Alephium mainnet, group 0
alephium:0_mainnet
# Alephium testnet, any group
alephium:-1_testnet
```

## References

- [Blockflow](https://medium.com/@alephium/an-introduction-to-blockflow-alephiums-sharding-algorithm-bbbf318c3402)
- [API Endpoints](https://node.mainnet.alephium.org/docs/)

## Copyright

Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).

0 comments on commit c4305e9

Please sign in to comment.