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

Tx expiration #1123

Merged
merged 58 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
1368c19
core: added `TempWlStorage` for ABCI++ prepare/process proposal
tzemanovic Jan 19, 2023
2bb8ead
changelog: add #1051
tzemanovic Feb 10, 2023
0b1aa74
Updates replay protection specs
grarco Dec 29, 2022
77e1627
Adds replay protection internal address and vp
grarco Dec 29, 2022
e028f9f
Updates replay protections specs with governance and unsigned inner hash
grarco Jan 4, 2023
14019da
Adds tx hash check in mempool validate
grarco Jan 4, 2023
c8710d7
Wrapper commit hash on unsigned inner tx
grarco Jan 9, 2023
78f1333
Unit test `mempool_validate`
grarco Jan 10, 2023
a5962d1
Refactors `unsigned_hash_tx`
grarco Jan 10, 2023
8cbccf7
Fixes replay protection specs
grarco Jan 10, 2023
5decfc9
Replay protection checks in `process_proposal`
grarco Jan 11, 2023
c795dce
Refactors `process_proposal`
grarco Jan 11, 2023
c00cb14
Fixes error codes
grarco Jan 11, 2023
b592344
Removes tx hash from storage in `finalize_block`
grarco Jan 11, 2023
f720b0a
Updates `process_proposal` unit tests
grarco Jan 12, 2023
a764bdb
Updates replay protection specs with protocol txs
grarco Jan 12, 2023
1f83434
Fixes `finalize_block` and adds unit test
grarco Jan 12, 2023
ada51c6
Updates `process_proposal` unit tests
grarco Jan 12, 2023
15eaf8d
Fmt
grarco Jan 12, 2023
fbb2bf5
Clippy
grarco Jan 13, 2023
ef04e1c
[ci] wasm checksums update
github-actions[bot] Jan 13, 2023
ec6a570
changelog: add #1017
grarco Jan 13, 2023
8391577
Fixes typos
grarco Jan 19, 2023
8b21bfd
Replay protection VP always rejects
grarco Jan 19, 2023
f3c3cdb
Fixes tx unsigned hash
grarco Jan 20, 2023
9f7ff17
Removes unnecessary clones
grarco Jan 20, 2023
906c742
Removes wal from replay protection specs
grarco Jan 20, 2023
b824f4e
Refactors replay protection logic
grarco Jan 23, 2023
8222615
Fmt
grarco Jan 23, 2023
e1f17ee
Fixes fee in unit tests
grarco Jan 24, 2023
519be43
[ci] wasm checksums update
github-actions[bot] Jan 24, 2023
b19e386
Fixes fee error code
grarco Feb 6, 2023
1d8e1da
Brings back sig check in `finalize_block`
grarco Feb 8, 2023
42e056d
Updates fees in replay protection specs
grarco Feb 8, 2023
48bcb8c
[ci] wasm checksums update
github-actions[bot] Feb 10, 2023
b23b7eb
Adds `ChainId` to struct `Tx`
grarco Jan 27, 2023
a5a437f
Adds chain id in `Tx` instantiations
grarco Jan 31, 2023
b96dd58
Adds tx `chain_id` in tests
grarco Jan 31, 2023
c6c2426
Validates tx `ChainId`
grarco Jan 31, 2023
5a626c4
Adjusts tx chain id check
grarco Feb 1, 2023
7e9643f
Unit tests for tx chain id
grarco Feb 1, 2023
dcc6d4b
Clippy + fmt
grarco Feb 1, 2023
ea1e448
Adjusts decrypted tx conversion
grarco Feb 3, 2023
976497c
Manages invalid chain id for decrypted txs
grarco Feb 6, 2023
a7ef5fe
[ci] wasm checksums update
github-actions[bot] Feb 10, 2023
d861a80
changelog: add #1106
grarco Feb 1, 2023
2d6e42e
Wrapper `epoch` in replay protection specs
grarco Feb 24, 2023
13e0fa9
Adds `expiration` field to `Tx`
grarco Feb 2, 2023
73a360a
Updates client for tx expiration
grarco Feb 2, 2023
0744c11
Tx expiration validation
grarco Feb 3, 2023
4b70485
Improves tx expiration checks. Adds unit tests
grarco Feb 7, 2023
d876660
Tx expiration check in `prepare_proposal`. Unit test
grarco Feb 7, 2023
2fdfbfc
Clippy + fmt
grarco Feb 7, 2023
d73aaec
Refactors block time retrieval
grarco Feb 8, 2023
58e601d
Refactors `prepare_proposal` tx validation
grarco Feb 24, 2023
e30bd99
Misc adjustments
grarco Feb 24, 2023
a11a3d1
[ci] wasm checksums update
github-actions[bot] Feb 24, 2023
76ad54b
changelog: add #1123
grarco Feb 7, 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: 2 additions & 0 deletions .changelog/unreleased/features/1123-tx-lifetime.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Adds expiration field to transactions
([#1123](https://github.com/anoma/namada/pull/1123))
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Adds hash-based replay protection
([#1017](https://github.com/anoma/namada/pull/1017))
3 changes: 3 additions & 0 deletions .changelog/unreleased/improvements/1051-temp-wl-storage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Added a TempWlStorage for storage_api::StorageRead/Write
in ABCI++ prepare/process proposal handler.
([#1051](https://github.com/anoma/namada/pull/1051))
2 changes: 2 additions & 0 deletions .changelog/unreleased/improvements/1106-tx-chain-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Adds chain id field to transactions
([#1106](https://github.com/anoma/namada/pull/1106))
11 changes: 11 additions & 0 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,7 @@ pub mod args {
const DRY_RUN_TX: ArgFlag = flag("dry-run");
const DUMP_TX: ArgFlag = flag("dump-tx");
const EPOCH: ArgOpt<Epoch> = arg_opt("epoch");
const EXPIRATION_OPT: ArgOpt<DateTimeUtc> = arg_opt("expiration");
const FORCE: ArgFlag = flag("force");
const DONT_PREFETCH_WASM: ArgFlag = flag("dont-prefetch-wasm");
const GAS_AMOUNT: ArgDefault<token::Amount> =
Expand Down Expand Up @@ -2863,6 +2864,8 @@ pub mod args {
pub fee_token: WalletAddress,
/// The max amount of gas used to process tx
pub gas_limit: GasLimit,
/// The optional expiration of the transaction
pub expiration: Option<DateTimeUtc>,
/// Sign the tx with the key for the given alias from your wallet
pub signing_key: Option<WalletKeypair>,
/// Sign the tx with the keypair of the public key of the given address
Expand Down Expand Up @@ -2923,6 +2926,12 @@ pub mod args {
"The maximum amount of gas needed to run transaction",
),
)
.arg(EXPIRATION_OPT.def().about(
"The expiration datetime of the transaction, after which the \
tx won't be accepted anymore. All of these examples are \
equivalent:\n2012-12-12T12:12:12Z\n2012-12-12 \
12:12:12Z\n2012- 12-12T12: 12:12Z",
tzemanovic marked this conversation as resolved.
Show resolved Hide resolved
))
.arg(
SIGNING_KEY_OPT
.def()
Expand Down Expand Up @@ -2954,6 +2963,7 @@ pub mod args {
let fee_amount = GAS_AMOUNT.parse(matches);
let fee_token = GAS_TOKEN.parse(matches);
let gas_limit = GAS_LIMIT.parse(matches).into();
let expiration = EXPIRATION_OPT.parse(matches);

let signing_key = SIGNING_KEY_OPT.parse(matches);
let signer = SIGNER.parse(matches);
Expand All @@ -2967,6 +2977,7 @@ pub mod args {
fee_amount,
fee_token,
gas_limit,
expiration,
signing_key,
signer,
}
Expand Down
2 changes: 1 addition & 1 deletion apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ pub async fn query_tx_deltas(
let mut transfer = None;
extract_payload(tx, &mut wrapper, &mut transfer);
// Epoch data is not needed for transparent transactions
let epoch = wrapper.map(|x| x.epoch).unwrap_or_default();
let epoch = Epoch::default();
if let Some(transfer) = transfer {
// Skip MASP addresses as they are already handled by
// ShieldedContext
Expand Down
4 changes: 2 additions & 2 deletions apps/src/lib/client/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

use borsh::BorshSerialize;
use namada::ledger::parameters::storage as parameter_storage;
use namada::proof_of_stake::Epoch;
use namada::proto::Tx;
use namada::types::address::{Address, ImplicitAddress};
use namada::types::hash::Hash;
use namada::types::key::*;
use namada::types::storage::Epoch;
use namada::types::token;
use namada::types::token::Amount;
use namada::types::transaction::{hash_tx, Fee, WrapperTx, MIN_FEE};
Expand Down Expand Up @@ -310,7 +310,7 @@ pub async fn sign_wrapper(
let decrypted_hash = tx.tx_hash.to_string();
TxBroadcastData::Wrapper {
tx: tx
.sign(keypair)
.sign(keypair, ctx.config.ledger.chain_id.clone(), args.expiration)
.expect("Wrapper tx signing keypair should be correct"),
wrapper_hash,
decrypted_hash,
Expand Down
87 changes: 74 additions & 13 deletions apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ pub async fn submit_custom(ctx: Context, args: args::TxCustom) {
let data = args.data_path.map(|data_path| {
std::fs::read(data_path).expect("Expected a file at given data path")
});
let tx = Tx::new(tx_code, data);
let tx = Tx::new(
tx_code,
data,
ctx.config.ledger.chain_id.clone(),
args.tx.expiration,
);
let (ctx, initialized_accounts) = process_tx(
ctx,
&args.tx,
Expand Down Expand Up @@ -169,7 +174,12 @@ pub async fn submit_update_vp(ctx: Context, args: args::TxUpdateVp) {
let data = UpdateVp { addr, vp_code };
let data = data.try_to_vec().expect("Encoding tx data shouldn't fail");

let tx = Tx::new(tx_code, Some(data));
let tx = Tx::new(
tx_code,
Some(data),
ctx.config.ledger.chain_id.clone(),
args.tx.expiration,
);
process_tx(
ctx,
&args.tx,
Expand Down Expand Up @@ -202,7 +212,12 @@ pub async fn submit_init_account(mut ctx: Context, args: args::TxInitAccount) {
};
let data = data.try_to_vec().expect("Encoding tx data shouldn't fail");

let tx = Tx::new(tx_code, Some(data));
let tx = Tx::new(
tx_code,
Some(data),
ctx.config.ledger.chain_id.clone(),
args.tx.expiration,
);
let (ctx, initialized_accounts) = process_tx(
ctx,
&args.tx,
Expand Down Expand Up @@ -335,7 +350,12 @@ pub async fn submit_init_validator(
validator_vp_code,
};
let data = data.try_to_vec().expect("Encoding tx data shouldn't fail");
let tx = Tx::new(tx_code, Some(data));
let tx = Tx::new(
tx_code,
Some(data),
ctx.config.ledger.chain_id.clone(),
tx_args.expiration,
);
let (mut ctx, initialized_accounts) = process_tx(
ctx,
&tx_args,
Expand Down Expand Up @@ -1677,7 +1697,12 @@ pub async fn submit_transfer(mut ctx: Context, args: args::TxTransfer) {
.try_to_vec()
.expect("Encoding tx data shouldn't fail");
let tx_code = ctx.read_wasm(TX_TRANSFER_WASM);
let tx = Tx::new(tx_code, Some(data));
let tx = Tx::new(
tx_code,
Some(data),
ctx.config.ledger.chain_id.clone(),
args.tx.expiration,
);
let signing_address = TxSigningKey::WalletAddress(args.source.to_address());

process_tx(
Expand Down Expand Up @@ -1797,7 +1822,12 @@ pub async fn submit_ibc_transfer(ctx: Context, args: args::TxIbcTransfer) {
prost::Message::encode(&any_msg, &mut data)
.expect("Encoding tx data shouldn't fail");

let tx = Tx::new(tx_code, Some(data));
let tx = Tx::new(
tx_code,
Some(data),
ctx.config.ledger.chain_id.clone(),
args.tx.expiration,
);
process_tx(
ctx,
&args.tx,
Expand Down Expand Up @@ -1942,7 +1972,12 @@ pub async fn submit_init_proposal(mut ctx: Context, args: args::InitProposal) {
.try_to_vec()
.expect("Encoding proposal data shouldn't fail");
let tx_code = ctx.read_wasm(TX_INIT_PROPOSAL);
let tx = Tx::new(tx_code, Some(data));
let tx = Tx::new(
tx_code,
Some(data),
ctx.config.ledger.chain_id.clone(),
args.tx.expiration,
);

process_tx(
ctx,
Expand Down Expand Up @@ -2082,7 +2117,12 @@ pub async fn submit_vote_proposal(mut ctx: Context, args: args::VoteProposal) {
.try_to_vec()
.expect("Encoding proposal data shouldn't fail");
let tx_code = ctx.read_wasm(TX_VOTE_PROPOSAL);
let tx = Tx::new(tx_code, Some(data));
let tx = Tx::new(
tx_code,
Some(data),
ctx.config.ledger.chain_id.clone(),
args.tx.expiration,
);

process_tx(
ctx,
Expand Down Expand Up @@ -2154,7 +2194,8 @@ pub async fn submit_reveal_pk_aux(
.try_to_vec()
.expect("Encoding a public key shouldn't fail");
let tx_code = ctx.read_wasm(TX_REVEAL_PK);
let tx = Tx::new(tx_code, Some(tx_data));
let chain_id = ctx.config.ledger.chain_id.clone();
let tx = Tx::new(tx_code, Some(tx_data), chain_id, args.expiration);

// submit_tx without signing the inner tx
let keypair = if let Some(signing_key) = &args.signing_key {
Expand Down Expand Up @@ -2357,7 +2398,12 @@ pub async fn submit_bond(ctx: Context, args: args::Bond) {
};
let data = bond.try_to_vec().expect("Encoding tx data shouldn't fail");

let tx = Tx::new(tx_code, Some(data));
let tx = Tx::new(
tx_code,
Some(data),
ctx.config.ledger.chain_id.clone(),
args.tx.expiration,
);
let default_signer = args.source.unwrap_or(args.validator);
process_tx(
ctx,
Expand Down Expand Up @@ -2412,7 +2458,12 @@ pub async fn submit_unbond(ctx: Context, args: args::Unbond) {
let data = data.try_to_vec().expect("Encoding tx data shouldn't fail");

let tx_code = ctx.read_wasm(TX_UNBOND_WASM);
let tx = Tx::new(tx_code, Some(data));
let tx = Tx::new(
tx_code,
Some(data),
ctx.config.ledger.chain_id.clone(),
args.tx.expiration,
);
let default_signer = args.source.unwrap_or(args.validator);
let (_ctx, _) = process_tx(
ctx,
Expand Down Expand Up @@ -2477,7 +2528,12 @@ pub async fn submit_withdraw(ctx: Context, args: args::Withdraw) {
let data = data.try_to_vec().expect("Encoding tx data shouldn't fail");

let tx_code = ctx.read_wasm(TX_WITHDRAW_WASM);
let tx = Tx::new(tx_code, Some(data));
let tx = Tx::new(
tx_code,
Some(data),
ctx.config.ledger.chain_id.clone(),
args.tx.expiration,
);
let default_signer = args.source.unwrap_or(args.validator);
process_tx(
ctx,
Expand Down Expand Up @@ -2563,7 +2619,12 @@ pub async fn submit_validator_commission_change(
};
let data = data.try_to_vec().expect("Encoding tx data shouldn't fail");

let tx = Tx::new(tx_code, Some(data));
let tx = Tx::new(
tx_code,
Some(data),
ctx.config.ledger.chain_id.clone(),
args.tx.expiration,
);
let default_signer = args.validator;
process_tx(
ctx,
Expand Down
Loading