-
Notifications
You must be signed in to change notification settings - Fork 111
Spec for StarkNet #39
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
574be28
Spec for StarkNet
delaaxe 313790e
Update starknet/caip-2.md
delaaxe a8b1647
Update starknet/caip-2.md
delaaxe 0ec2cd6
Create README.md
delaaxe c9717a2
minor editorial on readme
dd4f021
minor editorial + formatting
7ac026c
minor editorial + add EIP55 ref
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| --- | ||
| namespace-identifier: starknet | ||
| title: StarkNet Ecosystem | ||
| author: Argent Labs | ||
| discussions-to: | ||
| status: Draft | ||
| type: Informational | ||
| created: 2022-12-04 | ||
| updated: 2022-12-04 | ||
| replaces: CAIP-28 | ||
| --- | ||
|
|
||
| # Namespace for StarkNet | ||
|
|
||
| ## Introduction | ||
|
|
||
| This document describes the syntax and structure of the namespace for StarkNet. | ||
|
|
||
| ## Syntax | ||
|
|
||
| The namespace "starknet" refers to the StarkNet Layer 2 chain on Ethereum. | ||
|
|
||
| [Cairo field elements][] are one of the more novel aspects of Cairo's [Type system][], although future interfaces may not require any special knowledge or handling of field elements. ([More on field elements][].) | ||
|
|
||
| ## References | ||
|
|
||
| [Type system]: https://starknet.io/docs/reference/syntax.html#type-system | ||
| [Cairo field elements]: https://starknet.io/docs/how_cairo_works/cairo_intro.html#field-elements | ||
| [More on field elements]: https://medium.com/nethermind-eth/field-elements-all-the-way-down-59f02387d1d6 | ||
|
|
||
| ## Copyright | ||
|
|
||
| Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| --- | ||
| namespace-identifier: starknet-caip10 | ||
| title: StarkNet Namespace - Addresses | ||
| author: Argent Labs | ||
| discussions-to: | ||
| status: Draft | ||
| type: Standard | ||
| created: 2022-11-18 | ||
| updated: 2022-11-18 | ||
| requires: ["CAIP-2", "CAIP-10"] | ||
| supersedes: CAIP-5 | ||
| --- | ||
|
|
||
| # CAIP-10 | ||
|
|
||
| *For context, see the [CAIP-10][] specification.* | ||
|
|
||
| ## Rationale | ||
|
|
||
| The address of a StarkNet account is represented by an element of a field, whose maximum | ||
| value is slightly less than `2**256 - 1`. Because of this, 32-byte hex representations of | ||
| these addresses always have a leading zero. | ||
|
|
||
| ## Syntax | ||
|
|
||
| Like on Ethereum, StarkNet addresses begin with `0x` followed by 64 hexadecimal characters | ||
| representing the zero-padded address number, totaling 66 characters. | ||
|
|
||
| It's recommended to checksum the address using capitalization according to | ||
| [EIP55][], as is common elsewhere on EVM systems. | ||
|
|
||
| ## Test Cases | ||
|
|
||
| ``` | ||
| # StarkNet mainnet alpha (valid/checksummed) | ||
| starknet:SN_MAIN:0x02DdfB499765c064eaC5039E3841AA5f382E73B598097a40073BD8B48170Ab57 | ||
|
|
||
| # StarkNet mainnet alpha (may not validate in checksum-conformant systems) | ||
| starknet:SN_MAIN:0x02ddfb499765c064eac5039e3841aa5f382e73b598097a40073bd8b48170ab57 | ||
|
|
||
| # StarkNet goerli alpha | ||
| starknet:SN_GOERLI:0x02DdfB499765c064eaC5039E3841AA5f382E73B598097a40073BD8B48170Ab57 | ||
| ``` | ||
|
|
||
|
|
||
| ## References | ||
|
|
||
| - [addresses][]: Address format on StarkNet | ||
| - [Length of addresses][]: Decision fixing the length of addresses on StarkNet | ||
|
|
||
| [addresses]: https://starknet.io/docs/how_cairo_works/cairo_intro.html#field-elements | ||
| [Length of addresses]: https://github.com/starkware-libs/starknet-specs/pull/58 | ||
| [CAIP-2]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md | ||
| [CAIP-10]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-10.md | ||
| [CAIP-19]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-19.md | ||
| [CAIP-21]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-21.md | ||
| [CAIP-22]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-22.md | ||
| [EIP55]: https://eips.ethereum.org/EIPS/eip-55 | ||
|
|
||
| ## Rights | ||
|
|
||
| Copyright and related rights waived via CC0. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| --- | ||
| namespace-identifier: starknet-caip2 | ||
| title: StarkNet Namespace - Chains | ||
| author: Argent Labs | ||
| discussions-to: | ||
| status: Draft | ||
| type: Standard | ||
| created: 2022-11-18 | ||
| updated: 2022-11-18 | ||
| requires: CAIP-2 | ||
| supersedes: CAIP-5 | ||
| --- | ||
|
|
||
| # CAIP-2 | ||
|
|
||
| *For context, see the [CAIP-2][] specification.* | ||
|
|
||
| ### Rationale / Syntax | ||
|
|
||
| The namespace `starknet` refers to the StarkNet Layer 2 on Ethereum. | ||
|
|
||
| StarkNet currently represents its chains with string identifiers such as | ||
| `SN_MAIN` and `SN_GOERLI`. Internally, these strings are encoded as field | ||
| elements (according to a transformation documented in the system's [core | ||
| documentation][Transaction structure]), but using the case-sensitive root string | ||
| identifiers simplifies interoperability by sidestepping type system | ||
| interoperability around integers. | ||
|
|
||
| ### Resolution Method | ||
|
|
||
| To resolve a reference for the StarkNet namespace, make a JSON-RPC | ||
| request to a StarkNet Pathfinder node with method `starknet_chainId`, for example: | ||
|
|
||
| ```python | ||
| import requests | ||
|
|
||
| response = requests.post( | ||
| url=f"https://starknet-goerli.infura.io/v3/{API_KEY}", | ||
| json={"jsonrpc": "2.0", "method": "starknet_chainId", "params": [], "id": 1}, | ||
| ) | ||
|
|
||
| hex_chain_id = response.json()["result"] # "0x534e5f474f45524c49" | ||
| chain_id = bytes.fromhex(hex_chain_id[2:]).decode() # "SN_GOERLI" | ||
| ``` | ||
|
|
||
| The response will return a base-16-encoded field element that should be converted to | ||
| a string to express a StarkNet-compatible reference. | ||
|
|
||
| ## Test Cases | ||
|
|
||
| This is a list of manually composed examples: | ||
|
|
||
| ``` | ||
| # StarkNet mainnet alpha | ||
| starknet:SN_MAIN | ||
|
|
||
| # StarkNet goerli alpha | ||
| starknet:SN_GOERLI | ||
| ``` | ||
|
|
||
| ## References | ||
|
|
||
| - [Transaction structure][]: StarkNet's documentation on chainIDs used in transaction. | ||
| - [Making requests][]: Infura's documentation on how to call their Ethereum-style RPC endpoints for StarkNet. | ||
|
|
||
| [Transaction structure]: https://docs.starknet.io/documentation/develop/Blocks/transactions/#chain-id | ||
| [Making requests]: https://docs.infura.io/infura/networks/starknet/make-requests | ||
| [CAIP-2]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-2.md | ||
| [CAIP-10]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-10.md | ||
| [CAIP-19]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-19.md | ||
| [CAIP-21]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-21.md | ||
| [CAIP-22]: https://github.com/ChainAgnostic/CAIPs/blob/master/CAIPs/caip-22.md | ||
|
|
||
| ## Rights | ||
|
|
||
| Copyright and related rights waived via CC0. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.