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

fix(contracts): fix contract audit findings #1254

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

cryptoAtwill
Copy link
Contributor

@cryptoAtwill cryptoAtwill commented Jan 20, 2025

This PR addresses the review audits.

Fixes

Mediums:

  • M1: Addressed

Lows:

  • L1: I dont think we should address this. The subnet does not really know if the destination subnet exists. Caller should be aware.
  • L2: Updated, this one is known to have created tons of confusion.

Informationals:

  • I1: Addressed
  • I2: Addressed
  • I3: Addressed
  • I5: Addressed
  • I6: Addressed
  • I8: Addressed

To discuss

  • L3: We should taggle gas_limit in cross message transactions, but the issue is more complex than described. Maybe delay to another issue?
  • I4: We should discuss if we need this, but I think it’s a good practice
  • I7: I dont see the line mentioned, maybe the codebase is different

@cryptoAtwill cryptoAtwill requested a review from a team as a code owner January 20, 2025 10:24
@raulk raulk changed the title fix(node): update contract audit fix(contracts): update contract audit Jan 20, 2025
@raulk raulk changed the title fix(contracts): update contract audit fix(contracts): fix contract audit findings Jan 20, 2025
@karlem
Copy link
Contributor

karlem commented Jan 20, 2025

@cryptoAtwill I think it might be useful to add a sentence to each point in the list if possible. It is not clear from here what is being fixed.

@@ -27,6 +27,8 @@ contract GatewayManagerFacet is GatewayActorModifiers, ReentrancyGuard {
using AssetHelper for Asset;
using EnumerableSet for EnumerableSet.Bytes32Set;

event SubnetKilled(SubnetID id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's name this event SubnetDestroyed. That term is more general as it can apply in ephemeral subnets, self-destruction, expirations (e.g. subnet is not bootstrapped in a predefined amount of time).

}

/// @notice addStake - add collateral for an existing subnet
function addStake(uint256 amount) external payable {
function addStake(uint256 amount) external payable nonReentrant {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, but is there really a re-entrancy risk here? The contract call is performed before we update credit the stake, so it shouldn't bear any risks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lock does the check already, this then can go.

@@ -45,7 +45,7 @@ contract GatewayMessengerFacet is GatewayActorModifiers {
}

// We prevent the sender from being an EoA.
if (!(msg.sender.code.length > 0)) {
if (msg.sender.code.length == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆

@@ -423,7 +423,7 @@ library LibGateway {
sendReceipt(crossMsg, OutcomeType.SystemErr, abi.encodeWithSelector(InvalidXnetMessage.selector, InvalidXnetMessageReason.Nonce));
return;
}
subnet.appliedBottomUpNonce += 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this is purely stylistic, I would use a post-increment. It's visually more common.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Backlog
Development

Successfully merging this pull request may close these issues.

3 participants