-
Notifications
You must be signed in to change notification settings - Fork 45
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
Conversation
@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); |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cryptoAtwill Can't we do appliedBottomUpNonce++
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think ++appliedBottomUpNonce
is appliedBottomUpNonce += 1
but appliedBottomUpNonce++
is actually:
i = appliedBottomUpNonce;
appliedBottomUpNonce = appliedBottomUpNonce + 1;
i
it's slightly more gas consuming.
@@ -72,7 +74,6 @@ contract GatewayManagerFacet is GatewayActorModifiers, ReentrancyGuard { | |||
SubnetActorGetterFacet(msg.sender).collateralSource().lock(amount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we not move the lock after the check?
@@ -73,8 +76,13 @@ contract SubnetActorManagerFacet is SubnetActorModifiers, ReentrancyGuard, Pausa | |||
} | |||
} | |||
|
|||
/// @notice Sets the validator gater contract implementation | |||
/// @param gater The addresseof validator gater implementation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: addresseof
-> address of
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just small nits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a small comment but this looks good overall. Also consider adding additional unit tests to cover some of the fixes.
@@ -1584,7 +1584,7 @@ contract SubnetActorDiamondTest is Test, IntegrationTestBase { | |||
gatewayAddress, | |||
ConsensusType.Fendermint, | |||
DEFAULT_MIN_VALIDATOR_STAKE, | |||
DEFAULT_MIN_VALIDATORS, | |||
2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend assigning this to a constant variable for readability
This PR addresses the review audits.
Fixes
Mediums:
Lows:
Informationals:
To discuss