Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

[Do not merge] Nitro Stylus Diff #22

Draft
wants to merge 687 commits into
base: nitro-stylus-split
Choose a base branch
from
Draft

Conversation

rachel-bousfield
Copy link
Contributor

This temporary PR provides a diff between nitro-contracts and stylus-contracts to aid in review.

@cla-bot cla-bot bot added the s label Nov 15, 2023
Copy link
Member

@gzeoneth gzeoneth left a comment

Choose a reason for hiding this comment

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

some minor suggestions, yet to review the logic against nitro

Comment on lines +129 to +130
bool updateRoot = !(opcode == Instructions.LINK_MODULE ||
opcode == Instructions.UNLINK_MODULE);
Copy link
Member

Choose a reason for hiding this comment

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

can simplify into

Suggested change
bool updateRoot = !(opcode == Instructions.LINK_MODULE ||
opcode == Instructions.UNLINK_MODULE);
bool updateRoot = (opcode != Instructions.LINK_MODULE) &&
(opcode != Instructions.UNLINK_MODULE);

@@ -11,6 +11,8 @@ import "./ModuleMemoryCompact.sol";
library ModuleMemoryLib {
using MerkleProofLib for MerkleProof;

uint256 private constant LEAF_SIZE = 32;
Copy link
Member

Choose a reason for hiding this comment

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

This is defined separately in multiple contracts, we should consider to consolidate them

Comment on lines 395 to 396
bytes calldata proof
) internal view {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
bytes calldata proof
) internal view {
bytes calldata
) internal pure {

interface ArbOwner {
/// @notice Add account as a chain owner
// @notice Add account as a chain owner
Copy link
Member

@gzeoneth gzeoneth Nov 20, 2023

Choose a reason for hiding this comment

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

I believes natspec expect triple slash

}

uint256 lastProvedLeafIdx = ~uint256(0);
bytes32 lastProvedLeafContents;

Check warning

Code scanning / Slither

Uninitialized local variables Medium

@@ -62,16 +64,21 @@
ValueStack memory values = ValueStack({proved: valuesArray, remainingHash: 0});
ValueStack memory internalStack;
StackFrameWindow memory frameStack;
MultiStack memory emptyMultiStack;

Check warning

Code scanning / Slither

Uninitialized local variables Medium

Comment on lines +572 to +600
function executeSwitchCoThread(
ExecutionContext calldata,
Machine memory mach,
Module memory,
Instruction calldata inst,
bytes calldata
) internal pure {
if (mach.frameMultiStack.inactiveStackHash == MultiStackLib.NO_STACK_HASH) {
// cannot switch cothread if there isn't one
mach.status = MachineStatus.ERRORED;
return;
}
if (inst.argumentData == 0) {
if (mach.recoveryPc == MachineLib.NO_RECOVERY_PC) {
// switching to main thread, from main thread
mach.status = MachineStatus.ERRORED;
return;
}
mach.recoveryPc = MachineLib.NO_RECOVERY_PC;
} else {
if (mach.recoveryPc != MachineLib.NO_RECOVERY_PC) {
// switching from cothread to cothread
mach.status = MachineStatus.ERRORED;
return;
}
mach.setRecoveryFromPc(uint32(inst.argumentData));
}
mach.switchCoThreadStacks();
}
Comment on lines +433 to +464
function executeLinkModule(
ExecutionContext calldata,
Machine memory mach,
Module memory mod,
Instruction calldata,
bytes calldata proof
) internal pure {
string memory prefix = "Module merkle tree:";
bytes32 root = mach.modulesRoot;

uint256 pointer = mach.valueStack.pop().assumeI32();
if (!mod.moduleMemory.isValidLeaf(pointer)) {
mach.status = MachineStatus.ERRORED;
return;
}
(bytes32 userMod, uint256 offset, ) = mod.moduleMemory.proveLeaf(
pointer / LEAF_SIZE,
proof,
0
);

(uint256 leaf, , MerkleProof memory zeroProof) = proveLastLeaf(mach, offset, proof);

bool balanced = isPowerOfTwo(leaf + 1);
if (balanced) {
mach.modulesRoot = MerkleProofLib.growToNewRoot(root, leaf + 1, userMod, 0, prefix);
} else {
mach.modulesRoot = zeroProof.computeRootUnsafe(leaf + 1, userMod, prefix);
}

mach.valueStack.push(ValueLib.newI32(uint32(leaf + 1)));
}
Comment on lines +255 to +285
function _deployFactories(
address _inbox,
address _nativeToken,
uint256 _maxFeePerGas
) internal {
if (_nativeToken == address(0)) {
// we need to fund 4 retryable tickets
uint256 cost = l2FactoriesDeployer.getDeploymentTotalCost(
IInboxBase(_inbox),
_maxFeePerGas
);

// do it
l2FactoriesDeployer.perform{value: cost}(_inbox, _nativeToken, _maxFeePerGas);

// refund the caller
// solhint-disable-next-line avoid-low-level-calls
(bool sent, ) = msg.sender.call{value: address(this).balance}("");
require(sent, "Refund failed");
} else {
// Transfer fee token amount needed to pay for retryable fees to the inbox.
uint256 totalFee = l2FactoriesDeployer.getDeploymentTotalCost(
IInboxBase(_inbox),
_maxFeePerGas
);
IERC20(_nativeToken).safeTransferFrom(msg.sender, _inbox, totalFee);

// do it
l2FactoriesDeployer.perform(_inbox, _nativeToken, _maxFeePerGas);
}
}

Check failure

Code scanning / Slither

Functions that send Ether to arbitrary destinations High

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants