1

I was looking at Rocket Pool's docs on interacting with other contracts and they included a simple example function that another protocol could use to accept deposits of ETH, forward it to RP, and get back rETH. See below.

My question is about balance1 and balance2 for measuring how much someone who called this function deposited...specifically what if two people both called deposit at the same time...wouldn't address(this) contain both their funds and therefore balance2 would credit them with too much rETH?

deposit() external payable {
    // Check deposit amount
    require(msg.value > 0, "Invalid deposit amount");
    // Load contracts
    address rocketDepositPoolAddress = rocketStorage.getAddress(keccak256(abi.encodePacked("contract.address", "rocketDepositPool")));
    RocketDepositPoolInterface rocketDepositPool = RocketDepositPoolInterface(rocketDepositPoolAddress);
    address rocketTokenRETHAddress = rocketStorage.getAddress(keccak256(abi.encodePacked("contract.address", "rocketTokenRETH")));
    RocketTokenRETHInterface rocketTokenRETH = RocketTokenRETHInterface(rocketTokenRETHAddress);
    // Forward deposit to RP & get amount of rETH minted
    uint256 rethBalance1 = rocketTokenRETH.balanceOf(address(this));
    rocketDepositPool.deposit{value: msg.value}();
    uint256 rethBalance2 = rocketTokenRETH.balanceOf(address(this));
    require(rethBalance2 > rethBalance1, "No rETH was minted");
    uint256 rethMinted = rethBalance2 - rethBalance1;
    // Update user's balance
    balances[msg.sender] += rethMinted;
}

1 Answer 1

2

Even if two transactions are created at virtually the same exact time, there will be a definite order decided upon by the miner/validator of the block where the transactions took place.

This means that even if tx a and tx b are created at timestamp 100, one of the transactions will be added to the blockchain before the other one.

Even if the transactions were occurring at the same time, the local variables in the function wouldn't have shared values between the two synchronized transactions.

1
  • 1
    Okay that makes sense. Thank you Commented Sep 18, 2023 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.