Skip to content

Commit ad790a5

Browse files
authored
chore: added development keypair (#117)
* added keypair * add a note about keypair to the readme * formatting * fix type in readme * remove keypair * add keypair back * remove keypair * add keypair back * rename keypair
1 parent 8e0b8de commit ad790a5

File tree

2 files changed

+93
-30
lines changed

2 files changed

+93
-30
lines changed

README.md

Lines changed: 92 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Solana Protocol Contracts
12

23
**Note**: Mainnet-beta, testnet, devnet gateway program address:
34

@@ -6,28 +7,42 @@ ZETAjseVjuFsxdRxo6MmTCvqFwb3ZHUx56Co3vCmGis
67
```
78

89
The PDA account address (derived from seeds `b"meta"` and canonical bump) is
10+
911
```
1012
2f9SLuUNb7TNeM6gzBwT4ZjbL5ZyKzzHg1Ce9yiquEjj
1113
```
1214

1315
The PDA account address (derived from seeds `b"rent-payer")
16+
1417
```
1518
Am1aA3XQciu3vMG6E9yLa2Y9TcTf2XB3D3akLtjVzu3L
1619
```
1720

21+
**Important Note**: The keypair in this repository is public and is used only
22+
for development purposes. It should not be used on testnet or mainnet
23+
environments.
1824

1925
# Introduction
2026

21-
This repository hosts the smart contract (program) deployed on the Solana network to enable ZetaChain's cross-chain functionality. It consists of a single program that supports the following actions:
27+
This repository hosts the smart contract (program) deployed on the Solana
28+
network to enable ZetaChain's cross-chain functionality. It consists of a single
29+
program that supports the following actions:
2230

23-
1. Users on the Solana network can send SOL to the program to deposit into ZetaChain, with the option to invoke a ZetaChain EVM contract.
24-
2. Contracts on the ZetaChain EVM can withdraw SOL to users on the Solana network.
31+
1. Users on the Solana network can send SOL to the program to deposit into
32+
ZetaChain, with the option to invoke a ZetaChain EVM contract.
33+
2. Contracts on the ZetaChain EVM can withdraw SOL to users on the Solana
34+
network.
2535

2636
# Build and Test Instructions
2737

28-
Prerequisites: a recent version of `rust` compiler and `cargo` package manger must be installed. The program is built with the `anchor` framework so it needs to be installed as well; see [installation](https://www.anchor-lang.com/docs/installation)
38+
Prerequisites: a recent version of `rust` compiler and `cargo` package manger
39+
must be installed. The program is built with the `anchor` framework so it needs
40+
to be installed as well; see
41+
[installation](https://www.anchor-lang.com/docs/installation)
42+
43+
Please install compatible Solana tools and anchor-cli before build, otherwise
44+
the program will not be built successfully
2945

30-
Please install compatible Solana tools and anchor-cli before build, otherwise the program will not be built successfully
3146
```bash
3247
$ cargo install --git https://github.com/coral-xyz/anchor avm --force
3348

@@ -37,8 +52,9 @@ $ sh -c "$(curl -sSfL https://release.anza.xyz/v2.1.0/install)"
3752
```
3853

3954
To show the installed versions of the tools
55+
4056
```bash
41-
$ olana --version
57+
$ solana --version
4258
solana-cli 2.1.0
4359

4460
$ rustc --version
@@ -49,61 +65,104 @@ anchor-cli 0.31.1
4965
```
5066

5167
To build (this will require at least 2GB disk space)
68+
5269
```bash
5370
$ anchor build
5471
```
5572

5673
To run the tests
74+
5775
```bash
5876
$ anchor test
5977
```
6078

61-
To generate Go bindings for program's IDL
62-
Development environments : Localnet
79+
To generate Go bindings for program's IDL Development environments : Localnet
80+
6381
```bash
6482
$ make generate-dev
6583
```
6684

6785
Production environments : Mainnet,Testnet
86+
6887
```bash
6988
$ make generate-prod
7089
```
7190

7291
# Authentication and Authorization
7392

74-
Anyone can deposit and remote invoke ZetaChain contracts.
75-
76-
Only ZetaChain TSS account can call `withdraw` on the program. The ZetaChain TSS account is a collection of Observer/Signers which uses ECDSA TSS (Threshold Signature Scheme) to sign outbound transactions. The TSS address will appear in this program a single ECDSA secp256k1 address; but it does not have a single private key, rather its private key consists of multiple key shares and they collectively sign a message in a KeySign MPC ceremony. The program authenticates via verifying the TSS signature and is authorized by ZetaChain to perform outbound transactions as part of ZetaChain cross-chain machinery.
77-
78-
The ZetaChain TSS is on ECDSA secp256k1 curve; But Solana native digital signature scheme is EdDSA Ed25519 curve. Therefore the program uses custom logic to verify the TSS ECDSA signature (like alternative authentication in smart contract wallet); the native transaction signer (fee payer on Solana) does not carry authorization and it's only used to build the transaction and pay tx fees. There are no restrictions on who the native transaction signer/fee payer is. The following code excerpt is for authenticating TSS signature in the contract itself, using the [Rust secp256k1 library bundled with solana](https://docs.rs/solana-program/latest/solana_program/secp256k1_recover/index.html): https://github.com/zeta-chain/protocol-contracts-solana/blob/01eeb9733a00b6e972de0578b0e07ebc5837ec54/programs/protocol-contracts-solana/src/lib.rs#L116-L121
79-
80-
The function `recover_eth_address` is implemented in the gateway program: https://github.com/zeta-chain/protocol-contracts-solana/blob/01eeb9733a00b6e972de0578b0e07ebc5837ec54/programs/protocol-contracts-solana/src/lib.rs#L180-L196
81-
82-
The TSS signature is a ECDSA secp256k1 signature; its public key therefore address (Ethereum compatible hashing from pubkey) is therefore verifiable using the `secp256k1_recover` function. Alternatively, Solana runtime also provides a program to provide this verification service via CPI; see [proposal 48](https://github.com/solana-foundation/solana-improvement-documents/blob/main/proposals/0048-native-program-for-secp256r1-sigverify.md) which might be more cost efficient.
83-
84-
In the instruction, the ECDSA signed message_hash must commit to the `nonce`, `amount`, and `to` address. See the check in these instructions like: https://github.com/zeta-chain/protocol-contracts-solana/blob/01eeb9733a00b6e972de0578b0e07ebc5837ec54/programs/protocol-contracts-solana/src/lib.rs#L110-L114 The commitment of `nonce` in the signature prevents replay of the TSS ECDSA signed message. Also (to be added in https://github.com/zeta-chain/protocol-contracts-solana/issues/6) a chain id of Solana should be added to the commitment of the message hash, so that the signature cannot be replayed on *other blockchains* that potentially uses similar authentication (say in TON).
85-
93+
Anyone can deposit and remote invoke ZetaChain contracts.
94+
95+
Only ZetaChain TSS account can call `withdraw` on the program. The ZetaChain TSS
96+
account is a collection of Observer/Signers which uses ECDSA TSS (Threshold
97+
Signature Scheme) to sign outbound transactions. The TSS address will appear in
98+
this program a single ECDSA secp256k1 address; but it does not have a single
99+
private key, rather its private key consists of multiple key shares and they
100+
collectively sign a message in a KeySign MPC ceremony. The program authenticates
101+
via verifying the TSS signature and is authorized by ZetaChain to perform
102+
outbound transactions as part of ZetaChain cross-chain machinery.
103+
104+
The ZetaChain TSS is on ECDSA secp256k1 curve; But Solana native digital
105+
signature scheme is EdDSA Ed25519 curve. Therefore the program uses custom logic
106+
to verify the TSS ECDSA signature (like alternative authentication in smart
107+
contract wallet); the native transaction signer (fee payer on Solana) does not
108+
carry authorization and it's only used to build the transaction and pay tx fees.
109+
There are no restrictions on who the native transaction signer/fee payer is. The
110+
following code excerpt is for authenticating TSS signature in the contract
111+
itself, using the [Rust secp256k1 library bundled with
112+
solana](https://docs.rs/solana-program/latest/solana_program/secp256k1_recover/index.html):
113+
https://github.com/zeta-chain/protocol-contracts-solana/blob/01eeb9733a00b6e972de0578b0e07ebc5837ec54/programs/protocol-contracts-solana/src/lib.rs#L116-L121
114+
115+
The function `recover_eth_address` is implemented in the gateway program:
116+
https://github.com/zeta-chain/protocol-contracts-solana/blob/01eeb9733a00b6e972de0578b0e07ebc5837ec54/programs/protocol-contracts-solana/src/lib.rs#L180-L196
117+
118+
The TSS signature is a ECDSA secp256k1 signature; its public key therefore
119+
address (Ethereum compatible hashing from pubkey) is therefore verifiable using
120+
the `secp256k1_recover` function. Alternatively, Solana runtime also provides a
121+
program to provide this verification service via CPI; see [proposal
122+
48](https://github.com/solana-foundation/solana-improvement-documents/blob/main/proposals/0048-native-program-for-secp256r1-sigverify.md)
123+
which might be more cost efficient.
124+
125+
In the instruction, the ECDSA signed message*hash must commit to the `nonce`,
126+
`amount`, and `to` address. See the check in these instructions like:
127+
https://github.com/zeta-chain/protocol-contracts-solana/blob/01eeb9733a00b6e972de0578b0e07ebc5837ec54/programs/protocol-contracts-solana/src/lib.rs#L110-L114
128+
The commitment of `nonce` in the signature prevents replay of the TSS ECDSA
129+
signed message. Also (to be added in
130+
https://github.com/zeta-chain/protocol-contracts-solana/issues/6) a chain id of
131+
Solana should be added to the commitment of the message hash, so that the
132+
signature cannot be replayed on \_other blockchains* that potentially uses
133+
similar authentication (say in TON).
86134

87135
# Relevant Account and Addresses
88136

89-
The Gateway program derives a PDA (Program Derived Address) with seeds `b"meta"` and canonical bump. This PDA account/address actually holds the SOL balance of the Gateway program. For SPL tokens, the program stores the SPL token in PDA derived ATAs. For each SPL token (different mint account), the program creates an ATA from the PDA and the Mint (standard way of deriving ATA in Solana SPL program).
137+
The Gateway program derives a PDA (Program Derived Address) with seeds `b"meta"`
138+
and canonical bump. This PDA account/address actually holds the SOL balance of
139+
the Gateway program. For SPL tokens, the program stores the SPL token in PDA
140+
derived ATAs. For each SPL token (different mint account), the program creates
141+
an ATA from the PDA and the Mint (standard way of deriving ATA in Solana SPL
142+
program).
90143

91-
The PDA account itself is a data account that holds Gateway program state, namely the following data types https://github.com/zeta-chain/protocol-contracts-solana/blob/01eeb9733a00b6e972de0578b0e07ebc5837ec54/programs/protocol-contracts-solana/src/lib.rs#L271-L275
144+
The PDA account itself is a data account that holds Gateway program state,
145+
namely the following data types
146+
https://github.com/zeta-chain/protocol-contracts-solana/blob/01eeb9733a00b6e972de0578b0e07ebc5837ec54/programs/protocol-contracts-solana/src/lib.rs#L271-L275
92147

93-
The `nonce` is incremented on each successful withdraw transaction, and it's used to prevent replay of signed ECDSA messages.
94-
The `tss_address` is the TSS address of ZetaChain (20Bytes, Ethereum style). `authority` is the one who can update the TSS address stored in PDA account.
95-
The `initialize` instruction sets nonce to 0.
148+
The `nonce` is incremented on each successful withdraw transaction, and it's
149+
used to prevent replay of signed ECDSA messages. The `tss_address` is the TSS
150+
address of ZetaChain (20Bytes, Ethereum style). `authority` is the one who can
151+
update the TSS address stored in PDA account. The `initialize` instruction sets
152+
nonce to 0.
96153

97154
# Troubleshooting
98155

99156
## MacOS error when running `anchor test` or `solana-test-validator`
100157

101158
If you see errors like
159+
102160
```
103161
Unable to get latest blockhash. Test validator does not look started. Check ".anchor/test-ledger/test-ledger-log.txt" for errors. Consider increasing [test.startup_wait] in Anchor.toml.
104162
```
105163

106-
or
164+
or
165+
107166
```bash
108167
% solana-test-validator --reset
109168
Ledger location: test-ledger
@@ -113,21 +172,24 @@ Error: failed to start validator: Failed to create ledger at test-ledger: io err
113172

114173
This is because the BSD tar program is not compatible with the GNU tar program.
115174

116-
To fix the issue: install GNU tar program using homebrew and export it's executable path in your `.zshrc` file:
175+
To fix the issue: install GNU tar program using homebrew and export it's
176+
executable path in your `.zshrc` file:
117177

118178
**Mac with Apple Silicon**
119179

120180
```bash
121181
brew install gnu-tar
122-
# Put this in ~/.zshrc
182+
# Put this in ~/.zshrc
123183
export PATH="/opt/homebrew/opt/gnu-tar/libexec/gnubin:$PATH"
124184
```
125185

126186
**Intel-based Mac**
127187

128188
```bash
129189
brew install gnu-tar
130-
# Put this in ~/.zshrc
190+
# Put this in ~/.zshrc
131191
export PATH="/usr/local/opt/gnu-tar/libexec/gnubin:$PATH"
132192
```
133-
see https://solana.stackexchange.com/questions/4499/blockstore-error-when-starting-solana-test-validator-on-macos-13-0-1/16319#16319
193+
194+
see
195+
https://solana.stackexchange.com/questions/4499/blockstore-error-when-starting-solana-test-validator-on-macos-13-0-1/16319#16319

dev/keypair/gateway-keypair.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[148,138,110,3,169,253,42,101,79,110,149,110,112,214,41,163,75,28,36,29,241,151,41,200,135,185,252,180,158,191,166,156,119,192,217,18,69,149,119,145,212,43,144,149,176,111,89,140,102,63,193,127,241,148,51,161,170,62,19,196,239,253,6,192]

0 commit comments

Comments
 (0)