Skip to content

Commit b9873ed

Browse files
authored
feat(lst): more tests and hardening (#5219)
2 parents 9600b55 + e33bb51 commit b9873ed

File tree

11 files changed

+458
-212
lines changed

11 files changed

+458
-212
lines changed

Cargo.lock

Lines changed: 15 additions & 68 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cosmwasm/lst/Cargo.toml

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,28 @@ crate-type = ["cdylib", "rlib"]
1111
workspace = true
1212

1313
[dependencies]
14-
bincode = { workspace = true, features = ["derive"] }
15-
cosmwasm-schema = { workspace = true, optional = true }
16-
cosmwasm-std = { workspace = true, features = ["cosmwasm_2_0"] }
17-
cw-utils = { version = "2.0.0" }
18-
cw20 = { version = "2.0.0" }
19-
depolama = { workspace = true, features = ["iterator"] }
20-
embed-commit = { workspace = true }
21-
frissitheto = { workspace = true }
22-
ibc-union-spec = { workspace = true, features = ["serde", "bincode"] }
23-
itertools = { workspace = true }
24-
prost = { workspace = true, features = ["prost-derive"] }
14+
bincode = { workspace = true, features = ["derive"] }
15+
cosmwasm-schema = { workspace = true, optional = true }
16+
cosmwasm-std = { workspace = true, features = ["cosmwasm_2_0"] }
17+
cw-utils = { version = "2.0.0" }
18+
cw20 = { version = "2.0.0" }
19+
depolama = { workspace = true, features = ["iterator"] }
20+
embed-commit = { workspace = true }
21+
frissitheto = { workspace = true }
22+
itertools = { workspace = true }
23+
# TODO: Add back when the unbonding period is queryable from the chain
24+
# prost = { workspace = true, features = ["prost-derive"] }
2525
schemars = { workspace = true, optional = true }
2626
serde = { workspace = true }
2727
serde-json-wasm = "1.0"
2828
serde-utils = { workspace = true }
2929
sha2 = { workspace = true }
3030
thiserror = { workspace = true }
3131
unionlabs-encoding = { workspace = true, features = ["bincode"] }
32-
unionlabs-primitives = { workspace = true, features = ["bincode"] }
32+
unionlabs-primitives = { workspace = true, features = ["serde", "bincode", "generic-array-compat"] }
3333

3434
[dev-dependencies]
35-
cw-multi-test = "0.17.0"
36-
hex-literal = { version = "1.0" }
37-
ucs03-zkgm = { workspace = true, features = ["library"] }
35+
hex-literal = { version = "1.0" }
3836

3937
[features]
4038
default = []

cosmwasm/lst/src/contract.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ pub fn execute(
190190
min_mint_amount,
191191
} => bond(deps, info, mint_to_address, min_mint_amount.u128()),
192192
ExecuteMsg::Unbond { amount } => unbond(deps, env, info, amount.u128()),
193-
ExecuteMsg::SubmitBatch {} => submit_batch(deps, env),
193+
ExecuteMsg::SubmitBatch {} => submit_batch(deps, env, info),
194194
ExecuteMsg::Withdraw {
195195
batch_id,
196196
withdraw_to_address,

cosmwasm/lst/src/execute.rs

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use cosmwasm_std::{
6363
Uint128,
6464
};
6565
use cw20::Cw20ExecuteMsg;
66-
use cw_utils::must_pay;
66+
use cw_utils::{must_pay, nonpayable};
6767
use depolama::StorageExt;
6868

6969
use crate::{
@@ -225,6 +225,7 @@ pub fn unbond(
225225
info: MessageInfo,
226226
unbond_amount: u128,
227227
) -> ContractResult<Response> {
228+
nonpayable(&info)?;
228229
ensure_not_stopped(deps.as_ref())?;
229230

230231
let staker_hash = staker_hash(&info.sender);
@@ -312,7 +313,8 @@ pub fn unbond(
312313
///
313314
/// TODO: Withdraw unstaked tokens in this function
314315
/// TODO: Incentivize this call
315-
pub fn submit_batch(deps: DepsMut, env: Env) -> ContractResult<Response> {
316+
pub fn submit_batch(deps: DepsMut, env: Env, info: MessageInfo) -> ContractResult<Response> {
317+
nonpayable(&info)?;
316318
ensure_not_stopped(deps.as_ref())?;
317319

318320
let config = deps.storage.read_item::<ConfigStore>()?;
@@ -514,6 +516,7 @@ pub fn receive_rewards(deps: DepsMut, info: MessageInfo) -> ContractResult<Respo
514516
}
515517

516518
pub fn rebase(deps: DepsMut, info: MessageInfo) -> ContractResult<Response> {
519+
nonpayable(&info)?;
517520
ensure_not_stopped(deps.as_ref())?;
518521

519522
Ok(Response::new()
@@ -547,9 +550,8 @@ pub fn receive_unstaked_tokens(
547550
expected_native_unstaked,
548551
} = deps
549552
.storage
550-
.maybe_read::<SubmittedBatches>(&batch_id)?
553+
.take::<SubmittedBatches>(&batch_id)?
551554
.ok_or(ContractError::BatchNotFound { batch_id })?;
552-
deps.storage.delete::<SubmittedBatches>(&batch_id);
553555

554556
ensure!(
555557
receive_time <= env.block.time.seconds(),
@@ -590,6 +592,7 @@ pub fn withdraw(
590592
batch_id: BatchId,
591593
withdraw_to_address: Addr,
592594
) -> ContractResult<Response> {
595+
nonpayable(&info)?;
593596
ensure_not_stopped(deps.as_ref())?;
594597

595598
let config = deps.storage.read_item::<ConfigStore>()?;
@@ -652,6 +655,7 @@ pub fn transfer_ownership(
652655
info: MessageInfo,
653656
new_owner: String,
654657
) -> ContractResult<Response> {
658+
nonpayable(&info)?;
655659
ensure_admin(deps.as_ref(), &info)?;
656660

657661
deps.storage.write_item::<PendingOwnerStore>(&PendingOwner {
@@ -673,6 +677,7 @@ pub fn transfer_ownership(
673677

674678
// Revoke transfer ownership, callable by the owner
675679
pub fn revoke_ownership_transfer(deps: DepsMut, info: MessageInfo) -> ContractResult<Response> {
680+
nonpayable(&info)?;
676681
ensure_admin(deps.as_ref(), &info)?;
677682

678683
deps.storage.delete_item::<PendingOwnerStore>();
@@ -681,25 +686,27 @@ pub fn revoke_ownership_transfer(deps: DepsMut, info: MessageInfo) -> ContractRe
681686
}
682687

683688
pub fn accept_ownership(deps: DepsMut, env: Env, info: MessageInfo) -> ContractResult<Response> {
689+
nonpayable(&info)?;
690+
684691
let PendingOwner {
685692
address: pending_owner,
686693
owner_transfer_min_time_seconds,
687694
} = deps
688695
.storage
689-
.maybe_read_item::<PendingOwnerStore>()?
696+
.take_item::<PendingOwnerStore>()?
690697
.ok_or(ContractError::NoPendingOwner)?;
691698

692-
ensure!(
693-
owner_transfer_min_time_seconds <= env.block.time.seconds(),
694-
ContractError::OwnershipTransferNotReady {
695-
claimable_at_seconds: owner_transfer_min_time_seconds,
696-
now_seconds: env.block.time.seconds()
697-
}
698-
);
699-
700699
if pending_owner == info.sender.as_str() {
701-
deps.storage.delete_item::<PendingOwnerStore>();
700+
ensure!(
701+
owner_transfer_min_time_seconds <= env.block.time.seconds(),
702+
ContractError::OwnershipTransferNotReady {
703+
claimable_at_seconds: owner_transfer_min_time_seconds,
704+
now_seconds: env.block.time.seconds()
705+
}
706+
);
707+
702708
deps.storage.write_item::<Admin>(&info.sender);
709+
703710
Ok(Response::new()
704711
.add_event(Event::new("accept_ownership").add_attribute("new_owner", info.sender)))
705712
} else {
@@ -715,6 +722,7 @@ pub fn update_config(
715722
batch_period_seconds: Option<u64>,
716723
unbonding_period_seconds: Option<u64>,
717724
) -> ContractResult<Response> {
725+
nonpayable(&info)?;
718726
ensure_admin(deps.as_ref(), &info)?;
719727

720728
let mut event = Event::new("update_config");
@@ -773,6 +781,7 @@ pub fn update_config(
773781
}
774782

775783
pub fn circuit_breaker(deps: DepsMut, info: MessageInfo) -> ContractResult<Response> {
784+
nonpayable(&info)?;
776785
ensure_not_stopped(deps.as_ref())?;
777786

778787
// must either be admin or a monitor to halt the contract
@@ -798,6 +807,7 @@ pub fn resume_contract(
798807
info: MessageInfo,
799808
new_accounting_state: AccountingState,
800809
) -> ContractResult<Response> {
810+
nonpayable(&info)?;
801811
ensure_admin(deps.as_ref(), &info)?;
802812
ensure_stopped(deps.as_ref())?;
803813

@@ -828,8 +838,8 @@ pub fn slash_batches(
828838
info: MessageInfo,
829839
expected_amounts: Vec<BatchExpectedAmount>,
830840
) -> ContractResult<Response> {
841+
nonpayable(&info)?;
831842
ensure_admin(deps.as_ref(), &info)?;
832-
833843
// ensure the contract is stopped before slashing the batches
834844
ensure_stopped(deps.as_ref())?;
835845

0 commit comments

Comments
 (0)