Skip to content

Commit

Permalink
Hardcode intent for transaction messages (MystenLabs#15283)
Browse files Browse the repository at this point in the history
## Description 

All transaction messages should have the same intent, which can be hard
coded instead of always passing in, which adds possibility for
introducing errors and bugs.

## Test Plan 

CI. All changes are trivial and straightforward.

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
lxfind authored Dec 11, 2023
1 parent 0c50609 commit 7a858b0
Show file tree
Hide file tree
Showing 29 changed files with 81 additions and 142 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

10 changes: 2 additions & 8 deletions crates/simulacrum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ pub use self::store::in_mem_store::InMemoryStore;
use self::store::in_mem_store::KeyStore;
pub use self::store::SimulatorStore;
use sui_types::mock_checkpoint_builder::{MockCheckpointBuilder, ValidatorKeypairProvider};

use shared_crypto::intent::Intent;
use sui_types::{
gas_coin::GasCoin,
programmable_transaction_builder::ProgrammableTransactionBuilder,
Expand Down Expand Up @@ -358,11 +356,7 @@ impl<R, S: store::SimulatorStore> Simulacrum<R, S> {
let kind = sui_types::transaction::TransactionKind::ProgrammableTransaction(pt);
let tx_data =
sui_types::transaction::TransactionData::new_with_gas_data(kind, *sender, gas_data);
let tx = Transaction::from_data_and_signer(
tx_data,
shared_crypto::intent::Intent::sui_transaction(),
vec![key],
);
let tx = Transaction::from_data_and_signer(tx_data, vec![key]);

self.execute_transaction(tx).map(|x| x.0)
}
Expand Down Expand Up @@ -441,7 +435,7 @@ impl Simulacrum {
budget: 1_000_000_000,
};
let tx_data = TransactionData::new_with_gas_data(kind, sender, gas_data);
let tx = Transaction::from_data_and_signer(tx_data, Intent::sui_transaction(), vec![key]);
let tx = Transaction::from_data_and_signer(tx_data, vec![key]);
(tx, transfer_amount)
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/sui-cluster-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use sui_types::object::Owner;
use sui_types::quorum_driver_types::ExecuteTransactionRequestType;
use sui_types::sui_system_state::sui_system_state_summary::SuiSystemStateSummary;

use shared_crypto::intent::Intent;
use sui_sdk::SuiClient;
use sui_types::gas_coin::GasCoin;
use sui_types::{
Expand Down Expand Up @@ -153,7 +152,7 @@ impl TestContext {
.get_fullnode_client()
.quorum_driver_api()
.execute_transaction_block(
Transaction::from_data(txn_data, Intent::sui_transaction(), vec![signature]),
Transaction::from_data(txn_data, vec![signature]),
SuiTransactionBlockResponseOptions::new()
.with_object_changes()
.with_balance_changes()
Expand Down
1 change: 0 additions & 1 deletion crates/sui-core/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,6 @@ pub fn make_dummy_tx(
TEST_ONLY_GAS_UNIT_FOR_TRANSFER * 10,
10,
),
Intent::sui_transaction(),
vec![sender_sec],
)
}
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-faucet/src/bin/merge_coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async fn _split_coins_equally(
.keystore
.sign_secure(&active_address, &tx_data, Intent::sui_transaction())
.unwrap();
let tx = Transaction::from_data(tx_data, Intent::sui_transaction(), vec![signature]);
let tx = Transaction::from_data(tx_data, vec![signature]);
let resp = client
.quorum_driver_api()
.execute_transaction_block(
Expand Down Expand Up @@ -110,7 +110,7 @@ async fn _merge_coins(gas_coin: &str, mut wallet: WalletContext) -> Result<(), a
.keystore
.sign_secure(&active_address, &tx_data, Intent::sui_transaction())
.unwrap();
let tx = Transaction::from_data(tx_data, Intent::sui_transaction(), vec![signature]);
let tx = Transaction::from_data(tx_data, vec![signature]);
client
.quorum_driver_api()
.execute_transaction_block(
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-faucet/src/faucet/simple_faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ impl SimpleFaucet {
.keystore
.sign_secure(&self.active_address, &tx_data, Intent::sui_transaction())
.map_err(FaucetError::internal)?;
let tx = Transaction::from_data(tx_data, Intent::sui_transaction(), vec![signature]);
let tx = Transaction::from_data(tx_data, vec![signature]);
let tx_digest = *tx.digest();
info!(
?tx_digest,
Expand Down
4 changes: 1 addition & 3 deletions crates/sui-graphql-rpc/src/mutation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crate::{error::Error, types::execution_result::ExecutionResult};
use async_graphql::*;
use fastcrypto::encoding::Encoding;
use fastcrypto::{encoding::Base64, traits::ToFromBytes};
use shared_crypto::intent::Intent;
use sui_json_rpc_types::SuiTransactionBlockResponseOptions;
use sui_sdk::SuiClient;
use sui_types::quorum_driver_types::ExecuteTransactionRequestType;
Expand Down Expand Up @@ -71,8 +70,7 @@ impl Mutation {
.extend()?,
);
}
let transaction =
Transaction::from_generic_sig_data(tx_data, Intent::sui_transaction(), sigs);
let transaction = Transaction::from_generic_sig_data(tx_data, sigs);

let result = sui_sdk_client
.quorum_driver_api()
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-json-rpc/src/transaction_execution_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl TransactionExecutionApi {
for sig in signatures {
sigs.push(GenericSignature::from_bytes(&sig.to_vec()?)?);
}
let txn = Transaction::from_generic_sig_data(tx_data, Intent::sui_transaction(), sigs);
let txn = Transaction::from_generic_sig_data(tx_data, sigs);
let raw_transaction = if opts.show_raw_input {
bcs::to_bytes(txn.data())?
} else {
Expand Down
1 change: 1 addition & 0 deletions crates/sui-replay/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ move-bytecode-utils.workspace = true
move-core-types.workspace = true
tokio.workspace = true

shared-crypto.workspace = true
sui-config.workspace = true
sui-core.workspace = true
sui-execution.workspace = true
Expand Down
22 changes: 11 additions & 11 deletions crates/sui-replay/src/replay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use move_core_types::{
};
use prometheus::Registry;
use serde::{Deserialize, Serialize};
use shared_crypto::intent::Intent;
use similar::{ChangeTag, TextDiff};
use std::{
collections::{BTreeMap, HashSet},
Expand Down Expand Up @@ -828,12 +829,14 @@ impl LocalExec {
let required_objects = pre_run_sandbox.required_objects.clone();
let shared_object_refs = pre_run_sandbox.transaction_info.shared_object_refs.clone();

let transaction_intent = pre_run_sandbox
.transaction_info
.sender_signed_data
.intent_message()
.intent
.clone();
assert_eq!(
pre_run_sandbox
.transaction_info
.sender_signed_data
.intent_message()
.intent,
Intent::sui_transaction()
);
let transaction_signatures = pre_run_sandbox
.transaction_info
.sender_signed_data
Expand All @@ -859,11 +862,8 @@ impl LocalExec {
)
.await;

let sender_signed_tx = Transaction::from_generic_sig_data(
transaction_data,
transaction_intent,
transaction_signatures,
);
let sender_signed_tx =
Transaction::from_generic_sig_data(transaction_data, transaction_signatures);
let sender_signed_tx = VerifiedTransaction::new_unchecked(
VerifiedTransaction::new_unchecked(sender_signed_tx).into(),
);
Expand Down
1 change: 0 additions & 1 deletion crates/sui-rosetta/src/construction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ pub async fn combine(

let signed_tx = Transaction::from_generic_sig_data(
intent_msg.value,
Intent::sui_transaction(),
vec![GenericSignature::from_bytes(
&[&*flag, &*sig_bytes, &*pub_key].concat(),
)?],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ async fn test_transaction(
let response = client
.quorum_driver_api()
.execute_transaction_block(
Transaction::from_data(data.clone(), Intent::sui_transaction(), vec![signature]),
Transaction::from_data(data.clone(), vec![signature]),
SuiTransactionBlockResponseOptions::full_content(),
Some(ExecuteTransactionRequestType::WaitForLocalExecution),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ pub(crate) async fn sign_and_execute(
let transaction_response = match client
.quorum_driver_api()
.execute_transaction_block(
Transaction::from_data(txn_data, Intent::sui_transaction(), vec![signature]),
Transaction::from_data(txn_data, vec![signature]),
SuiTransactionBlockResponseOptions::new().with_effects(),
Some(request_type),
)
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-sdk/examples/programmable_transactions_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async fn main() -> Result<(), anyhow::Error> {
let transaction_response = sui
.quorum_driver_api()
.execute_transaction_block(
Transaction::from_data(tx_data, Intent::sui_transaction(), vec![signature]),
Transaction::from_data(tx_data, vec![signature]),
SuiTransactionBlockResponseOptions::full_content(),
Some(ExecuteTransactionRequestType::WaitForLocalExecution),
)
Expand Down
1 change: 0 additions & 1 deletion crates/sui-sdk/examples/sign_tx_guide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ async fn main() -> Result<(), anyhow::Error> {
.execute_transaction_block(
sui_types::transaction::Transaction::from_generic_sig_data(
intent_msg.value,
Intent::sui_transaction(),
vec![GenericSignature::Signature(sui_sig)],
),
SuiTransactionBlockResponseOptions::default(),
Expand Down
12 changes: 2 additions & 10 deletions crates/sui-sdk/examples/tic_tac_toe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ impl TicTacToe {
.client
.quorum_driver_api()
.execute_transaction_block(
Transaction::from_data(
create_game_call,
Intent::sui_transaction(),
vec![signature],
),
Transaction::from_data(create_game_call, vec![signature]),
SuiTransactionBlockResponseOptions::full_content(),
Some(ExecuteTransactionRequestType::WaitForLocalExecution),
)
Expand Down Expand Up @@ -207,11 +203,7 @@ impl TicTacToe {
.client
.quorum_driver_api()
.execute_transaction_block(
Transaction::from_data(
place_mark_call,
Intent::sui_transaction(),
vec![signature],
),
Transaction::from_data(place_mark_call, vec![signature]),
SuiTransactionBlockResponseOptions::new().with_effects(),
Some(ExecuteTransactionRequestType::WaitForLocalExecution),
)
Expand Down
8 changes: 4 additions & 4 deletions crates/sui-sdk/examples/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub const SUI_FAUCET: &str = "https://faucet.testnet.sui.io/v1/gas"; // testnet
///
/// By default, this function will set up a wallet locally if there isn't any, or reuse the
/// existing one and its active address. This function should be used when two addresses are needed,
/// e.g., transfering objects from one address to another.
/// e.g., transferring objects from one address to another.
pub async fn setup_for_write() -> Result<(SuiClient, SuiAddress, SuiAddress), anyhow::Error> {
let (client, active_address) = setup_for_read().await?;
// make sure we have some SUI (5_000_000 MIST) on this address
Expand Down Expand Up @@ -130,7 +130,7 @@ pub async fn request_tokens_from_faucet(

let mut coin_id = "".to_string();

// wait for the faucet to finsh the batch of token requests
// wait for the faucet to finish the batch of token requests
loop {
let resp = client
.get("https://faucet.testnet.sui.io/v1/status")
Expand Down Expand Up @@ -222,7 +222,7 @@ pub async fn split_coin_digest(
// get the reference gas price from the network
let gas_price = sui.read_api().get_reference_gas_price().await?;

// now we programatically build the transaction through several commands
// now we programmatically build the transaction through several commands
let mut ptb = ProgrammableTransactionBuilder::new();
// first, we want to split the coin, and we specify how much SUI (in MIST) we want
// for the new coin
Expand Down Expand Up @@ -259,7 +259,7 @@ pub async fn split_coin_digest(
let transaction_response = sui
.quorum_driver_api()
.execute_transaction_block(
Transaction::from_data(tx_data, Intent::sui_transaction(), vec![signature]),
Transaction::from_data(tx_data, vec![signature]),
SuiTransactionBlockResponseOptions::new(),
Some(ExecuteTransactionRequestType::WaitForLocalExecution),
)
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-sdk/src/wallet_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl WalletContext {
.sign_secure(&data.sender(), data, Intent::sui_transaction())
.unwrap();
// TODO: To support sponsored transaction, we should also look at the gas owner.
Transaction::from_data(data.clone(), Intent::sui_transaction(), vec![sig])
Transaction::from_data(data.clone(), vec![sig])
}

/// Execute a transaction and wait for it to be locally executed on the fullnode.
Expand Down
9 changes: 4 additions & 5 deletions crates/sui-test-transaction-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ impl TestTransactionBuilder {
}

pub fn build_and_sign(self, signer: &dyn Signer<Signature>) -> Transaction {
Transaction::from_data_and_signer(self.build(), Intent::sui_transaction(), vec![signer])
Transaction::from_data_and_signer(self.build(), vec![signer])
}

pub fn build_and_sign_multisig(
Expand All @@ -333,8 +333,7 @@ impl TestTransactionBuilder {
signers: &[&dyn Signer<Signature>],
) -> Transaction {
let data = self.build();
let intent = Intent::sui_transaction();
let intent_msg = IntentMessage::new(intent.clone(), data.clone());
let intent_msg = IntentMessage::new(Intent::sui_transaction(), data.clone());

let mut signatures = Vec::with_capacity(signers.len());
for signer in signers {
Expand All @@ -344,7 +343,7 @@ impl TestTransactionBuilder {
let multisig =
GenericSignature::MultiSig(MultiSig::combine(signatures, multisig_pk).unwrap());

Transaction::from_generic_sig_data(data, intent, vec![multisig])
Transaction::from_generic_sig_data(data, vec![multisig])
}

pub fn build_and_sign_multisig_legacy(
Expand All @@ -365,7 +364,7 @@ impl TestTransactionBuilder {
MultiSigLegacy::combine(signatures, multisig_pk).unwrap(),
);

Transaction::from_generic_sig_data(data, intent, vec![multisig])
Transaction::from_generic_sig_data(data, vec![multisig])
}
}

Expand Down
9 changes: 4 additions & 5 deletions crates/sui-types/src/messages_checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use once_cell::sync::OnceCell;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use shared_crypto::intent::{Intent, IntentScope};
use shared_crypto::intent::IntentScope;
use std::fmt::{Debug, Display, Formatter};
use std::slice::Iter;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
Expand Down Expand Up @@ -571,7 +571,6 @@ impl FullCheckpointContents {
100000000000,
100,
),
Intent::sui_transaction(),
vec![&key],
);
let effects = TransactionEffects::new_with_tx(&transaction);
Expand Down Expand Up @@ -801,8 +800,8 @@ mod tests {

// Tests that ConsensusCommitPrologue with different consensus commit digest will result in different checkpoint content.
#[test]
fn test_checkpoing_summary_with_different_consensus_digest() {
// First, tests that same consensus commit digest will procude the same checkpoint content.
fn test_checkpoint_summary_with_different_consensus_digest() {
// First, tests that same consensus commit digest will produce the same checkpoint content.
{
let t1 = VerifiedTransaction::new_consensus_commit_prologue_v2(
1,
Expand All @@ -821,7 +820,7 @@ mod tests {
assert_eq!(c1.digest(), c2.digest());
}

// Next, tests that different consensus commit digests will procude the different checkpoint contents.
// Next, tests that different consensus commit digests will produce the different checkpoint contents.
{
let t1 = VerifiedTransaction::new_consensus_commit_prologue_v2(
1,
Expand Down
Loading

0 comments on commit 7a858b0

Please sign in to comment.