Skip to content

Commit

Permalink
deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
dndll committed Mar 27, 2024
1 parent f4b00ae commit aa0b990
Show file tree
Hide file tree
Showing 40 changed files with 229 additions and 43 deletions.
2 changes: 0 additions & 2 deletions api/NEAR Light Client/.env.sample

This file was deleted.

5 changes: 0 additions & 5 deletions api/NEAR Light Client/bruno.json

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
meta {
name: Check Release Status
name: check-release
type: http
seq: 2
}
Expand Down Expand Up @@ -28,7 +28,7 @@ headers {
}

vars:pre-request {
release: 13
release: noop
}

assert {
Expand All @@ -37,18 +37,16 @@ assert {
}

script:pre-request {
let entrypoint = bru.getProcessEnv("ENTRYPOINT")
let release = bru.getEnvVar(`${entrypoint}_RELEASE_NUM_NEW`)
if (release != null && entrypoint != null) {
let release = bru.getProcessEnv(`CHECK_RELEASE_NUM`)
if (release != null) {
bru.setVar("release", release)
}
}

script:post-response {
let entrypoint = bru.getProcessEnv("ENTRYPOINT")
if (res.body.status == "success") {
bru.setEnvVar(`${entrypoint}_RELEASE_ID_OLD`, bru.getEnvVar(`${entrypoint}_RELEASE_ID`))
bru.setEnvVar(`${entrypoint}_RELEASE_NUM`, bru.getEnvVar(`${entrypoint}_RELEASE_NUM_NEW`))
bru.setEnvVar(`${entrypoint}_RELEASE_ID`, bru.getEnvVar(`${entrypoint}_RELEASE_ID_NEW`))
bru.setEnvVar(`${entrypoint}_RELEASE_NUM`, bru.getProcessEnv(`CHECK_RELEASE_NUM`))
bru.setEnvVar(`${entrypoint}_RELEASE_ID`, bru.getProcessEnv(`CHECK_RELEASE_ID`))
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
meta {
name: New Entrypoint
name: new-deployment
type: http
seq: 1
}

post {
url: {{succinctBaseUrl}}/release/new
body: text
auth: bearer
}

headers {
Expand All @@ -24,12 +23,12 @@ headers {
sec-fetch-site: same-origin
sec-gpc: 1
user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36
cookie: session={{succinctSession}}
content-type: text/plain;charset=UTF-8
cookie: session={{succinctSession}}
}

auth:bearer {
token: {{succinctAuthToken}}
token: {{succinctApiKey}}
}

body:text {
Expand All @@ -47,6 +46,10 @@ vars:pre-request {
entrypoint: fake
}

assert {
res.status: eq 200
}

script:pre-request {
let gitRef = bru.getProcessEnv("GIT_REF")
if (gitRef != null) {
Expand All @@ -56,16 +59,11 @@ script:pre-request {
if (entrypoint != null) {
bru.setVar("entrypoint", entrypoint)
}
bru.setVar("succinctSession", bru.getProcessEnv("SUCCINCT_SESSION"))
bru.setVar("succinctApiKey", bru.getProcessEnv("SUCCINCT_API_KEY"))
}

script:post-response {
let entrypoint = bru.getProcessEnv("ENTRYPOINT")
bru.setEnvVar(`${entrypoint}_RELEASE_ID_NEW`, res.body.release_id)
bru.setEnvVar(`${entrypoint}_RELEASE_NUM_NEW`, res.body.release_number)
bru.setVar(`${entrypoint}_RELEASE_ID_NEW`, res.body.release_id)
bru.setVar(`${entrypoint}_RELEASE_NUM_NEW`, res.body.release_number)
}

assert {
res.status: eq 200
bru.setVar(`CHECK_RELEASE_ID`, res.body.release_id)
bru.setVar(`CHECK_RELEASE_NUM`, res.body.release_number)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
meta {
name: Pull Verifying Key
name: pull-vk
type: http
seq: 4
}
Expand Down Expand Up @@ -28,7 +28,7 @@ headers {
}

vars:pre-request {
releaseId: c2829278-6849-4487-ba5f-96ce503837d5
releaseId: c2829278-6849-4487-ba5f-96ce503837d5
}

assert {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
meta {
name: Update name
name: update-name
type: http
seq: 3
}
Expand Down Expand Up @@ -43,14 +43,14 @@ assert {
}

script:pre-request {
let entrypoint = bru.getProcessEnv("ENTRYPOINT")
let releaseNum = bru.getEnvVar(`${entrypoint}_RELEASE_ID`)
if (releaseNum != null && entrypoint != null) {
let releaseNum = bru.getProcessEnv(`CHECK_RELEASE_ID`)
if (releaseNum != null) {
bru.setVar("releaseNum", releaseNum)
}

let version = bru.getProcessEnv("VERSION")
let version = bru.getEnvVar("VERSION")
if (version != null) {
bru.setVar("version", version)
}
bru.setVar("succinctSession", bru.getProcessEnv("SUCCINCT_SESSION"))
}
19 changes: 19 additions & 0 deletions bruno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"version": "1",
"name": "api",
"type": "collection",
"presets": {
"requestType": "http",
"requestUrl": "{{succinctBaseUrl}}"
},
"ignore": [
"bin",
"target",
".git",
"crates",
"build",
"nearx",
"vendor",
"wrapped"
]
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ vars {
operatorBaseUrl: http://0.0.0.0:3030
gitRef: 700edd24ac1666307f3f740e36bf4c5808c26e1b
}

vars:secret [
succinctAuthToken,
succinctApiKey,
succinctSession
]
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
nativeBuildInputs = with pkgs; [
bashInteractive
taplo
just
clang
cmake
openssl
Expand All @@ -43,7 +44,6 @@

vscode-extensions.vadimcn.vscode-lldb.adapter
rust-analyzer

];
buildInputs = with pkgs; [
(rustVersion.override { extensions = [ "rust-src" ]; })
Expand Down
121 changes: 121 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
set export
set dotenv-filename := ".env"
set dotenv-load

brunoc := "npx -y @usebruno/cli run"

# Deploy a succinct circuit
succinct-deploy $ENTRYPOINT $VERSION:
$(brunoc) "Succinct/Deploy/new-deployment.bru" --env testnet -o /tmp/{{ENTRYPOINT}}-deployment-v${{VERSION}}.json

succinct-check $ENTRYPOINT $VERSION:
$(brunoc) "Succinct/Deploy/check-deployment.bru" --env testnet -o /tmp/{{ENTRYPOINT}}-deployment-v${{VERSION}}.json

GIT_REF := env_var_or_default('GIT_REF', 'master')
VERSION := env_var_or_default('VERSION', 'dev')

BROADCAST := if env("BROADCAST", "") != "n" {"--broadcast "} else {""}
LEGACY := if env('LEGACY', "") != "" {"--legacy "} else {""}
VERIFIER := env('VERIFIER', 'etherscan')
VERIFY := if env('VERIFY', "") != "n" {"--verify " + VERIFIER} else {""}

ETH_RPC_URL := env('ETH_RPC_URL', 'https://rpc.sepolia.eth.gateway.fm')
CHAIN_ID := env('CHAIN_ID', '11155111')
ETH_PRIVATE_KEY := env_var('ETH_PRIVATE_KEY')
ETH_PUBLIC_KEY := env_var('ETH_PUBLIC_KEY')

forge-script SCRIPT TAIL *ARGS:
#!/usr/bin/env bash
echo {{SCRIPT}}
echo {{TAIL}}
cd ./nearx/contract && \
forge script {{SCRIPT}} \
--ffi \
--sender {{ETH_PUBLIC_KEY}} \
--rpc-url {{ETH_RPC_URL}} \
--private-key {{ETH_PRIVATE_KEY}} \
{{TAIL}} {{ARGS}} -vvvv
get-deployments OUTPUT:
echo "Getting deployments"
{{brunoc}} "api/succinct/Get Deployments.bru" --env testnet -o {{OUTPUT}}

filter-deployments INPUT NAME:
cat {{INPUT}} \
| jq '.results[0].response.data' | jq -r "[.[] | select(.chain_id == {{CHAIN_ID}})]" \
| jq -r ".[] | select((.edges.release.name | contains(\"{{VERSION}}\")) and (.edges.release.entrypoint | contains(\"{{NAME}}\")))"

init: (get-deployments "/tmp/deployments.json")
#!/usr/bin/env bash
set -euxo pipefail
S_INFO=$(just filter-deployments /tmp/deployments.json Sync)
echo $S_INFO | jq -r .gateway
echo $S_INFO | jq -r .function_id

just filter-deployments /tmp/deployments.json Verify | jq -r .function_id

deploy: (forge-script "Deploy" BROADCAST + VERIFY + LEGACY)

initialise: init
forge-script Initialise

update-params: (forge-script "UpdateParams" BROADCAST + LEGACY)

upgrade: (forge-script "Upgrade" BROADCAST + VERIFY + LEGACY)

request-sync: (forge-script "RequestSync" BROADCAST + LEGACY)

request-verify: (forge-script "RequestVerify" BROADCAST + LEGACY)

call-brunoc REQUEST:
{{brunoc}} "api/succinct/deploy/{{REQUEST}}.bru" --env testnet -o /tmp/{{REQUEST}}-v{{VERSION}}.json

check $CHECK_RELEASE_NUM:
{{brunoc}} "api/succinct/deploy/check.bru" --env testnet -o /tmp/check-v{{VERSION}}.json

wait-for-success ENTRYPOINT:
#!/usr/bin/env bash

CHECK_RELEASE_NUM=$(cat /tmp/new-deployment-v{{VERSION}}.json | jq -r ".results[0].response.data.release_number")
CHECK_RELEASE_ID=$(cat /tmp/new-deployment-v{{VERSION}}.json | jq -r ".results[0].response.data.release_id")

for ((count=0; count<20; count++)); do
just check $CHECK_RELEASE_NUM
if [ $? -ne 0 ]; then
echo "non zero exit code: $?, trying in 30s"
sleep 30s
else
echo "success"
break
fi
done

# TODO: update name
update-release-name $ENTRYPOINT:
#!/usr/bin/env bash
export CHECK_RELEASE_ID=$(echo `just filter-deployments /tmp/deployments.json {{ENTRYPOINT}}` | jq -r .edges.release.id)
{{brunoc}} "api/succinct/deploy/update-name.bru" --env testnet -o /tmp/update-release-name-v{{VERSION}}.json
update-current-name $ENTRYPOINT:
#!/usr/bin/env bash
export CHECK_RELEASE_ID=$(echo `just filter-deployments /tmp/deployments.json {{ENTRYPOINT}}` | jq -r .edges.release.id)
export VERSION=old
echo $VERSION
{{brunoc}} "api/succinct/deploy/update-name.bru" --env-var VERSION=$VERSION --env testnet -o /tmp/update-current-name-vold.json || exit 0
get-verifier OUTPUT:
cat {{OUTPUT}} | jq -r '.results[].response.data.bytecode'

release-dev $ENTRYPOINT $GIT_REF:
#!/usr/bin/env bash
set -euxo pipefail
just call-brunoc "new-deployment"
just update-current-name {{ENTRYPOINT}}
just wait-for-success {{ENTRYPOINT}}
just update-release-name {{ENTRYPOINT}}
export FUNCTION_VERIFIER=`just get-verifier /tmp/check-v{{VERSION}}.json`
FUNCTION_VERIFIER=$FUNCTION_VERIFIER just forge-script "DeployAndRegisterFunction" ""
19 changes: 14 additions & 5 deletions nearx/contract/script/DeployAndRegisterVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,32 @@ pragma solidity ^0.8.0;
import "forge-std/Script.sol";
import "forge-std/Vm.sol";
import "forge-std/console.sol";
import {ISuccinctGateway} from "../../src/SuccinctGateway.sol";
import {FunctionVerifier} from "./FunctionVerifier.sol";

interface ISuccinctGateway {
function deployAndRegisterFunction(
address _owner,
bytes memory _bytecode,
bytes32 _salt
) external returns (bytes32, address);
}

//import {FunctionVerifier} from "./FunctionVerifier.sol";

contract DeployAndRegisterFunction is Script {
function run() external returns (bytes32, address) {
vm.startBroadcast();

bytes memory bytecode = type(FunctionVerifier).creationCode;
bytes memory bytecode = vm.envBytes("FUNCTION_VERIFIER");
//bytes memory bytecode = type(FunctionVerifier).creationCode;

address GATEWAY = vm.envAddress("GATEWAY_ID");
address GATEWAY = vm.envAddress("SUCCINCT_GATEWAY_ID");
console.logAddress(GATEWAY);

bytes32 SALT = vm.envBytes32("CREATE2_SALT");

address OWNER = msg.sender;

(bytes32 functionId, address verifier) = SuccinctGateway(GATEWAY)
(bytes32 functionId, address verifier) = ISuccinctGateway(GATEWAY)
.deployAndRegisterFunction(OWNER, bytecode, SALT);

return (functionId, verifier);
Expand Down
Loading

0 comments on commit aa0b990

Please sign in to comment.