diff --git a/src/cairo/test_utils.cairo b/src/cairo/test_utils.cairo index 2c2d8e8..8fe8b5d 100644 --- a/src/cairo/test_utils.cairo +++ b/src/cairo/test_utils.cairo @@ -546,6 +546,7 @@ mod test_utils { token_bridge_address: ContractAddress, l1_bridge_address: EthAddress, l1_token: EthAddress, + depositor: EthAddress, l2_recipient: ContractAddress, amount_to_deposit: u256 ) { @@ -556,6 +557,7 @@ mod test_utils { ref token_bridge_state, from_address: l1_bridge_address.into(), :l1_token, + :depositor, :l2_recipient, amount: amount_to_deposit ); diff --git a/src/cairo/token_bridge.cairo b/src/cairo/token_bridge.cairo index 7c2b3b9..a0dceed 100644 --- a/src/cairo/token_bridge.cairo +++ b/src/cairo/token_bridge.cairo @@ -1013,6 +1013,7 @@ mod TokenBridge { ref self: ContractState, from_address: felt252, l1_token: EthAddress, + depositor: EthAddress, l2_recipient: ContractAddress, amount: u256, ) { @@ -1029,9 +1030,9 @@ mod TokenBridge { ref self: ContractState, from_address: felt252, l1_token: EthAddress, + depositor: EthAddress, l2_recipient: ContractAddress, amount: u256, - depositor: EthAddress, message: Span, ) { // Verify deposit originating from the l1 bridge. diff --git a/src/cairo/token_bridge_admin_test.cairo b/src/cairo/token_bridge_admin_test.cairo index b1c9bbb..669c32f 100644 --- a/src/cairo/token_bridge_admin_test.cairo +++ b/src/cairo/token_bridge_admin_test.cairo @@ -24,6 +24,7 @@ mod token_bridge_admin_test { ITokenBridgeAdminDispatcher, ITokenBridgeAdminDispatcherTrait }; + const DEFAULT_DEPOSITOR_ETH_ADDRESS: felt252 = 7; // TODO change the name of deploy_and_prepare. // Deploys the token bridge and sets the caller as the App Governer (and as App Role Admin). @@ -189,14 +190,19 @@ mod token_bridge_admin_test { #[available_gas(30000000)] fn test_successful_initiate_token_withdraw_with_limits_one_withdrawal() { let (l1_bridge_address, l1_token, l1_recipient) = get_default_l1_addresses(); - + let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS }; let token_bridge_address = deploy_token_bridge(); // Deploy a new token and deposit funds to this token. let l2_recipient = initial_owner(); let amount_to_deposit = default_amount(); deploy_new_token_and_deposit( - :token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit + :token_bridge_address, + :l1_bridge_address, + :l1_token, + :depositor, + :l2_recipient, + :amount_to_deposit ); enable_withdrawal_limit(:token_bridge_address, :l1_token); @@ -218,14 +224,19 @@ mod token_bridge_admin_test { #[available_gas(30000000)] fn test_successful_initiate_token_withdraw_with_limits_two_withdrawals() { let (l1_bridge_address, l1_token, l1_recipient) = get_default_l1_addresses(); - + let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS }; let token_bridge_address = deploy_token_bridge(); // Deploy a new token and deposit funds to this token. let l2_recipient = initial_owner(); let amount_to_deposit = default_amount(); deploy_new_token_and_deposit( - :token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit + :token_bridge_address, + :l1_bridge_address, + :l1_token, + :depositor, + :l2_recipient, + :amount_to_deposit ); enable_withdrawal_limit(:token_bridge_address, :l1_token); @@ -258,14 +269,19 @@ mod token_bridge_admin_test { #[available_gas(30000000)] fn test_successful_initiate_token_withdraw_with_and_without_limits() { let (l1_bridge_address, l1_token, l1_recipient) = get_default_l1_addresses(); - + let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS }; let token_bridge_address = deploy_token_bridge(); // Deploy a new token and deposit funds to this token. let l2_recipient = initial_owner(); let amount_to_deposit = default_amount(); deploy_new_token_and_deposit( - :token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit + :token_bridge_address, + :l1_bridge_address, + :l1_token, + :depositor, + :l2_recipient, + :amount_to_deposit ); enable_withdrawal_limit(:token_bridge_address, :l1_token); @@ -312,14 +328,19 @@ mod token_bridge_admin_test { #[should_panic(expected: ('LIMIT_EXCEEDED', 'ENTRYPOINT_FAILED',))] fn test_failed_initiate_token_withdraw_with_and_without_limits() { let (l1_bridge_address, l1_token, l1_recipient) = get_default_l1_addresses(); - + let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS }; let token_bridge_address = deploy_token_bridge(); // Deploy a new token and deposit funds to this token. let l2_recipient = initial_owner(); let amount_to_deposit = default_amount(); deploy_new_token_and_deposit( - :token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit + :token_bridge_address, + :l1_bridge_address, + :l1_token, + :depositor, + :l2_recipient, + :amount_to_deposit ); enable_withdrawal_limit(:token_bridge_address, :l1_token); @@ -357,7 +378,7 @@ mod token_bridge_admin_test { #[available_gas(30000000)] fn test_successful_initiate_token_withdraw_with_limits_different_days() { let (l1_bridge_address, l1_token, l1_recipient) = get_default_l1_addresses(); - + let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS }; let token_bridge_address = deploy_token_bridge(); set_caller_as_app_role_admin_app_governor(:token_bridge_address); let token_bridge_admin = get_token_bridge_admin(:token_bridge_address); @@ -367,7 +388,12 @@ mod token_bridge_admin_test { let l2_recipient = initial_owner(); let amount_to_deposit = default_amount(); deploy_new_token_and_deposit( - :token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit + :token_bridge_address, + :l1_bridge_address, + :l1_token, + :depositor, + :l2_recipient, + :amount_to_deposit ); enable_withdrawal_limit(:token_bridge_address, :l1_token); @@ -406,14 +432,19 @@ mod token_bridge_admin_test { #[available_gas(30000000)] fn test_successful_initiate_token_withdraw_with_limits_same_day_differnet_time() { let (l1_bridge_address, l1_token, l1_recipient) = get_default_l1_addresses(); - + let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS }; let token_bridge_address = deploy_token_bridge(); // Deploy a new token and deposit funds to this token. let l2_recipient = initial_owner(); let amount_to_deposit = default_amount(); deploy_new_token_and_deposit( - :token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit + :token_bridge_address, + :l1_bridge_address, + :l1_token, + :depositor, + :l2_recipient, + :amount_to_deposit ); enable_withdrawal_limit(:token_bridge_address, :l1_token); @@ -453,14 +484,19 @@ mod token_bridge_admin_test { #[should_panic(expected: ('LIMIT_EXCEEDED', 'ENTRYPOINT_FAILED',))] fn test_failed_initiate_token_withdraw_limit_exceeded_one_withdrawal() { let (l1_bridge_address, l1_token, l1_recipient) = get_default_l1_addresses(); - + let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS }; let token_bridge_address = deploy_token_bridge(); // Deploy a new token and deposit funds to this token. let l2_recipient = initial_owner(); let amount_to_deposit = default_amount(); deploy_new_token_and_deposit( - :token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit + :token_bridge_address, + :l1_bridge_address, + :l1_token, + :depositor, + :l2_recipient, + :amount_to_deposit ); enable_withdrawal_limit(:token_bridge_address, :l1_token); @@ -481,14 +517,19 @@ mod token_bridge_admin_test { #[should_panic(expected: ('LIMIT_EXCEEDED', 'ENTRYPOINT_FAILED',))] fn test_failed_initiate_token_withdraw_limit_exceeded_two_withdrawals() { let (l1_bridge_address, l1_token, l1_recipient) = get_default_l1_addresses(); - + let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS }; let token_bridge_address = deploy_token_bridge(); // Deploy a new token and deposit funds to this token. let l2_recipient = initial_owner(); let amount_to_deposit = default_amount(); deploy_new_token_and_deposit( - :token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit + :token_bridge_address, + :l1_bridge_address, + :l1_token, + :depositor, + :l2_recipient, + :amount_to_deposit ); enable_withdrawal_limit(:token_bridge_address, :l1_token); @@ -517,14 +558,19 @@ mod token_bridge_admin_test { #[should_panic(expected: ('LIMIT_EXCEEDED', 'ENTRYPOINT_FAILED',))] fn test_failed_initiate_token_withdraw_limit_exceeded_same_day_different_time() { let (l1_bridge_address, l1_token, l1_recipient) = get_default_l1_addresses(); - + let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS }; let token_bridge_address = deploy_token_bridge(); // Deploy a new token and deposit funds to this token. let l2_recipient = initial_owner(); let amount_to_deposit = default_amount(); deploy_new_token_and_deposit( - :token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit + :token_bridge_address, + :l1_bridge_address, + :l1_token, + :depositor, + :l2_recipient, + :amount_to_deposit ); // Limit the withdrawal amount. diff --git a/src/cairo/token_bridge_test.cairo b/src/cairo/token_bridge_test.cairo index 01ac54e..2d32c10 100644 --- a/src/cairo/token_bridge_test.cairo +++ b/src/cairo/token_bridge_test.cairo @@ -83,9 +83,9 @@ mod token_bridge_test { ref token_bridge_state, from_address: l1_bridge_address.into(), :l1_token, + :depositor, :l2_recipient, amount: amount_to_deposit, - :depositor, :message ); } @@ -270,14 +270,19 @@ mod token_bridge_test { #[available_gas(30000000)] fn test_successful_initiate_token_withdraw() { let (l1_bridge_address, l1_token, l1_recipient) = get_default_l1_addresses(); - + let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS }; let token_bridge_address = deploy_token_bridge(); // Deploy a new token and deposit funds to this token. let l2_recipient = initial_owner(); let amount_to_deposit = default_amount(); deploy_new_token_and_deposit( - :token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit + :token_bridge_address, + :l1_bridge_address, + :l1_token, + :depositor, + :l2_recipient, + :amount_to_deposit ); // Initiate withdraw (set the caller to be the initial_owner). @@ -302,12 +307,18 @@ mod token_bridge_test { let l1_recipient = EthAddress { address: 0 }; let token_bridge_address = deploy_token_bridge(); + let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS }; // Deploy a new token and deposit funds to this token. let l2_recipient = initial_owner(); let amount_to_deposit = default_amount(); deploy_new_token_and_deposit( - :token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit + :token_bridge_address, + :l1_bridge_address, + :l1_token, + :depositor, + :l2_recipient, + :amount_to_deposit ); // Should panic because the recipient is invalid. @@ -327,6 +338,8 @@ mod token_bridge_test { let (l1_bridge_address, l1_token, l1_recipient) = get_default_l1_addresses(); let token_bridge_address = deploy_token_bridge(); let token_bridge = get_token_bridge(:token_bridge_address); + let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS }; + // The token does not exist; hence, there is no withdrawal limit applied. Therefore, the // quota is max. assert( @@ -338,7 +351,12 @@ mod token_bridge_test { let l2_recipient = initial_owner(); let amount_to_deposit = default_amount(); deploy_new_token_and_deposit( - :token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit + :token_bridge_address, + :l1_bridge_address, + :l1_token, + :depositor, + :l2_recipient, + :amount_to_deposit ); // By default, the withdrawal limit is off; hence, the quota is max. assert( @@ -389,12 +407,18 @@ mod token_bridge_test { let token_bridge_address = deploy_token_bridge(); let token_bridge = get_token_bridge(:token_bridge_address); + let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS }; // Deploy a new token and deposit funds to this token. let l2_recipient = initial_owner(); let amount_to_deposit = default_amount(); deploy_new_token_and_deposit( - :token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit + :token_bridge_address, + :l1_bridge_address, + :l1_token, + :depositor, + :l2_recipient, + :amount_to_deposit ); let l2_token = token_bridge.get_l2_token(:l1_token); starknet::testing::set_contract_address(address: token_bridge_address); @@ -644,12 +668,18 @@ mod token_bridge_test { let (l1_bridge_address, l1_token, l1_recipient) = get_default_l1_addresses(); let token_bridge_address = deploy_token_bridge(); + let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS }; // Deploy a new token and deposit funds to this token. let l2_recipient = initial_owner(); let amount_to_deposit = default_amount(); deploy_new_token_and_deposit( - :token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit + :token_bridge_address, + :l1_bridge_address, + :l1_token, + :depositor, + :l2_recipient, + :amount_to_deposit ); // Initiate withdraw. @@ -665,12 +695,18 @@ mod token_bridge_test { let (l1_bridge_address, l1_token, l1_recipient) = get_default_l1_addresses(); let token_bridge_address = deploy_token_bridge(); + let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS }; // Deploy a new token and deposit funds to this token. let l2_recipient = initial_owner(); let amount_to_deposit = default_amount(); deploy_new_token_and_deposit( - :token_bridge_address, :l1_bridge_address, :l1_token, :l2_recipient, :amount_to_deposit + :token_bridge_address, + :l1_bridge_address, + :l1_token, + :depositor, + :l2_recipient, + :amount_to_deposit ); // Initiate withdraw. @@ -685,6 +721,7 @@ mod token_bridge_test { let (l1_bridge_address, l1_token, _) = get_default_l1_addresses(); let token_bridge_address = deploy_token_bridge(); + let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS }; // Deploy a new token and deposit funds to this token. let l2_recipient = initial_owner(); @@ -693,6 +730,7 @@ mod token_bridge_test { :token_bridge_address, :l1_bridge_address, :l1_token, + :depositor, :l2_recipient, amount_to_deposit: first_amount ); @@ -709,6 +747,7 @@ mod token_bridge_test { ref token_bridge_state, from_address: l1_bridge_address.into(), :l1_token, + :depositor, :l2_recipient, amount: second_amount ); @@ -854,6 +893,7 @@ mod token_bridge_test { // Set an arbitrary l1 bridge address. let l1_bridge_address = EthAddress { address: DEFAULT_L1_BRIDGE_ETH_ADDRESS }; + let depositor = EthAddress { address: DEFAULT_DEPOSITOR_ETH_ADDRESS }; // Deploy token contract. let initial_owner = initial_owner(); @@ -879,6 +919,7 @@ mod token_bridge_test { ref token_bridge_state, from_address: l1_not_bridge_address.into(), l1_token: l1_bridge_address, + :depositor, l2_recipient: initial_owner, amount: default_amount() ); diff --git a/src/solidity/LegacyBridge.sol b/src/solidity/LegacyBridge.sol index 34777cc..6ab2b4f 100644 --- a/src/solidity/LegacyBridge.sol +++ b/src/solidity/LegacyBridge.sol @@ -35,6 +35,15 @@ abstract contract LegacyBridge is StarknetTokenBridge, OverrideLegacyProxyGovern return NamedStorage.getAddressValue(BRIDGED_TOKEN_TAG); } + function depositors() internal pure returns (mapping(uint256 => address) storage) { + return NamedStorage.uintToAddressMapping(DEPOSITOR_ADDRESSES_TAG); + } + + modifier onlyDepositor(uint256 nonce) { + require(depositors()[nonce] == msg.sender, "ONLY_DEPOSITOR"); + _; + } + /* Upgraded legacy bridge does not support token enrollment. */ diff --git a/src/solidity/StarknetTokenBridge.sol b/src/solidity/StarknetTokenBridge.sol index 758f82d..dbe244b 100644 --- a/src/solidity/StarknetTokenBridge.sol +++ b/src/solidity/StarknetTokenBridge.sol @@ -86,9 +86,11 @@ contract StarknetTokenBridge is ); event WithdrawalLimitEnabled(address indexed sender, address indexed token); event WithdrawalLimitDisabled(address indexed sender, address indexed token); + uint256 constant N_DEPOSIT_PAYLOAD_ARGS = 5; + uint256 constant DEPOSIT_MESSAGE_FIXED_SIZE = 1; function identify() external pure virtual returns (string memory) { - return "StarkWare_StarknetTokenBridge_2.0_2"; + return "StarkWare_StarknetTokenBridge_2.0_3"; } function validateInitData(bytes calldata data) internal view virtual override { @@ -122,13 +124,6 @@ contract StarknetTokenBridge is return 0; } - modifier onlyDepositor(uint256 nonce) { - address depositor_ = depositors()[nonce]; - require(depositor_ != address(0x0), "NO_DEPOSIT_TO_CANCEL"); - require(depositor_ == msg.sender, "ONLY_DEPOSITOR"); - _; - } - modifier onlyManager() { require(manager() == msg.sender, "ONLY_MANAGER"); _; @@ -390,9 +385,6 @@ contract StarknetTokenBridge is return payload; } - uint256 constant ARGUMENT_SIZE = 4; - uint256 constant MESSAGE_METADATA_SIZE = 2; - function depositMessagePayload( address token, uint256 amount, @@ -401,15 +393,15 @@ contract StarknetTokenBridge is uint256[] memory message ) private view returns (uint256[] memory) { uint256 MESSAGE_OFFSET = withMessage - ? ARGUMENT_SIZE + MESSAGE_METADATA_SIZE - : ARGUMENT_SIZE; + ? N_DEPOSIT_PAYLOAD_ARGS + DEPOSIT_MESSAGE_FIXED_SIZE + : N_DEPOSIT_PAYLOAD_ARGS; uint256[] memory payload = new uint256[](MESSAGE_OFFSET + message.length); payload[0] = uint256(uint160(token)); - payload[1] = l2Recipient; - payload[2] = amount & (UINT256_PART_SIZE - 1); - payload[3] = amount >> UINT256_PART_SIZE_BITS; + payload[1] = uint256(uint160(msg.sender)); + payload[2] = l2Recipient; + payload[3] = amount & (UINT256_PART_SIZE - 1); + payload[4] = amount >> UINT256_PART_SIZE_BITS; if (withMessage) { - payload[MESSAGE_OFFSET - 2] = uint256(uint160(msg.sender)); payload[MESSAGE_OFFSET - 1] = message.length; for (uint256 i = 0; i < message.length; i++) { require(message[i].isFelt(), "INVALID_MESSAGE_DATA"); @@ -465,8 +457,6 @@ contract StarknetTokenBridge is selector, depositMessagePayload(token, amount, l2Recipient, isWithMsg, message) ); - require(depositors()[nonce] == address(0x0), "DEPOSIT_ALREADY_REGISTERED"); - depositors()[nonce] = msg.sender; // The function exclusively supports two specific selectors, and any attempt to use an unknown // selector will result in a transaction failure. @@ -527,7 +517,7 @@ contract StarknetTokenBridge is uint256 amount, uint256 l2Recipient, uint256 nonce - ) external onlyDepositor(nonce) { + ) external { messagingContract().startL1ToL2MessageCancellation( l2TokenBridge(), HANDLE_TOKEN_DEPOSIT_SELECTOR, @@ -547,7 +537,7 @@ contract StarknetTokenBridge is uint256 l2Recipient, uint256[] calldata message, uint256 nonce - ) external onlyDepositor(nonce) { + ) external { messagingContract().startL1ToL2MessageCancellation( l2TokenBridge(), HANDLE_DEPOSIT_WITH_MESSAGE_SELECTOR, @@ -577,7 +567,7 @@ contract StarknetTokenBridge is uint256 l2Recipient, uint256[] calldata message, uint256 nonce - ) external onlyDepositor(nonce) { + ) external { messagingContract().cancelL1ToL2Message( l2TokenBridge(), HANDLE_DEPOSIT_WITH_MESSAGE_SELECTOR, @@ -600,7 +590,7 @@ contract StarknetTokenBridge is uint256 amount, uint256 l2Recipient, uint256 nonce - ) external onlyDepositor(nonce) { + ) external { messagingContract().cancelL1ToL2Message( l2TokenBridge(), HANDLE_TOKEN_DEPOSIT_SELECTOR, diff --git a/src/solidity/StarknetTokenStorage.sol b/src/solidity/StarknetTokenStorage.sol index dd36277..e9263e8 100644 --- a/src/solidity/StarknetTokenStorage.sol +++ b/src/solidity/StarknetTokenStorage.sol @@ -54,10 +54,6 @@ abstract contract StarknetTokenStorage { return IStarknetMessaging(NamedStorage.getAddressValue(MESSAGING_CONTRACT_TAG)); } - function depositors() internal pure returns (mapping(uint256 => address) storage) { - return NamedStorage.uintToAddressMapping(DEPOSITOR_ADDRESSES_TAG); - } - // Storage Setters. function setManager(address contract_) internal { NamedStorage.setAddressValueOnce(MANAGER_TAG, contract_); diff --git a/src/solidity/token_bridge_test.py b/src/solidity/token_bridge_test.py index 0c79004..20a4548 100644 --- a/src/solidity/token_bridge_test.py +++ b/src/solidity/token_bridge_test.py @@ -379,6 +379,7 @@ def test_deposit_message_sent_consumed( token_bridge_wrapper: TokenBridgeWrapper, messaging_contract ): fee = DEFAULT_DEPOSIT_FEE + depositor = int(token_bridge_wrapper.default_user.address, 16) setup_contracts(token_bridge_wrapper=token_bridge_wrapper) token_bridge_wrapper.deposit(amount=HALF_DEPOSIT_AMOUNT, l2_recipient=L2_RECIPIENT, fee=fee) token_bridge_wrapper.deposit( @@ -391,6 +392,7 @@ def test_deposit_message_sent_consumed( l1_handler_selector=HANDLE_TOKEN_DEPOSIT_SELECTOR, payload=[ int(token_bridge_wrapper.token_address(), 16), + depositor, L2_RECIPIENT, HALF_DEPOSIT_AMOUNT % 2**128, HALF_DEPOSIT_AMOUNT // 2**128, @@ -404,10 +406,10 @@ def test_deposit_message_sent_consumed( l1_handler_selector=HANDLE_DEPOSIT_WITH_MESSAGE_SELECTOR, payload=[ int(token_bridge_wrapper.token_address(), 16), + depositor, L2_RECIPIENT, HALF_DEPOSIT_AMOUNT % 2**128, HALF_DEPOSIT_AMOUNT // 2**128, - int(token_bridge_wrapper.default_user.address, 16), len(MESSAGE), *MESSAGE, ], @@ -731,7 +733,7 @@ def test_hacked_cancel_deposit( assert token_bridge_wrapper.get_bridge_balance() == DEPOSIT_AMOUNT # Initiate deposit cancellation from non-depositor. - with pytest.raises(EthRevertException, match="ONLY_DEPOSITOR"): + with pytest.raises(EthRevertException, match="NO_MESSAGE_TO_CANCEL"): token_bridge_wrapper.deposit_cancel_request( amount=DEPOSIT_AMOUNT, l2_recipient=L2_RECIPIENT, @@ -750,7 +752,7 @@ def test_hacked_cancel_deposit( eth_test_utils.advance_time(MESSAGE_CANCEL_DELAY) # Only depositor can claim the funds. - with pytest.raises(EthRevertException, match="ONLY_DEPOSITOR"): + with pytest.raises(EthRevertException, match="NO_MESSAGE_TO_CANCEL"): token_bridge_wrapper.deposit_reclaim( amount=DEPOSIT_AMOUNT, l2_recipient=L2_RECIPIENT, @@ -775,7 +777,7 @@ def test_hacked_cancel_deposit_with_message( assert token_bridge_wrapper.get_bridge_balance() == DEPOSIT_AMOUNT # Initiate deposit cancellation from non-depositor. - with pytest.raises(EthRevertException, match="ONLY_DEPOSITOR"): + with pytest.raises(EthRevertException, match="NO_MESSAGE_TO_CANCEL"): token_bridge_wrapper.deposit_cancel_request( amount=DEPOSIT_AMOUNT, l2_recipient=L2_RECIPIENT, @@ -796,7 +798,7 @@ def test_hacked_cancel_deposit_with_message( eth_test_utils.advance_time(MESSAGE_CANCEL_DELAY) # Only depositor can claim the funds. - with pytest.raises(EthRevertException, match="ONLY_DEPOSITOR"): + with pytest.raises(EthRevertException, match="NO_MESSAGE_TO_CANCEL"): token_bridge_wrapper.deposit_reclaim( amount=DEPOSIT_AMOUNT, l2_recipient=L2_RECIPIENT, @@ -828,7 +830,7 @@ def test_cancel_deposit( ) _sender = tx_receipt.w3_tx_receipt["from"] assert token_bridge_wrapper.get_bridge_balance() == DEPOSIT_AMOUNT - with pytest.raises(EthRevertException, match="NO_DEPOSIT_TO_CANCEL"): + with pytest.raises(EthRevertException, match="NO_MESSAGE_TO_CANCEL"): token_bridge_wrapper.deposit_cancel_request( amount=DEPOSIT_AMOUNT, l2_recipient=L2_RECIPIENT, nonce=1 ) @@ -854,16 +856,24 @@ def test_cancel_deposit( "nonce": 0, } + l1l2_msg_payload = [ + int(token_bridge_wrapper.token_address(), 16), + int(token_bridge_wrapper.default_user.address, 16), + L2_RECIPIENT, + DEPOSIT_AMOUNT, + 0, + ] + assert msg_cancel_req_ev == { "fromAddress": bridge.address, "toAddress": L2_TOKEN_CONTRACT, "selector": HANDLE_TOKEN_DEPOSIT_SELECTOR, - "payload": [int(token_bridge_wrapper.token_address(), 16), L2_RECIPIENT, DEPOSIT_AMOUNT, 0], + "payload": l1l2_msg_payload, "nonce": 0, } # Try to reclaim deposit with different properties (not existing deposit or not cancelled one). - with pytest.raises(EthRevertException, match="NO_DEPOSIT_TO_CANCEL"): + with pytest.raises(EthRevertException, match="NO_MESSAGE_TO_CANCEL"): token_bridge_wrapper.deposit_reclaim( amount=DEPOSIT_AMOUNT, l2_recipient=L2_RECIPIENT, @@ -899,7 +909,7 @@ def test_cancel_deposit( "fromAddress": bridge.address, "toAddress": L2_TOKEN_CONTRACT, "selector": HANDLE_TOKEN_DEPOSIT_SELECTOR, - "payload": [int(token_bridge_wrapper.token_address(), 16), L2_RECIPIENT, DEPOSIT_AMOUNT, 0], + "payload": l1l2_msg_payload, "nonce": 0, } @@ -930,7 +940,7 @@ def test_cancel_deposit_with_message( ) _sender = tx_receipt.w3_tx_receipt["from"] assert token_bridge_wrapper.get_bridge_balance() == DEPOSIT_AMOUNT - with pytest.raises(EthRevertException, match="NO_DEPOSIT_TO_CANCEL"): + with pytest.raises(EthRevertException, match="NO_MESSAGE_TO_CANCEL"): token_bridge_wrapper.deposit_cancel_request( amount=DEPOSIT_AMOUNT, l2_recipient=L2_RECIPIENT, message=MESSAGE, nonce=1 ) @@ -960,24 +970,26 @@ def test_cancel_deposit_with_message( "nonce": 0, } + l1l2_msg_payload = [ + int(token_bridge_wrapper.token_address(), 16), + int(token_bridge_wrapper.default_user.address, 16), + L2_RECIPIENT, + DEPOSIT_AMOUNT, + 0, + len(MESSAGE), + *MESSAGE, + ] + assert msg_cancel_req_ev == { "fromAddress": bridge.address, "toAddress": L2_TOKEN_CONTRACT, "selector": HANDLE_DEPOSIT_WITH_MESSAGE_SELECTOR, - "payload": [ - int(token_bridge_wrapper.token_address(), 16), - L2_RECIPIENT, - DEPOSIT_AMOUNT, - 0, - int(token_bridge_wrapper.default_user.address, 16), - len(MESSAGE), - *MESSAGE, - ], + "payload": l1l2_msg_payload, "nonce": 0, } # Try to reclaim deposit with different properties (not existing deposit or not cancelled one). - with pytest.raises(EthRevertException, match="NO_DEPOSIT_TO_CANCEL"): + with pytest.raises(EthRevertException, match="NO_MESSAGE_TO_CANCEL"): token_bridge_wrapper.deposit_reclaim( amount=DEPOSIT_AMOUNT, l2_recipient=L2_RECIPIENT, @@ -1016,15 +1028,7 @@ def test_cancel_deposit_with_message( "fromAddress": bridge.address, "toAddress": L2_TOKEN_CONTRACT, "selector": HANDLE_DEPOSIT_WITH_MESSAGE_SELECTOR, - "payload": [ - int(token_bridge_wrapper.token_address(), 16), - L2_RECIPIENT, - DEPOSIT_AMOUNT, - 0, - int(token_bridge_wrapper.default_user.address, 16), - len(MESSAGE), - *MESSAGE, - ], + "payload": l1l2_msg_payload, "nonce": 0, }