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

IBC Rate Limiting Audit Fixes #818

Merged
merged 24 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8e59f69
added undo rate limit send packet
sampocs Jun 6, 2023
3c449a6
added pending packet sequence keepers
sampocs Jun 6, 2023
ea03a06
implemented sequence checks and unit tests
sampocs Jun 6, 2023
b595566
added whitelist address keeper functions
sampocs Jun 6, 2023
42e283d
implemented address whitelist and unit tests
sampocs Jun 6, 2023
a20260f
updated readme
sampocs Jun 6, 2023
f4de6e8
added whitelist address in register host zone
sampocs Jun 7, 2023
f6ac6e7
fixed unit test
sampocs Jun 7, 2023
1e5cbd8
added queries for denom blacklist and address whitelist
sampocs Jun 7, 2023
8bedb4a
only stored pending packet if rate limit exists
sampocs Jun 7, 2023
7b2af20
fixed bug in build.sh with juno
sampocs Jun 8, 2023
9d60d30
increased gas
sampocs Jun 8, 2023
af2a635
fixed rate limit integration tests
sampocs Jun 9, 2023
2ad2213
fixed init/export genesis
sampocs Jun 9, 2023
489748c
changes after testing timeout/failure
sampocs Jun 11, 2023
8cd33f8
addressed aidan PR comments
sampocs Jun 12, 2023
0ee1f22
temporarily reverted address whitelist check
sampocs Jun 12, 2023
a98df1d
added whitelist to protos
sampocs Jun 13, 2023
74fb0cf
implemented new whitelist and unit tests
sampocs Jun 13, 2023
0c9b08d
added whitelist address in register host zone
sampocs Jun 13, 2023
5ed0bfd
fixed queries and init genesis
sampocs Jun 13, 2023
730d7ec
renamed whitelist address data struct and keepers
sampocs Jun 13, 2023
c347de9
updated readme
sampocs Jun 13, 2023
c6846d3
Merge branch 'main' into sam/ratelimit-audit-fix-timeout
sampocs Jun 13, 2023
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
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
path = deps/juno
url = https://github.com/CosmosContracts/juno.git
[submodule "deps/osmosis"]
# Commit: v15.1.0
# Commit: 08669da8509059980dc964976ee1ca60c84f5c8a
path = deps/osmosis
url = https://github.com/osmosis-labs/osmosis.git
[submodule "deps/stargaze"]
Expand Down
2 changes: 2 additions & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ func (app *StrideApp) setupUpgradeHandlers() {
Added: []string{ratelimittypes.StoreKey, autopilottypes.StoreKey},
}
}
// TODO: v10 UPGRADE HANDLER
// Add module and ICA accounts for each host zone to the rate limit whitelist

if storeUpgrades != nil {
app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, storeUpgrades))
Expand Down
2 changes: 1 addition & 1 deletion deps/osmosis
Submodule osmosis updated 1144 files
1 change: 1 addition & 0 deletions dockernet/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ build_local_and_docker() {
# Some projects have a hard coded build directory, while others allow the passing of BUILDDIR
# In the event that they have it hard coded, this will copy it into our build directory
mv $folder/build/* $BUILDDIR/ > /dev/null 2>&1
mv $folder/bin/* $BUILDDIR/ > /dev/null 2>&1

if [[ "$local_build_succeeded" == "0" ]]; then
echo "Done"
Expand Down
28 changes: 14 additions & 14 deletions dockernet/config/relayer_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ chains:
account-prefix: stride
keyring-backend: test
gas-adjustment: 1.3
gas-prices: 0.01ustrd
gas-prices: 0.02ustrd
coin-type: 118
debug: false
timeout: 20s
Expand All @@ -27,8 +27,8 @@ chains:
rpc-addr: http://gaia1:26657
account-prefix: cosmos
keyring-backend: test
gas-adjustment: 1.2
gas-prices: 0.01uatom
gas-adjustment: 1.3
gas-prices: 0.02uatom
coin-type: 118
debug: false
timeout: 20s
Expand All @@ -42,8 +42,8 @@ chains:
rpc-addr: http://juno1:26657
account-prefix: juno
keyring-backend: test
gas-adjustment: 1.2
gas-prices: 0.01ujuno
gas-adjustment: 1.3
gas-prices: 0.02ujuno
coin-type: 118
debug: false
timeout: 20s
Expand All @@ -57,8 +57,8 @@ chains:
rpc-addr: http://osmo1:26657
account-prefix: osmo
keyring-backend: test
gas-adjustment: 1.2
gas-prices: 0.01uosmo
gas-adjustment: 1.3
gas-prices: 0.02uosmo
coin-type: 118
debug: false
timeout: 20s
Expand All @@ -72,8 +72,8 @@ chains:
rpc-addr: http://stars1:26657
account-prefix: stars
keyring-backend: test
gas-adjustment: 1.2
gas-prices: 0.01ustars
gas-adjustment: 1.3
gas-prices: 0.02ustars
coin-type: 118
debug: false
timeout: 20s
Expand All @@ -88,7 +88,7 @@ chains:
account-prefix: stride
keyring-backend: test
gas-adjustment: 1.3
gas-prices: 0.01uwalk
gas-prices: 0.02uwalk
coin-type: 118
debug: false
timeout: 20s
Expand All @@ -102,8 +102,8 @@ chains:
rpc-addr: http://evmos1:26657
account-prefix: evmos
keyring-backend: test
gas-adjustment: 1.2
gas-prices: 0.01aevmos
gas-adjustment: 1.3
gas-prices: 0.02aevmos
coin-type: 60
debug: false
timeout: 20s
Expand All @@ -119,8 +119,8 @@ chains:
# rpc-addr: http://{node_prefix}1:26657
# account-prefix: {bech32_hrp_account_prefix}
# keyring-backend: test
# gas-adjustment: 1.2
# gas-prices: 0.01{minimal_denom}
# gas-adjustment: 1.3
# gas-prices: 0.02{minimal_denom}
# coin-type: {coin-type}
# debug: false
# timeout: 20s
Expand Down
8 changes: 4 additions & 4 deletions dockernet/config/relayer_config_juno_osmo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ chains:
rpc-addr: http://juno1:26657
account-prefix: juno
keyring-backend: test
gas-adjustment: 1.2
gas-prices: 0.01ujuno
gas-adjustment: 1.3
gas-prices: 0.02ujuno
debug: false
timeout: 20s
output-format: json
Expand All @@ -28,8 +28,8 @@ chains:
rpc-addr: http://osmo1:26657
account-prefix: osmo
keyring-backend: test
gas-adjustment: 1.2
gas-prices: 0.01uosmo
gas-adjustment: 1.3
gas-prices: 0.02uosmo
debug: false
timeout: 20s
output-format: json
Expand Down
4 changes: 2 additions & 2 deletions dockernet/dockerfiles/Dockerfile.osmo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ WORKDIR /opt/

RUN set -eux; apk add --no-cache ca-certificates build-base; apk add git linux-headers

ENV COMMIT_HASH=v15.1.0
ENV COMMIT_HASH=08669da8509059980dc964976ee1ca60c84f5c8a

RUN git clone https://github.com/osmosis-labs/osmosis.git \
&& cd osmosis \
Expand All @@ -13,7 +13,7 @@ RUN git clone https://github.com/osmosis-labs/osmosis.git \
WORKDIR /opt/osmosis

# Cosmwasm - download correct libwasmvm version and verify checksum
RUN WASMVM_VERSION=$(go list -m github.com/CosmWasm/wasmvm | cut -d ' ' -f 2) \
RUN WASMVM_VERSION=v1.0.0 \
&& wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/libwasmvm_muslc.$(uname -m).a \
-O /lib/libwasmvm_muslc.a \
&& wget https://github.com/CosmWasm/wasmvm/releases/download/$WASMVM_VERSION/checksums.txt -O /tmp/checksums.txt \
Expand Down
3 changes: 2 additions & 1 deletion dockernet/scripts/ratelimit/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ submit_proposal_and_vote() {
proposal_file=$2

echo ">>> Submitting proposal for: $proposal_file"
$STRIDE_MAIN_CMD tx gov submit-legacy-proposal $proposal_type ${CURRENT_DIR}/proposals/${proposal_file} --from ${STRIDE_VAL_PREFIX}1 -y | TRIM_TX
$STRIDE_MAIN_CMD tx gov submit-legacy-proposal $proposal_type ${CURRENT_DIR}/proposals/${proposal_file} \
--from ${STRIDE_VAL_PREFIX}1 -y --gas 1000000 | TRIM_TX
sleep 3

proposal_id=$(get_last_proposal_id)
Expand Down
2 changes: 2 additions & 0 deletions dockernet/scripts/ratelimit/run_all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ source ${CURRENT_DIR}/test_tx_remove.sh
source ${CURRENT_DIR}/test_quota_update.sh
source ${CURRENT_DIR}/test_bidirectional_flow.sh
source ${CURRENT_DIR}/test_denoms.sh
source ${CURRENT_DIR}/test_send_failure.sh

setup_juno_osmo_channel
setup_channel_value
Expand All @@ -23,3 +24,4 @@ test_denom_ujuno
test_denom_sttoken
test_denom_juno_traveler
test_remove_rate_limit
test_send_failures
56 changes: 56 additions & 0 deletions dockernet/scripts/ratelimit/test_send_failure.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
CURRENT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source ${CURRENT_DIR}/../../config.sh
source ${CURRENT_DIR}/common.sh

test_ack_timeout() {
print_header "TESTING ACK TIMEOUT"

# Capture the start flow
start_flow=$(get_flow_amount ustrd channel-2 outflow)
echo "Initial outflow for ustrd: $start_flow"

# Send the transfer with a sub-second timeout timestamp to force a timeout
echo "Transferring..."
timeout=1000 # in nanoseconds
$STRIDE_MAIN_CMD tx ibc-transfer transfer transfer channel-2 $(OSMO_ADDRESS) 10000000ustrd \
--from val1 -y --packet-timeout-timestamp $timeout | TRIM_TX
sleep 15

# Capture the outflow
end_flow=$(get_flow_amount ustrd channel-2 outflow)
echo "End outflow for ustrd: $end_flow"

# The outflow should have been reset
actual_flow_change=$((end_flow-start_flow))
print_expectation 0 $actual_flow_change "Flow Change"
}

test_ack_failure() {
print_header "TESTING ACK FAILURE"

# Capture the start flow
start_flow=$(get_flow_amount ustrd channel-2 outflow)
echo "Initial outflow for ustrd: $start_flow"

# Send the transfer with a stride destination address instead of an osmo address
# to cause the transfer to fail
echo "Transferring..."
invalid_address=$(STRIDE_ADDRESS)
$STRIDE_MAIN_CMD tx ibc-transfer transfer transfer channel-2 $invalid_address 10000000ustrd --from val1 -y | TRIM_TX
sleep 15

# Capture the outflow
end_flow=$(get_flow_amount ustrd channel-2 outflow)
echo "End outflow for ustrd: $end_flow"

# The outflow should have been reset
actual_flow_change=$((end_flow-start_flow))
print_expectation 0 $actual_flow_change "Flow Change"
}

test_send_failures() {
wait_until_epoch_end

test_ack_timeout
test_ack_failure
}
4 changes: 2 additions & 2 deletions dockernet/src/init_chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ set_stride_genesis() {
jq '(.app_state.epochs.epochs[] | select(.identifier=="stride_epoch") ).duration = $epochLen' --arg epochLen $STRIDE_EPOCH_EPOCH_DURATION $genesis_config > json.tmp && mv json.tmp $genesis_config
jq '(.app_state.epochs.epochs[] | select(.identifier=="mint") ).duration = $epochLen' --arg epochLen $STRIDE_MINT_EPOCH_DURATION $genesis_config > json.tmp && mv json.tmp $genesis_config
jq '.app_state.staking.params.unbonding_time = $newVal' --arg newVal "$UNBONDING_TIME" $genesis_config > json.tmp && mv json.tmp $genesis_config
jq '.app_state.gov.deposit_params.max_deposit_period = $newVal' --arg newVal "$MAX_DEPOSIT_PERIOD" $genesis_config > json.tmp && mv json.tmp $genesis_config
jq '.app_state.gov.voting_params.voting_period = $newVal' --arg newVal "$VOTING_PERIOD" $genesis_config > json.tmp && mv json.tmp $genesis_config
jq '.app_state.gov.params.max_deposit_period = $newVal' --arg newVal "$MAX_DEPOSIT_PERIOD" $genesis_config > json.tmp && mv json.tmp $genesis_config
jq '.app_state.gov.params.voting_period = $newVal' --arg newVal "$VOTING_PERIOD" $genesis_config > json.tmp && mv json.tmp $genesis_config

# enable stride as an interchain accounts controller
jq "del(.app_state.interchain_accounts)" $genesis_config > json.tmp && mv json.tmp $genesis_config
Expand Down
10 changes: 8 additions & 2 deletions proto/stride/ratelimit/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ option go_package = "github.com/Stride-Labs/stride/v9/x/ratelimit/types";

// GenesisState defines the ratelimit module's genesis state.
message GenesisState {
// params defines all the parameters of the module.
Params params = 1 [
(gogoproto.moretags) = "yaml:\"params\"",
(gogoproto.nullable) = false
];

// list of rate limits
repeated RateLimit rate_limits = 2 [
(gogoproto.moretags) = "yaml:\"rate_limits\"",
(gogoproto.nullable) = false
];

repeated AddressWhitelist whitelisted_address_pairs = 3 [
(gogoproto.moretags) = "yaml:\"whitelisted_address_pairs\"",
(gogoproto.nullable) = false
];

repeated string blacklisted_denoms = 4;
repeated string pending_send_packet_sequence_numbers = 5;
}
18 changes: 18 additions & 0 deletions proto/stride/ratelimit/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ service Query {
option (google.api.http).get =
"/Stride-Labs/stride/ratelimit/ratelimits/{channel_id}";
}
rpc AllBlacklistedDenoms(QueryAllBlacklistedDenomsRequest)
returns (QueryAllBlacklistedDenomsResponse) {
option (google.api.http).get =
"/Stride-Labs/stride/ratelimit/blacklisted_denoms";
}
rpc AllWhitelistedAddresses(QueryAllWhitelistedAddressesRequest)
returns (QueryAllWhitelistedAddressesResponse) {
option (google.api.http).get =
"/Stride-Labs/stride/ratelimit/whitelisted_addresses";
}
}

message QueryAllRateLimitsRequest {}
Expand All @@ -49,3 +59,11 @@ message QueryRateLimitsByChannelIdRequest { string channel_id = 1; }
message QueryRateLimitsByChannelIdResponse {
repeated RateLimit rate_limits = 1 [ (gogoproto.nullable) = false ];
}

message QueryAllBlacklistedDenomsRequest {}
message QueryAllBlacklistedDenomsResponse { repeated string denoms = 1; }

message QueryAllWhitelistedAddressesRequest {}
message QueryAllWhitelistedAddressesResponse {
repeated AddressWhitelist address_pairs = 1 [ (gogoproto.nullable) = false ];
}
5 changes: 5 additions & 0 deletions proto/stride/ratelimit/ratelimit.proto
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ message RateLimit {
Quota quota = 2;
Flow flow = 3;
}

message AddressWhitelist {
string sender = 1;
asalzmann marked this conversation as resolved.
Show resolved Hide resolved
string receiver = 2;
}
Loading