From c2d6105ad9c5b1cfbd544cc382cd8e7667ed0b9a Mon Sep 17 00:00:00 2001 From: James Hiew Date: Thu, 1 Dec 2022 14:21:01 +0000 Subject: [PATCH 1/4] Add Amount::is_zero fn --- core/src/types/token.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/src/types/token.rs b/core/src/types/token.rs index d95d944b8c..28e7d3947c 100644 --- a/core/src/types/token.rs +++ b/core/src/types/token.rs @@ -45,6 +45,11 @@ pub const MAX_AMOUNT: Amount = Amount { micro: u64::MAX }; pub type Change = i128; impl Amount { + /// Returns whether an amount is zero. + pub fn is_zero(&self) -> bool { + self.micro == 0 + } + /// Get the amount as a [`Change`] pub fn change(&self) -> Change { self.micro as Change @@ -550,6 +555,15 @@ mod tests { assert_eq!(max.checked_add(one), None); assert_eq!(max.checked_add(max), None); } + + #[test] + fn test_amount_is_zero() { + let zero = Amount::from(0); + assert!(zero.is_zero()); + + let non_zero = Amount::from(1); + assert!(!non_zero.is_zero()); + } } /// Helpers for testing with addresses. From 626548d45eac3a3811fde412e3a3eadd42ac37d5 Mon Sep 17 00:00:00 2001 From: James Hiew Date: Thu, 1 Dec 2022 14:23:05 +0000 Subject: [PATCH 2/4] Short circuit token::transfer if amount is zero --- core/src/ledger/storage_api/token.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/src/ledger/storage_api/token.rs b/core/src/ledger/storage_api/token.rs index c1e6573a21..b177029f7e 100644 --- a/core/src/ledger/storage_api/token.rs +++ b/core/src/ledger/storage_api/token.rs @@ -33,6 +33,9 @@ pub fn transfer( where S: StorageRead + StorageWrite, { + if amount.is_zero() { + return Ok(()); + } let src_key = token::balance_key(token, src); let src_balance = read_balance(storage, token, src)?; match src_balance.checked_sub(amount) { From b5e6d478d074781c5e4a7a9ef915609bb3e37d53 Mon Sep 17 00:00:00 2001 From: James Hiew Date: Fri, 16 Dec 2022 13:36:49 +0000 Subject: [PATCH 3/4] Add changelog --- .changelog/unreleased/improvements/856-amount-is-zero.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/improvements/856-amount-is-zero.md diff --git a/.changelog/unreleased/improvements/856-amount-is-zero.md b/.changelog/unreleased/improvements/856-amount-is-zero.md new file mode 100644 index 0000000000..a70f019426 --- /dev/null +++ b/.changelog/unreleased/improvements/856-amount-is-zero.md @@ -0,0 +1,2 @@ +- Return early in PosBase::transfer if an attempt is made to transfer zero + tokens ([#856](https://github.com/anoma/namada/pull/856)) \ No newline at end of file From 9f988a7493c2ea0fecf2e470bbdc6911427c2b16 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 30 Mar 2023 19:29:44 +0000 Subject: [PATCH 4/4] [ci] wasm checksums update --- wasm/checksums.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/wasm/checksums.json b/wasm/checksums.json index 5f4b6eb74f..7acadc85e8 100644 --- a/wasm/checksums.json +++ b/wasm/checksums.json @@ -1,16 +1,16 @@ { - "tx_bond.wasm": "tx_bond.3277d0c7eb81db738c3b77963c546e385e11bd0c87ff5213e49d0d4a96f4b7e1.wasm", + "tx_bond.wasm": "tx_bond.8915d1bc2e50a39113eda4b84dbafcef55634bda3c7c517687112952353bdc40.wasm", "tx_change_validator_commission.wasm": "tx_change_validator_commission.8da9bfc181836d1715e3e35f99bf3577c157f619ceb573b2911e9ebd2b497a9b.wasm", - "tx_ibc.wasm": "tx_ibc.7f35d82f6ba216f6ecffe0c7ca52e641a9b7763dde03d533a88bc20a88c14737.wasm", + "tx_ibc.wasm": "tx_ibc.d8d856437804b82374051fb15c441c9b50715e51aca06b4f7d1ffe67fd75dd13.wasm", "tx_init_account.wasm": "tx_init_account.9cc792ba8535b0e29643184afbd51c6b5e7153a4276a7acc23079ed9e802fb2b.wasm", - "tx_init_proposal.wasm": "tx_init_proposal.26d8b551e609dddc6dc6e608d36994edde00b49a14c20fa0c8074e94244d5674.wasm", + "tx_init_proposal.wasm": "tx_init_proposal.84fa938093c4a5bd9d0113ac2684fa38ccd99cd56e8291da74026a9b85d278a4.wasm", "tx_init_validator.wasm": "tx_init_validator.3f04b3bbeb17b493858ba96dc309021468b166ab01d594773cbf9744d1a8076b.wasm", "tx_reveal_pk.wasm": "tx_reveal_pk.7a645d6afbf8844e1aea83905eed26f9e7d550db456bdde169a4786c902b917f.wasm", - "tx_transfer.wasm": "tx_transfer.0db9fb8473c65b88800e2cd1e9a630245d01062cdc31fdb80b87da53fedaa5fd.wasm", + "tx_transfer.wasm": "tx_transfer.64d73335d0db816c56d21e5ef2af11f594337370d36ba28a8e1b329e1216692f.wasm", "tx_unbond.wasm": "tx_unbond.c3391611d4a1f5818876a799efa87fee793eedcba193c636e294bf1dd4c6f340.wasm", "tx_update_vp.wasm": "tx_update_vp.dbaf4fdacb12fba9fe1231afd0371a302a8242cbbf74565d8605a646fe5a00ab.wasm", "tx_vote_proposal.wasm": "tx_vote_proposal.704d0c40268c997ab185d9e5a9f02decf40f4c51c9684a25ef6a9be2768b180d.wasm", - "tx_withdraw.wasm": "tx_withdraw.d213ea0d916f7c962527fb2526df98479dff7c0ab984e776f523e61407ca3608.wasm", + "tx_withdraw.wasm": "tx_withdraw.70bea521c96d4a5e970a741c7b5af03c6407c4b7f9c27b3f8b9a4baa530f6c43.wasm", "vp_implicit.wasm": "vp_implicit.e5aff165c7b3c43f0d6d0bc2848f2d171ce5599f01fa33d0572bea584a83903c.wasm", "vp_masp.wasm": "vp_masp.813d4ec58e55255f0fe3e3d40ea723fca34dcea69de57f26e89c7737c56254db.wasm", "vp_testnet_faucet.wasm": "vp_testnet_faucet.25bcab2206bba4cf89dbf33cf133fd034878566d7e375856bbf53e4547db441f.wasm",