Skip to content
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

StargateQuery (and more) #1073

Merged
merged 32 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
214101a
Wire up StargateQuery
assafmo Aug 17, 2022
a359a8e
Fix debugger for go-tests
assafmo Aug 22, 2022
6061640
Add integration tests, enable stargate feature
assafmo Aug 22, 2022
84174bf
Add integration tests to the CI
assafmo Aug 22, 2022
8755a43
Make StargateMsg work (with tests)
assafmo Aug 22, 2022
40c02fe
Implement all missing v1 QueryPlugins
assafmo Aug 22, 2022
9f55427
Continue fixing the v1 querier
assafmo Aug 22, 2022
8b5ff3d
Fix StargateQuery paths
assafmo Aug 22, 2022
2adda1d
Remove unused code
assafmo Aug 23, 2022
dad0b26
LocalSecret: expose LOG_LEVEL as env var
assafmo Aug 23, 2022
ff4250a
StargateQuery test
assafmo Aug 23, 2022
be350cc
Implement all queries for v1 integration tests contract
assafmo Aug 23, 2022
0725def
Integration tests: finish implementing v1 contract query
assafmo Aug 23, 2022
3849efb
Verify EIP191 inside the enclave
assafmo Aug 23, 2022
9f333d3
Increase `make go-tests` timeout 20m->40m
assafmo Aug 23, 2022
38c225a
Fix go tests for StargateMsg (Add compute MsgServer)
assafmo Aug 23, 2022
6585e96
Fix Integration-Tests CI
assafmo Aug 23, 2022
bd1f396
Clippy
assafmo Aug 23, 2022
a58ecae
Clippy
assafmo Aug 23, 2022
aa542b2
Fix CI Integration-Tests?
assafmo Aug 23, 2022
0ec3497
Parse protos on reply to extract reply params
assafmo Aug 24, 2022
38d7c51
Compute MsgServer refactor
assafmo Aug 24, 2022
c397862
Use v0.10 MsgRouter for MsgExec & MsgInit
assafmo Aug 24, 2022
eae764e
Try debugging Integration-Tests CI
assafmo Aug 24, 2022
2dbedca
Try debugging Integration-Tests CI
assafmo Aug 24, 2022
9157ddf
CI Go-Tests increase timeout 20m->40m
assafmo Aug 24, 2022
1973545
Merge branch 'cosmwasm-v1' into stargate-query
assafmo Aug 24, 2022
898e375
Fix bug from previous merge
assafmo Aug 24, 2022
229bc81
v1 sanity contract: make ExecuteMsg::GasMeter more efficient because …
assafmo Aug 24, 2022
76b2562
rustfmt v1 sanity contract
assafmo Aug 24, 2022
bb335e0
Fix TestCallbackSanity for wasmd v0.28
assafmo Aug 24, 2022
5185c9a
Fix all go-test that relied on events being ordered
assafmo Aug 24, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ jobs:
echo "not_a_key" > ias_keys/develop/spid.txt
echo "not_a_key" > ias_keys/develop/api_key.txt
LOG_LEVEL=ERROR go test -v ./x/compute/client/...
LOG_LEVEL=ERROR go test -p 1 -timeout 20m -v ./x/compute/internal/...
LOG_LEVEL=ERROR go test -p 1 -timeout 40m -v ./x/compute/internal/...

Clippy:
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -294,15 +294,21 @@ jobs:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Build docker testnet
- name: Build LocalSecret
run: |
echo not_a_key | tee {api_key,spid}.txt
DOCKER_TAG=v0.0.0 make build-localsecret
- name: Run integration tests
run: |
cd integration-tests
yarn
docker run -d -p 9091:9091 --name localsecret ghcr.io/scrtlabs/localsecret:v0.0.0
sleep 30
docker logs localsecret
yarn test
- name: Run secret.js tests
run: |
git clone --depth 1 https://github.com/scrtlabs/secret.js
# Copy v1 contract to tests directory
cp ./target/wasm32-unknown-unknown/release/v1_sanity_contract.wasm ./secret.js/test/test_contract_v1.wasm
cd secret.js
# Use the docker images that we built just a few steps above
perl -i -pe 's/localsecret:.+?"/localsecret:v0.0.0"/' ./test/*
Expand Down
1 change: 1 addition & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"request": "launch",
"mode": "debug",
"program": "${file}",
"cwd": "${workspaceFolder}/x/compute/internal/keeper",
"env": { "SGX_MODE": "SW", "RUST_BACKTRACE": "1" },
"args": [
"test",
Expand Down
12 changes: 7 additions & 5 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"rust-analyzer.linkedProjects": [
"./cosmwasm/Cargo.toml",
"./cosmwasm/enclaves/Cargo.toml",
"./x/compute/internal/keeper/testdata/v1-sanity-contract/Cargo.toml",
"./x/compute/internal/keeper/testdata/test-contract/Cargo.toml"
"cosmwasm/Cargo.toml",
"cosmwasm/enclaves/Cargo.toml",
"x/compute/internal/keeper/testdata/v1-sanity-contract/Cargo.toml",
"x/compute/internal/keeper/testdata/test-contract/Cargo.toml",
"integration-tests/contract-v1/Cargo.toml",
"integration-tests/contract-v0.10/Cargo.toml",
"go-cosmwasm/Cargo.toml"
],
"rust-analyzer.diagnostics.experimental.enable": true,
"rust-analyzer.rustfmt.rangeFormatting.enable": true,
Expand All @@ -20,7 +23,6 @@
"go.useLanguageServer": true,
"go.lintTool": "golangci-lint",
"go.lintOnSave": "workspace",
"go.buildTags": "secretcli",
"gopls": {
"formatting.gofumpt": true
},
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ go-tests: build-test-contract
cp ./cosmwasm/enclaves/execute/librust_cosmwasm_enclave.signed.so ./x/compute/internal/keeper
rm -rf ./x/compute/internal/keeper/.sgx_secrets
mkdir -p ./x/compute/internal/keeper/.sgx_secrets
GOMAXPROCS=8 SGX_MODE=SW SCRT_SGX_STORAGE='./' go test -failfast -timeout 2400s -v ./x/compute/internal/... $(GO_TEST_ARGS)
GOMAXPROCS=8 SGX_MODE=SW SCRT_SGX_STORAGE='./' go test -failfast -timeout 40m -v ./x/compute/internal/... $(GO_TEST_ARGS)

go-tests-hw: build-test-contract
# empty BUILD_PROFILE means debug mode which compiles faster
Expand Down
7 changes: 4 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ func NewSecretNetworkApp(
AddRoute(ibcclienttypes.RouterKey, ibcclient.NewClientProposalHandler(app.ibcKeeper.ClientKeeper))

// Just re-use the full router - do we want to limit this more?
computeRouter := app.Router()
regRouter := app.Router()

// Replace with bootstrap flag when we figure out how to test properly and everything works
Expand All @@ -419,7 +418,7 @@ func NewSecretNetworkApp(

// The last arguments can contain custom message handlers, and custom query handlers,
// if we want to allow any custom callbacks
supportedFeatures := "staking"
supportedFeatures := "staking,stargate,ibc3"

app.computeKeeper = compute.NewKeeper(
appCodec,
Expand All @@ -435,7 +434,9 @@ func NewSecretNetworkApp(
app.ibcKeeper.PortKeeper,
app.transferKeeper,
app.ibcKeeper.ChannelKeeper,
computeRouter,
app.Router(),
app.MsgServiceRouter(),
app.GRPCQueryRouter(),
computeDir,
computeConfig,
supportedFeatures,
Expand Down
21 changes: 21 additions & 0 deletions cosmwasm/enclaves/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub fn redact_custom_events(reply: &mut Reply) {
}
}

if new_ev.attributes.len() > 0 {
if !new_ev.attributes.is_empty() {
events.push(new_ev);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub fn extract_contract_key(env: &Env) -> Result<[u8; CONTRACT_KEY_LENGTH], Encl
let contract_key =
base64::decode(env.contract_key.as_ref().unwrap().as_bytes()).map_err(|err| {
warn!(
"got an error while trying to deserialize output bytes into json {:?}: {}",
"got an error while trying to decode contract key {:?}: {}",
env, err
);
EnclaveError::FailedContractAuthentication
Expand Down Expand Up @@ -243,6 +243,7 @@ pub fn verify_params(
.verify_bytes(
sig_info.sign_bytes.as_slice(),
sig_info.signature.as_slice(),
sig_info.sign_mode,
)
.map_err(|err| {
warn!("Signature verification failed: {:?}", err);
Expand Down Expand Up @@ -290,7 +291,7 @@ fn get_signer_and_messages(

Ok((sender_public_key.clone(), sign_doc.body.messages))
}
SIGN_MODE_LEGACY_AMINO_JSON => {
SIGN_MODE_LEGACY_AMINO_JSON | SIGN_MODE_EIP_191 => {
use protobuf::well_known_types::Any as AnyProto;
use protobuf::Message;

Expand Down
2 changes: 1 addition & 1 deletion cosmwasm/enclaves/shared/contract-engine/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ pub fn encrypt_output(
Some(_) => {
let mut events: Vec<Event> = vec![];

if ok.attributes.len() > 0 {
if !ok.attributes.is_empty() {
events.push(Event {
ty: "wasm".to_string(),
attributes: ok.attributes.clone(),
Expand Down
3 changes: 3 additions & 0 deletions cosmwasm/enclaves/shared/cosmos-proto/src/tx/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,7 @@ pub enum SignMode {
SIGN_MODE_DIRECT = 1,
SIGN_MODE_TEXTUAL = 2,
SIGN_MODE_LEGACY_AMINO_JSON = 127,
SIGN_MODE_EIP_191 = 191
}

impl ::protobuf::ProtobufEnum for SignMode {
Expand All @@ -1169,6 +1170,7 @@ impl ::protobuf::ProtobufEnum for SignMode {
1 => ::std::option::Option::Some(SignMode::SIGN_MODE_DIRECT),
2 => ::std::option::Option::Some(SignMode::SIGN_MODE_TEXTUAL),
127 => ::std::option::Option::Some(SignMode::SIGN_MODE_LEGACY_AMINO_JSON),
191 => ::std::option::Option::Some(SignMode::SIGN_MODE_EIP_191),
_ => ::std::option::Option::None
}
}
Expand All @@ -1179,6 +1181,7 @@ impl ::protobuf::ProtobufEnum for SignMode {
SignMode::SIGN_MODE_DIRECT,
SignMode::SIGN_MODE_TEXTUAL,
SignMode::SIGN_MODE_LEGACY_AMINO_JSON,
SignMode::SIGN_MODE_EIP_191,
];
values
}
Expand Down
11 changes: 8 additions & 3 deletions cosmwasm/enclaves/shared/cosmos-types/src/multisig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::types::CosmosPubKey;

use enclave_crypto::traits::VerifyingKey;

use cosmos_proto::crypto::multisig::multisig::MultiSignature;
use cosmos_proto::{crypto::multisig::multisig::MultiSignature, tx::signing::SignMode};

use super::traits::CosmosAminoPubkey;

Expand Down Expand Up @@ -94,7 +94,12 @@ impl CosmosAminoPubkey for MultisigThresholdPubKey {
}

impl VerifyingKey for MultisigThresholdPubKey {
fn verify_bytes(&self, bytes: &[u8], sig: &[u8]) -> Result<(), CryptoError> {
fn verify_bytes(
&self,
bytes: &[u8],
sig: &[u8],
sign_mode: SignMode,
) -> Result<(), CryptoError> {
debug!("verifying multisig");
trace!("Sign bytes are: {:?}", bytes);
let signatures = decode_multisig_signature(sig)?;
Expand Down Expand Up @@ -122,7 +127,7 @@ impl VerifyingKey for MultisigThresholdPubKey {
for (i, current_signer) in signers.iter().enumerate() {
trace!("Checking pubkey: {:?}", current_signer);
// This technically support that one of the multisig signers is a multisig itself
let result = current_signer.verify_bytes(bytes, current_sig);
let result = current_signer.verify_bytes(bytes, current_sig, sign_mode);

if result.is_ok() {
signer_pos = Some(i);
Expand Down
13 changes: 10 additions & 3 deletions cosmwasm/enclaves/shared/cosmos-types/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use log::*;

use enclave_ffi_types::EnclaveError;
use proto::tx::signing::SignMode;
use protobuf::Message;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -120,10 +121,15 @@ impl CosmosAminoPubkey for CosmosPubKey {
}

impl VerifyingKey for CosmosPubKey {
fn verify_bytes(&self, bytes: &[u8], sig: &[u8]) -> Result<(), CryptoError> {
fn verify_bytes(
&self,
bytes: &[u8],
sig: &[u8],
sign_mode: SignMode,
) -> Result<(), CryptoError> {
match self {
CosmosPubKey::Secp256k1(pubkey) => pubkey.verify_bytes(bytes, sig),
CosmosPubKey::Multisig(pubkey) => pubkey.verify_bytes(bytes, sig),
CosmosPubKey::Secp256k1(pubkey) => pubkey.verify_bytes(bytes, sig, sign_mode),
CosmosPubKey::Multisig(pubkey) => pubkey.verify_bytes(bytes, sig, sign_mode),
}
}
}
Expand All @@ -139,6 +145,7 @@ pub enum SignModeDef {
SIGN_MODE_DIRECT = 1,
SIGN_MODE_TEXTUAL = 2,
SIGN_MODE_LEGACY_AMINO_JSON = 127,
SIGN_MODE_EIP_191 = 191,
}

#[allow(non_camel_case_types)]
Expand Down
43 changes: 43 additions & 0 deletions cosmwasm/enclaves/shared/cosmwasm-v010-types/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,34 @@ pub enum QueryRequest {
Dist(DistQuery),
Mint(MintQuery),
Gov(GovQuery),
Ibc(IbcQuery),
Stargate { path: String, data: Binary },
}

/// These are queries to the various IBC modules to see the state of the contract's
/// IBC connection. These will return errors if the contract is not "ibc enabled"
#[non_exhaustive]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "snake_case")]
pub enum IbcQuery {
/// Gets the Port ID the current contract is bound to.
///
/// Returns a `PortIdResponse`.
PortId {},
/// Lists all channels that are bound to a given port.
/// If `port_id` is omitted, this list all channels bound to the contract's port.
///
/// Returns a `ListChannelsResponse`.
ListChannels { port_id: Option<String> },
/// Lists all information for a (portID, channelID) pair.
/// If port_id is omitted, it will default to the contract's own channel.
/// (To save a PortId{} call)
///
/// Returns a `ChannelResponse`.
Channel {
channel_id: String,
port_id: Option<String>,
},
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -97,6 +125,8 @@ pub enum WasmQuery {
/// Key is the raw key used in the contracts Storage
key: Binary,
},
/// returns a ContractInfoResponse with metadata on the contract from the runtime
ContractInfo { contract_addr: String },
}

impl From<GovQuery> for QueryRequest {
Expand Down Expand Up @@ -153,6 +183,19 @@ pub enum StakingQuery {
Validators {},
/// Returns all the unbonding delegations by the delegator
UnbondingDelegations { delegator: HumanAddr },

/// Returns all validators in the currently active validator set.
///
/// The query response type is `AllValidatorsResponse`.
AllValidators {},
/// Returns the validator at the given address. Returns None if the validator is
/// not part of the currently active validator set.
///
/// The query response type is `ValidatorResponse`.
Validator {
/// The validator's address (e.g. (e.g. cosmosvaloper1...))
address: String,
},
}

/// Delegation is basic (cheap to query) data about a delegation
Expand Down
Loading