Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
ltfschoen committed Jan 2, 2025
1 parent 6211074 commit 5a399b9
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 34 deletions.
16 changes: 11 additions & 5 deletions _SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ ssh root@172.105.184.209
* $PROJECT_ROOT/packages/relayer/SecretPath/TNLS-Relayers/.env
* Development
* Create a new Keplar Wallet that must use Google to generate an associated private key.
* Add a value for `secret-private-key` that you obtain from creating a new Keplar Wallet that must use Google to generate an associated private key, and exclude the '0x' prefix, that is associated with an address (e.g. secret1glfedwlusunwly7q05umghzwl6nf2vj6wr38fg)
* Add for Ethereum Development Node the private key into `ethereum-private-key = XXXXX` of the .env file $PROJECT_ROOT/packages/secret-contracts-scripts/.env. IMPORTANT: Exclude the leading `0x`
* Add a value for `secret-private-key` that you obtain from creating a new Keplar Wallet that must use Google to generate an associated private key, that is associated with an address (e.g. secret1glfedwlusunwly7q05umghzwl6nf2vj6wr38fg)
* Add for Ethereum Development Node the private key into `ethereum-private-key = XXXXX` of the .env file to be the same as that used in $PROJECT_ROOT/packages/secret-contracts-scripts/.env. for `ETH_DEVELOPMENT_PRIVATE_KEY`. IMPORTANT: Exclude the leading `0x`.
* Testnet
* Add for Ethereum Sepolia the private key into `ethereum-private-key = XXXXX` of the .env file to be the same as that used in $PROJECT_ROOT/packages/secret-contracts-scripts/.env for `ETH_TESTNET_PRIVATE_KEY`
* IMPORTANT: Exclude the leading `0x`
* IMPORTANT: Exclude the leading `0x`.
* $PROJECT_ROOT/packages/relayer/SecretPath/TNLS-Relayers/config.yml
* Check there is a `chain_id` and `api_endpoint` for both an Ethereum Network and a Secret Network, that should both be for development, testing, or mainnet usage. This should already be pre-configured.

Expand All @@ -179,8 +179,10 @@ Continue with [Run Services](#run-services).

* Run the following to start the Secret Development Node docker container, the Ethereum Development Node systemd service, and the Relayer systemd service.
```bash
export PROJECT_ROOT="/root/nunya"
export USE_NETWORK="localhost" # alternatively "testnet" or "mainnet"
cd $PROJECT_ROOT
$PROJECT_ROOT/scripts/run.sh $PROJECT_ROOT $USE_NETWORK | tee $PROJECT_ROOT/run.log
$PROJECT_ROOT/scripts/run.sh | tee $PROJECT_ROOT/run.log
```
* Note: If you modified your custom Secret Gateway code and the CODE_HASH changes, the script automatically update the `code_hash` of the Relay in the relevant Gitsubmodule to match it.
* Wait. The script outputs "Finished loading" when finished
Expand Down Expand Up @@ -244,7 +246,7 @@ Relayer->>EVM Gateway Contract: Forward response to `postExecution()`
EVM Gateway Contract-->>Nunya EVM Contract: Forward to `fulfilledSecretContractPubkeyCallback()`
```

* TODO: See [_SPECIFICATION](./_SPECIFICATION.md) and [_DEMO_AND_VIDEO](./_DEMO_AND_VIDEO.md) and Github Issues for additional features that need to be added.
* TODO: See [_DEV_DEEPDIVE](./DEV_DEEPDIVE.md) and [_SPECIFICATION](./_SPECIFICATION.md) and [_DEMO_AND_VIDEO](./_DEMO_AND_VIDEO.md) and Github Issues for additional features that need to be added.

#### Queries

Expand Down Expand Up @@ -357,6 +359,10 @@ Check use of consistent versions across the codebase (e.g. `v1.15.0-beta.19`).

This means you are likely using the wrong Node.js version, so just change to the project root directory and run `nvm use` in that terminal tab to use the version specified in the .nvmrc file.

### Error `failed to execute message; message index: 0: Execution error: Error during static Wasm validation: Wasm bytecode could not be deserialized. Deserialization error: "Invalid table reference (128)": create contract failed` or `failed to execute message; message index: 0: Execution error: Error during static Wasm validation: Wasm bytecode could not be deserialized. Deserialization error: "I/O Error: UnexpectedEof": create contract failed`

This error may occur if you try to upload the Secret contracts using `make build` instead of the optimised build using `make build-mainnet-reproducible`.

### Unable to upload code to Secret Network using `await secretjs.tx.compute.storeCode`

Check if Beta version of secretjs is necessary incase the Secret Testnet is being upgraded or change to a different version. Update the secretjs dependency in $PROJECT_ROOT/packages/secret-contracts-scripts/package.json to use a version from https://github.com/scrtlabs/secret.js/tags that both uploads and instantiates (e.g. v1.15.0-beta.19) by asking the Secret Network team.
Expand Down
12 changes: 6 additions & 6 deletions deployed.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@
"endpoint": "http://172.105.184.209:1317",
"secretNunya": {
"nunyaContractCodeId": "2",
"nunyaContractCodeHash": "0e1904c8f258b365d24865041ab51de62fdbf515d15e8fe785774662201c809a",
"nunyaContractCodeHash": "57f4f72804e180100c7108282fc46fa6275bee92829a3faa9e18526c9105948e",
"nunyaContractAddress": "secret1gyruqan6yxf0q423t8z5zce3x7np35uw8s8wqc"
},
"secretGateway": {
"gatewayContractCodeId": "2",
"gatewayContractAddress": "secret1gyruqan6yxf0q423t8z5zce3x7np35uw8s8wqc",
"gatewayContractCodeHash": "28e460006f968e69d48797832c22a564c3077e170a63c772bcc077f099da14ba",
"gatewayContractCodeId": "1",
"gatewayContractAddress": "secret1mfk7n6mc2cg6lznujmeckdh4x0a5ezf6hx6y8q",
"gatewayContractCodeHash": "be3db4b4c42d33300eee7801769a4176ed3046f23c08812fc2a85bc76075e1d5",
"gatewayContractAdminAddress": "secret1glfedwlusunwly7q05umghzwl6nf2vj6wr38fg",
"gatewayContractPublicKey": "0x041401d96329bc48ec810b3ca8140b419c0ab6b820a0fb0775e2bc5234d37f8da0fea791b1d14a70347d9e2ca1b025a94b3182ee32f7761de31176dfdc979a8fa0",
"gatewayContractEncryptionKeyForChaChaPoly1305": "AhQB2WMpvEjsgQs8qBQLQZwKtrggoPsHdeK8UjTTf42g"
"gatewayContractPublicKey": "0x04509cae738e3e67ef99924e300f44cda07c913a4c5c43729d9935465a8174126ab69f0813749cfe75a61602783e7cdc50f95f7ca47086bb6551e2a9760a6bda98",
"gatewayContractEncryptionKeyForChaChaPoly1305": "AlCcrnOOPmfvmZJOMA9EzaB8kTpMXENynZk1RlqBdBJq"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/relayer/SecretPath
8 changes: 7 additions & 1 deletion packages/secret-contracts-scripts/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ let initialNetworkSettings = {
// nunyaContractCodeHash: "", // only know after upload
// nunyaContractAddress: "", // only know after instantiate
nunyaContractWasmPath: "contract.wasm.gz",
nunyaContractWasmPathOptimized: "secret_evm_storage.wasm.gz"
},
// https://docs.scrt.network/secret-network-documentation/confidential-computing-layer/ethereum-evm-developer-toolkit/supported-networks/secret-gateway/secretpath-mainnet-secret-4-contracts
secretGateway: {
Expand All @@ -52,6 +53,7 @@ let initialNetworkSettings = {
// gatewayContractPublicKey: "0x04a0d632acd0d2f5da02fc385ea30a8deab4d5639d1a821a3a552625ad0f1759d0d2e80ca3adb236d90caf1b12e0ddf3a351c5729b5e00505472dca6fed5c31e2a",
// gatewayContractEncryptionKeyForChaChaPoly1305: "AqDWMqzQ0vXaAvw4XqMKjeq01WOdGoIaOlUmJa0PF1nQ",
gatewayContractWasmPath: "secret-gateway-contract.wasm.gz",
gatewayContractWasmPathOptimized: "secret_gateway.wasm.gz",
}
},
testnet: {
Expand All @@ -64,6 +66,7 @@ let initialNetworkSettings = {
// nunyaContractCodeHash: "b44049cbf187939df9f9857905197ecbc06e99702b3332b12cb6d968f39d88b2", // only know after upload
// nunyaContractAddress: "secret1h09whd3z8s9ms66mavd9rjm8r2rpew2trm0nkp", // only know after instantiate
nunyaContractWasmPath: "contract.wasm.gz",
nunyaContractWasmPathOptimized: "secret_evm_storage.wasm.gz"
},
// https://docs.scrt.network/secret-network-documentation/confidential-computing-layer/ethereum-evm-developer-toolkit/supported-networks/secret-gateway/secretpath-testnet-pulsar-3-contracts
secretGateway: {
Expand All @@ -74,18 +77,20 @@ let initialNetworkSettings = {
// gatewayContractPublicKey: "0x046d0aac3ef10e69055e934ca899f508ba516832dc74aa4ed4d741052ed5a568774d99d3bfed641a7935ae73aac8e34938db747c2f0e8b2aa95c25d069a575cc8b",
// gatewayContractEncryptionKeyForChaChaPoly1305: "A20KrD7xDmkFXpNMqJn1CLpRaDLcdKpO1NdBBS7VpWh3",
gatewayContractWasmPath: "secret-gateway-contract.wasm.gz",
gatewayContractWasmPathOptimized: "secret_gateway.wasm.gz",
}
},
localhost: {
walletMnemonic: process.env.SECRET_DEVELOPMENT_MNEMONIC,
isOptimizedContractWasm: false,
isOptimizedContractWasm: true,
chainId: "secretdev-1",
endpoint: process.env.SECRET_DEVELOPMENT_ENDPOINT,
secretNunya: {
// nunyaContractCodeId: "", // only know after upload
// nunyaContractCodeHash: "", // only know after upload
// nunyaContractAddress: "", // only know after instantiate
nunyaContractWasmPath: "contract.wasm.gz",
nunyaContractWasmPathOptimized: "secret_evm_storage.wasm.gz"
},
secretGateway: {
// IMPORTANT: Updated in deployed.json after deployment instead of here that only serves inputs
Expand All @@ -106,6 +111,7 @@ let initialNetworkSettings = {
// Obtain from running `yarn run secret:querySecretGatewayPubkey`
// gatewayContractEncryptionKeyForChaChaPoly1305: "",
gatewayContractWasmPath: "secret-gateway-contract.wasm.gz",
gatewayContractWasmPathOptimized: "secret_gateway.wasm.gz",
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function main () {
}

const isLocal = config.networkSettings.secret.network == "localhost";
const { walletMnemonic, isOptimizedContractWasm, secretNunya: { nunyaContractWasmPath }, secretGateway: { gatewayContractAdminAddress, gatewayContractCodeId, gatewayContractCodeHash, gatewayContractWasmPath }, chainId: secretChainId, endpoint: secretEndpoint } =
const { walletMnemonic, isOptimizedContractWasm, secretNunya: { nunyaContractWasmPath }, secretGateway: { gatewayContractAdminAddress, gatewayContractCodeId, gatewayContractCodeHash, gatewayContractWasmPath, gatewayContractWasmPathOptimized }, chainId: secretChainId, endpoint: secretEndpoint } =
isLocal == false
? config.networkSettings.secret.testnet
: config.networkSettings.secret.localhost;
Expand All @@ -34,11 +34,11 @@ async function main () {

const rootPath = path.join(__dirname, '../../../'); // relative to ./dist
console.log('rootPath', rootPath)
// const contract_wasm: any = fs.readFileSync(`${rootPath}packages/secret-contracts/nunya-contract/${nunyaContractWasmPath}`);
// Optimised nunya-contract
// const contract_wasm: any = fs.readFileSync(`${rootPath}packages/secret-contracts/nunya-contract/${isOptimizedContractWasm ? "optimized-wasm/" : ""}${nunyaContractWasmPath}`);
const secret_gateway_contract_wasm: any = fs.readFileSync(`${rootPath}packages/secret-contracts/secret-gateway/${isOptimizedContractWasm ? "optimized-wasm/" : ""}${gatewayContractWasmPath}`);
const secretGatewayContractWASMPath = `${rootPath}packages/secret-contracts/secret-gateway/${isOptimizedContractWasm ? "optimized-wasm/" + gatewayContractWasmPathOptimized : gatewayContractWasmPath}`;
console.log('secretGatewayContractWASMPath: ', secretGatewayContractWASMPath);
const secret_gateway_contract_wasm: any = fs.readFileSync(secretGatewayContractWASMPath);
// console.log('secret_gateway_contract_wasm: ', secret_gateway_contract_wasm);

const secretjs = new SecretNetworkClient({
chainId: secretChainId,
url: secretEndpoint || "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async function main () {
} else {
throw new Error(`Unsupported Secret network.`)
}
const { walletMnemonic, isOptimizedContractWasm, secretNunya: { nunyaContractWasmPath }, chainId: secretChainId, endpoint: secretEndpoint } = varsSecret;
const { walletMnemonic, isOptimizedContractWasm, secretNunya: { nunyaContractWasmPath, nunyaContractWasmPathOptimized }, chainId: secretChainId, endpoint: secretEndpoint } = varsSecret;

// must be all true or all false other
const arrIsLocal = [isLocalSecretInit, isLocalSecretDeployed, isLocalEvm];
Expand All @@ -80,10 +80,10 @@ async function main () {

const rootPath = path.join(__dirname, '../../../'); // relative to ./dist
console.log('rootPath', rootPath)
// const contract_wasm: any = fs.readFileSync(`${rootPath}packages/secret-contracts/nunya-contract/${nunyaContractWasmPath}`);
// Optimised nunya-contract
const contract_wasm: any = fs.readFileSync(`${rootPath}packages/secret-contracts/nunya-contract/${isOptimizedContractWasm ? "optimized-wasm/" : ""}${nunyaContractWasmPath}`);
console.log('contract_wasm: ', contract_wasm);
const contractWasmPath = `${rootPath}packages/secret-contracts/nunya-contract/${isOptimizedContractWasm ? "optimized-wasm/" + nunyaContractWasmPathOptimized : nunyaContractWasmPath}`;
console.log('contractWasmPath: ', contractWasmPath);
const contract_wasm: any = fs.readFileSync(contractWasmPath);
// console.log('contract_wasm: ', contract_wasm);
// Convert from Bytes (Uint8Array) to Base64
const gatewayContractPublicKeyBase64 = Buffer.from(gatewayContractPublicKey.substring(2), "hex").toString("base64");
console.log('gatewayContractPublicKeyBase64: ', gatewayContractPublicKeyBase64);
Expand All @@ -93,6 +93,7 @@ async function main () {
wallet: wallet,
walletAddress: wallet.address,
});
console.log('secretEndpoint: ', secretEndpoint);
// console.log('secretjs: ', secretjs);

const { balance } = await secretjs.query.bank.balance({
Expand Down
7 changes: 7 additions & 0 deletions packages/secret-contracts/secret-gateway/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ start-server: # CTRL+C to stop
-v $$(pwd):/root/code \
--name secretdev ghcr.io/scrtlabs/localsecret:v1.15.0-beta.19

.PHONY: start-server-daemon
start-server-daemon: # CTRL+C to stop
docker run -it -d --rm \
-p 9091:9091 -p 26657:26657 -p 26656:26656 -p 1317:1317 -p 5000:5000 \
-v $$(pwd):/root/code \
--name secretdev ghcr.io/scrtlabs/localsecret:v1.15.0-beta.19

.PHONY: copy-secret-gateway-contract-local
copy-secret-gateway-contract-local:
sudo docker cp secret-gateway-contract.wasm secretdev:/root/code/secret-gateway-contract.wasm
Expand Down
Binary file not shown.
26 changes: 16 additions & 10 deletions scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

# Part 1 - Secret Network

PROJECT_ROOT=$1
USE_NETWORK=$2
echo -e "PROJECT_ROOT: $PROJECT_ROOT"
echo -e "USE_NETWORK: $USE_NETWORK"
cd $PROJECT_ROOT
Expand Down Expand Up @@ -244,15 +242,23 @@ yarn run secret:setEVMGatewayAddress
# Warning: If you only run `make build-mainnet` then you will get this error https://github.com/svub/nunya/issues/8 when deploying.
#
# Note: Use `make build-mainnet-reproducible` for both Testnet and Mainnet, NOT just Mainnet
if [ $USE_NETWORK == "localhost" ]; then
cd $PROJECT_ROOT/packages/secret-contracts/nunya-contract
make clean
make build
#
# TODO: Read from deployed.json using `$CHOSEN_NETWORK` to determine whether `isOptimizedContractWasm`
# is true or false and based on that decide whether to perform optimized build or not.
# Currently `isOptimizedContractWasm` is only in config.ts, so we need to migrate contents of
# config.ts to deployed.json sooner since we can read that from here, instead of using `$USE_NETWORK`,
# since we want to use .env files, not passing environment variables from command line
if [[ $USE_NETWORK == "localhost" || $USE_NETWORK == "testnet" || $USE_NETWORK == "mainnet" ]]; then
# unoptimized may cause issues

# cd $PROJECT_ROOT/packages/secret-contracts/nunya-contract
# make clean
# make build

# cd $PROJECT_ROOT/packages/secret-contracts/secret-gateway
# make clean
# make build

cd $PROJECT_ROOT/packages/secret-contracts/secret-gateway
make clean
make build
elif [ $CHOSEN_NETWORK == "testnet" || $CHOSEN_NETWORK == "mainnet" ]; then
# Remove any old Docker containers, if necessary, that were used to compile the Testnet or Mainnet code
docker rmi sco

Expand Down

0 comments on commit 5a399b9

Please sign in to comment.