Repository: public-awesome/launchpad
Pull request #521 (2023-03-06 22:44:12)

Revert "Fix Airdrop Claim Message"
Reverts public-awesome/launchpad#520


Patch:
diff --git a/contracts/sg-eth-airdrop/src/claim_airdrop.rs b/contracts/sg-eth-airdrop/src/claim_airdrop.rs
index 854e227c..05951292 100644
--- a/contracts/sg-eth-airdrop/src/claim_airdrop.rs
+++ b/contracts/sg-eth-airdrop/src/claim_airdrop.rs
@@ -19,7 +19,13 @@ pub fn claim_airdrop(
     eth_sig: String,
 ) -> Result<Response, ContractError> {
     let config = CONFIG.load(deps.storage)?;
-    validate_claim(&deps, eth_address.clone(), eth_sig, config.clone())?;
+    validate_claim(
+        &deps,
+        info.clone(),
+        eth_address.clone(),
+        eth_sig,
+        config.clone(),
+    )?;
     let res = claim_and_whitelist_add(&deps, info, config.airdrop_amount)?;
     increment_local_mint_count_for_address(deps, eth_address)?;
 
@@ -86,18 +92,23 @@ mod validation {
         state::Config,
     };
 
-    pub fn compute_plaintext_msg(config: &Config, eth_address: &str) -> String {
-        str::replace(&config.claim_msg_plaintext, "{wallet}", eth_address)
+    pub fn compute_plaintext_msg(config: &Config, info: MessageInfo) -> String {
+        str::replace(
+            &config.claim_msg_plaintext,
+            "{wallet}",
+            info.sender.as_ref(),
+        )
     }
 
     pub fn validate_claim(
         deps: &DepsMut,
+        info: MessageInfo,
         eth_address: String,
         eth_sig: String,
         config: Config,
     ) -> Result<(), ContractError> {
         validate_is_eligible(deps, eth_address.clone())?;
-        validate_eth_sig(deps, eth_address.clone(), eth_sig, config)?;
+        validate_eth_sig(deps, info, eth_address.clone(), eth_sig, config)?;
         validate_mints_remaining(deps, &eth_address)?;
         Ok(())
     }
@@ -114,11 +125,13 @@ mod validation {
 
     fn validate_eth_sig(
         deps: &DepsMut,
+        info: MessageInfo,
         eth_address: String,
         eth_sig: String,
         config: Config,
     ) -> Result<(), ContractError> {
-        let valid_eth_sig = validate_ethereum_text(deps, &config, eth_sig, eth_address.clone())?;
+        let valid_eth_sig =
+            validate_ethereum_text(deps, info, &config, eth_sig, eth_address.clone())?;
         match valid_eth_sig {
             true => Ok(()),
             false => Err(ContractError::AddressNotEligible {
@@ -145,11 +158,12 @@ mod validation {
 
     pub fn validate_ethereum_text(
         deps: &DepsMut,
+        info: MessageInfo,
         config: &Config,
         eth_sig: String,
         eth_address: String,
     ) -> StdResult<bool> {
-        let plaintext_msg = compute_plaintext_msg(config, &eth_address);
+        let plaintext_msg = compute_plaintext_msg(config, info);
         match hex::decode(eth_sig.clone()) {
             Ok(eth_sig_hex) => {
                 verify_ethereum_text(deps.as_ref(), &plaintext_msg, &eth_sig_hex, &eth_address)


Test patch:
diff --git a/test-suite/src/sg_eth_airdrop/constants/claim_constants.rs b/test-suite/src/sg_eth_airdrop/constants/claim_constants.rs
index 2a3a0bca..674d6678 100644
--- a/test-suite/src/sg_eth_airdrop/constants/claim_constants.rs
+++ b/test-suite/src/sg_eth_airdrop/constants/claim_constants.rs
@@ -3,5 +3,5 @@ pub const MOCK_AIRDROP_ADDR_STR: &str = "contract3";
 pub const MOCK_MINTER_ADDR_STR: &str = "contract1";
 pub const STARGAZE_WALLET_01: &str = "0xstargaze_wallet_01";
 pub const STARGAZE_WALLET_02: &str = "0xstargaze_wallet_02";
-pub const CONFIG_PLAINTEXT: &str = "My wallet is {wallet}, sign me up and rest in peace";
+pub const CONFIG_PLAINTEXT: &str = "My Stargaze address is {wallet} and I want a Winter Pal.";
 pub const NATIVE_DENOM: &str = "ustars";
diff --git a/test-suite/src/sg_eth_airdrop/setup/setup_signatures.rs b/test-suite/src/sg_eth_airdrop/setup/setup_signatures.rs
index 2e5796c7..2b1e7236 100644
--- a/test-suite/src/sg_eth_airdrop/setup/setup_signatures.rs
+++ b/test-suite/src/sg_eth_airdrop/setup/setup_signatures.rs
@@ -10,21 +10,21 @@ pub async fn get_signature(
     wallet.sign_message(plaintext_msg).await
 }
 
-pub fn get_wallet_and_sig() -> (
+pub fn get_wallet_and_sig(
+    claim_plaintext: String,
+) -> (
     Wallet<ethers_core::k256::ecdsa::SigningKey>,
     std::string::String,
     H160,
     std::string::String,
 ) {
     let wallet = LocalWallet::new(&mut thread_rng());
-    let eth_addr = wallet.address();
-    let eth_addr_str = format!("{:?}", wallet.address());
-    let claim_plaintext = get_msg_plaintext(eth_addr_str.clone());
     let eth_sig_str = task::block_on(get_signature(wallet.clone(), &claim_plaintext))
         .unwrap()
         .to_string();
-
-    (wallet, eth_sig_str, eth_addr, eth_addr_str)
+    let eth_address = wallet.address();
+    let eth_addr_str = format!("{:?}", eth_address);
+    (wallet, eth_sig_str, eth_address, eth_addr_str)
 }
 
 pub fn get_msg_plaintext(wallet_address: String) -> String {
diff --git a/test-suite/src/sg_eth_airdrop/tests/test_claim.rs b/test-suite/src/sg_eth_airdrop/tests/test_claim.rs
index ac2b7768..671c9552 100644
--- a/test-suite/src/sg_eth_airdrop/tests/test_claim.rs
+++ b/test-suite/src/sg_eth_airdrop/tests/test_claim.rs
@@ -37,7 +37,8 @@ fn query_minter_as_expected(app: &mut StargazeApp, airdrop_contract: Addr, minte
 fn test_instantiate() {
     let mut app = custom_mock_app();
     let minter_address = Addr::unchecked("contract1");
-    let (_, _, _, eth_addr_str) = get_wallet_and_sig();
+    let claim_plaintext = &get_msg_plaintext(STARGAZE_WALLET_01.to_string());
+    let (_, _, _, eth_addr_str) = get_wallet_and_sig(claim_plaintext.clone());
     let params = InstantiateParams {
         addresses: vec![eth_addr_str],
         funds_amount: WHITELIST_AMOUNT + INSTANTIATION_FEE,
@@ -56,7 +57,8 @@ fn test_instantiate_plaintext_too_long() {
     let long_config_plaintext: String = String::from_utf8(vec![b'X'; 1001]).unwrap() + " {wallet}";
     let mut app = custom_mock_app();
     let minter_address = Addr::unchecked("contract1");
-    let (_, _, _, eth_addr_str) = get_wallet_and_sig();
+    let claim_plaintext = &get_msg_plaintext(STARGAZE_WALLET_01.to_string());
+    let (_, _, _, eth_addr_str) = get_wallet_and_sig(claim_plaintext.clone());
     let params = InstantiateParams {
         addresses: vec![eth_addr_str],
         funds_amount: WHITELIST_AMOUNT + INSTANTIATION_FEE,
@@ -76,10 +78,11 @@ fn test_instantiate_plaintext_too_long() {
 
 #[test]
 fn test_instantiate_plaintext_missing_wallet() {
-    let config_plaintext = "This message doesn't have wallet string";
+    let plaintext_config_no_wallet = "This message doesn't have wallet string".to_string();
     let mut app = custom_mock_app();
     let minter_address = Addr::unchecked("contract1");
-    let (_, _, _, eth_addr_str) = get_wallet_and_sig();
+    let claim_plaintext = &get_msg_plaintext(STARGAZE_WALLET_01.to_string());
+    let (_, _, _, eth_addr_str) = get_wallet_and_sig(claim_plaintext.clone());
     let params = InstantiateParams {
         addresses: vec![eth_addr_str],
         funds_amount: WHITELIST_AMOUNT + INSTANTIATION_FEE,
@@ -88,7 +91,7 @@ fn test_instantiate_plaintext_missing_wallet() {
         admin_account: Addr::unchecked(OWNER),
         app: &mut app,
         per_address_limit: 1,
-        claim_msg_plaintext: config_plaintext.to_string(),
+        claim_msg_plaintext: plaintext_config_no_wallet,
     };
     let res = instantiate_contract(params).unwrap_err();
     assert_eq!(
@@ -139,7 +142,8 @@ fn test_airdrop_eligible_query() {
 
 #[test]
 fn test_valid_eth_sig_claim() {
-    let (_, eth_sig_str, _, eth_addr_str) = get_wallet_and_sig();
+    let claim_plaintext = &get_msg_plaintext(STARGAZE_WALLET_01.to_string());
+    let (_, eth_sig_str, _, eth_addr_str) = get_wallet_and_sig(claim_plaintext.clone());
     let mut app = custom_mock_app();
     configure_mock_minter_with_mock_whitelist(&mut app);
     let minter_addr = Addr::unchecked(MOCK_MINTER_ADDR_STR);
@@ -185,8 +189,9 @@ fn test_valid_eth_sig_claim() {
 
 #[test]
 fn test_invalid_eth_sig_claim() {
-    let (_, _, _, eth_addr_str) = get_wallet_and_sig();
-    let (_, eth_sig_str_2, _, _) = get_wallet_and_sig();
+    let claim_plaintext = &get_msg_plaintext(STARGAZE_WALLET_01.to_string());
+    let (_, _, _, eth_addr_str) = get_wallet_and_sig(claim_plaintext.clone());
+    let (_, eth_sig_str_2, _, _) = get_wallet_and_sig(claim_plaintext.clone());
 
     let mut app = custom_mock_app();
     configure_mock_minter_with_mock_whitelist(&mut app);
@@ -221,7 +226,8 @@ fn test_invalid_eth_sig_claim() {
 
 #[test]
 fn test_can_not_claim_twice() {
-    let (_, eth_sig_str, _, eth_addr_str) = get_wallet_and_sig();
+    let claim_plaintext = &get_msg_plaintext(STARGAZE_WALLET_01.to_string());
+    let (_, eth_sig_str, _, eth_addr_str) = get_wallet_and_sig(claim_plaintext.clone());
 
     let mut app = custom_mock_app();
     configure_mock_minter_with_mock_whitelist(&mut app);
@@ -279,7 +285,8 @@ fn test_can_not_claim_twice() {
 
 #[test]
 fn test_claim_one_valid_airdrop() {
-    let (_, eth_sig_str, _, eth_addr_str) = get_wallet_and_sig();
+    let claim_plaintext = &get_msg_plaintext(STARGAZE_WALLET_01.to_string());
+    let (_, eth_sig_str, _, eth_addr_str) = get_wallet_and_sig(claim_plaintext.clone());
 
     let stargaze_wallet_01 = Addr::unchecked(STARGAZE_WALLET_01);
 
@@ -328,7 +335,8 @@ fn test_claim_one_valid_airdrop() {
 
 #[test]
 fn test_claim_twice_receive_funds_once() {
-    let (_, eth_sig_str, _, eth_addr_str) = get_wallet_and_sig();
+    let claim_plaintext = &get_msg_plaintext(STARGAZE_WALLET_01.to_string());
+    let (_, eth_sig_str, _, eth_addr_str) = get_wallet_and_sig(claim_plaintext.clone());
 
     let stargaze_wallet_01 = Addr::unchecked(STARGAZE_WALLET_01);
     let mut app = custom_mock_app();
@@ -397,7 +405,8 @@ fn test_claim_twice_receive_funds_once() {
 
 #[test]
 fn test_ineligible_does_not_receive_funds() {
-    let (_, _, _, eth_addr_str) = get_wallet_and_sig();
+    let claim_plaintext = &get_msg_plaintext(STARGAZE_WALLET_01.to_string());
+    let (_, _, _, eth_addr_str) = get_wallet_and_sig(claim_plaintext.clone());
 
     let mut app = custom_mock_app();
     configure_mock_minter_with_mock_whitelist(&mut app);
@@ -423,7 +432,8 @@ fn test_ineligible_does_not_receive_funds() {
         .unwrap();
     assert_eq!(balances, []);
 
-    let (_, eth_sig_str_2, _, eth_addr_str_2) = get_wallet_and_sig();
+    let claim_plaintext_2 = &get_msg_plaintext(STARGAZE_WALLET_02.to_string());
+    let (_, eth_sig_str_2, _, eth_addr_str_2) = get_wallet_and_sig(claim_plaintext_2.clone());
 
     let claim_message = ExecuteMsg::ClaimAirdrop {
         eth_address: eth_addr_str_2.clone(),
@@ -448,12 +458,12 @@ fn test_one_eth_claim_two_stargaze_addresses_invalid() {
     let stargaze_wallet_01 = Addr::unchecked(STARGAZE_WALLET_01);
     let stargaze_wallet_02 = Addr::unchecked(STARGAZE_WALLET_02);
 
-    let eth_address = wallet_1.address();
-    let eth_addr_str_1 = format!("{:?}", eth_address);
-    let claim_plaintext_1 = &get_msg_plaintext(eth_addr_str_1.clone());
+    let claim_plaintext_1 = &get_msg_plaintext(STARGAZE_WALLET_01.to_string());
     let eth_sig_str_1 = task::block_on(get_signature(wallet_1.clone(), claim_plaintext_1))
         .unwrap()
         .to_string();
+    let eth_address = wallet_1.address();
+    let eth_addr_str_1 = format!("{:?}", eth_address);
 
     let mut app = custom_mock_app();
     configure_mock_minter_with_mock_whitelist(&mut app);
@@ -497,7 +507,7 @@ fn test_one_eth_claim_two_stargaze_addresses_invalid() {
     ];
     assert_eq!(res.events[1].attributes, expected_attributes);
 
-    let claim_plaintext_2 = &get_msg_plaintext(eth_addr_str_1.to_string());
+    let claim_plaintext_2 = &get_msg_plaintext(STARGAZE_WALLET_02.to_string());
     let eth_sig_str_2 = task::block_on(get_signature(wallet_1, claim_plaintext_2))
         .unwrap()
         .to_string();
@@ -522,7 +532,8 @@ fn test_one_eth_claim_two_stargaze_addresses_invalid() {
 
 #[test]
 fn test_two_claims_allowed_success() {
-    let (_, eth_sig_str, _, eth_addr_str) = get_wallet_and_sig();
+    let claim_plaintext = &get_msg_plaintext(STARGAZE_WALLET_01.to_string());
+    let (_, eth_sig_str, _, eth_addr_str) = get_wallet_and_sig(claim_plaintext.clone());
 
     let stargaze_wallet_01 = Addr::unchecked(STARGAZE_WALLET_01);
 
diff --git a/test-suite/src/sg_eth_airdrop/tests/test_collection_whitelist.rs b/test-suite/src/sg_eth_airdrop/tests/test_collection_whitelist.rs
index ae604679..808287f8 100644
--- a/test-suite/src/sg_eth_airdrop/tests/test_collection_whitelist.rs
+++ b/test-suite/src/sg_eth_airdrop/tests/test_collection_whitelist.rs
@@ -9,7 +9,7 @@ use crate::sg_eth_airdrop::setup::collection_whitelist_helpers::{
     send_funds_to_address, update_admin_for_whitelist,
 };
 use crate::sg_eth_airdrop::setup::execute_msg::instantiate_contract;
-use crate::sg_eth_airdrop::setup::setup_signatures::get_wallet_and_sig;
+use crate::sg_eth_airdrop::setup::setup_signatures::{get_msg_plaintext, get_wallet_and_sig};
 use crate::sg_eth_airdrop::setup::test_msgs::InstantiateParams;
 use cosmwasm_std::Addr;
 use sg_eth_airdrop::msg::QueryMsg;
@@ -24,7 +24,8 @@ fn test_set_minter_contract_success() {
     let (mut app, creator) = (vt.router, vt.accts.creator);
     let minter_addr = vt.collection_response_vec[0].minter.clone().unwrap();
 
-    let (_, _, _, eth_addr_str) = get_wallet_and_sig();
+    let claim_plaintext = &get_msg_plaintext(STARGAZE_WALLET_01.to_string());
+    let (_, _, _, eth_addr_str) = get_wallet_and_sig(claim_plaintext.clone());
 
     let contract_admin = Addr::unchecked(creator);
     let params = InstantiateParams {
@@ -55,7 +56,8 @@ fn test_claim_added_to_minter_whitelist() {
     let whitelist_addr =
         configure_collection_whitelist(&mut app, creator.clone(), buyer, minter_addr.clone());
     setup_block_time(&mut app, GENESIS_MINT_START_TIME, None);
-    let (_, eth_sig_str, _, eth_addr_str) = get_wallet_and_sig();
+    let claim_plaintext = &get_msg_plaintext(STARGAZE_WALLET_01.to_string());
+    let (_, eth_sig_str, _, eth_addr_str) = get_wallet_and_sig(claim_plaintext.clone());
 
     let airdrop_contract = Addr::unchecked(AIRDROP_ADDR_STR);
     let params = InstantiateParams {