Skip to content

Commit

Permalink
feat: compile without viaIR
Browse files Browse the repository at this point in the history
  • Loading branch information
sujithsomraaj committed Aug 15, 2023
1 parent cd21945 commit c6ac7b8
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 77 deletions.
54 changes: 27 additions & 27 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
AxelarHelperTest:testCustomOrderingAxelar() (gas: 311397)
AxelarHelperTest:testFancyAxelar() (gas: 220082)
AxelarHelperTest:testMultiDstAxelar() (gas: 360162)
AxelarHelperTest:testSimpleAxelar() (gas: 174830)
CelerHelperTest:testCustomOrderingCeler() (gas: 109020)
CelerHelperTest:testFancyCeler() (gas: 118925)
CelerHelperTest:testMultiDstCeler() (gas: 152825)
CelerHelperTest:testSimpleCeler() (gas: 72270)
CelerHelperTest:testSimpleCelerWithEstimates() (gas: 73517)
HyperlaneHelperTest:testCustomOrderingHL() (gas: 146123)
HyperlaneHelperTest:testFancyHL() (gas: 146761)
HyperlaneHelperTest:testMultiDstHL() (gas: 194207)
HyperlaneHelperTest:testSimpleHL() (gas: 98620)
HyperlaneHelperTest:testSimpleHLWithEstimates() (gas: 99315)
LayerZeroHelperTest:testCustomOrderingLZ() (gas: 341156)
LayerZeroHelperTest:testFancyLZ() (gas: 296248)
LayerZeroHelperTest:testMultiDstLZ() (gas: 477162)
LayerZeroHelperTest:testSimpleLZ() (gas: 246272)
LayerZeroHelperTest:testSimpleLZWithEstimates() (gas: 247133)
StargateHelperTest:testCustomOrderingSG() (gas: 807528)
StargateHelperTest:testFancySG() (gas: 594258)
StargateHelperTest:testSimpleSG() (gas: 542126)
StargateHelperTest:testSimpleSGWithEstimates() (gas: 543402)
WormholeHelperTest:testCustomOrderingWormhole() (gas: 284998)
WormholeHelperTest:testFancyWormhole() (gas: 224663)
WormholeHelperTest:testMultiDstWormhole() (gas: 345244)
WormholeHelperTest:testSimpleWormhole() (gas: 178309)
AxelarHelperTest:testCustomOrderingAxelar() (gas: 472462)
AxelarHelperTest:testFancyAxelar() (gas: 297729)
AxelarHelperTest:testMultiDstAxelar() (gas: 519062)
AxelarHelperTest:testSimpleAxelar() (gas: 250761)
CelerHelperTest:testCustomOrderingCeler() (gas: 132077)
CelerHelperTest:testFancyCeler() (gas: 132906)
CelerHelperTest:testMultiDstCeler() (gas: 172575)
CelerHelperTest:testSimpleCeler() (gas: 80089)
CelerHelperTest:testSimpleCelerWithEstimates() (gas: 86015)
HyperlaneHelperTest:testCustomOrderingHL() (gas: 186889)
HyperlaneHelperTest:testFancyHL() (gas: 163204)
HyperlaneHelperTest:testMultiDstHL() (gas: 235011)
HyperlaneHelperTest:testSimpleHL() (gas: 114050)
HyperlaneHelperTest:testSimpleHLWithEstimates() (gas: 114835)
LayerZeroHelperTest:testCustomOrderingLZ() (gas: 386343)
LayerZeroHelperTest:testFancyLZ() (gas: 317392)
LayerZeroHelperTest:testMultiDstLZ() (gas: 531028)
LayerZeroHelperTest:testSimpleLZ() (gas: 265631)
LayerZeroHelperTest:testSimpleLZWithEstimates() (gas: 331518)
StargateHelperTest:testCustomOrderingSG() (gas: 900947)
StargateHelperTest:testFancySG() (gas: 639391)
StargateHelperTest:testSimpleSG() (gas: 585377)
StargateHelperTest:testSimpleSGWithEstimates() (gas: 652708)
WormholeHelperTest:testCustomOrderingWormhole() (gas: 325336)
WormholeHelperTest:testFancyWormhole() (gas: 242095)
WormholeHelperTest:testMultiDstWormhole() (gas: 389017)
WormholeHelperTest:testSimpleWormhole() (gas: 194459)
3 changes: 0 additions & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,3 @@

[profile.default]
solc_version = '0.8.19'
optimizer_runs = 100
optimizer = true
viaIR = true
44 changes: 23 additions & 21 deletions src/axelar/AxelarHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ contract AxelarHelper is Test {
return _findLogs(logs, MESSAGE_EVENT_SELECTOR, length);
}

struct LocalVars {
uint256 prevForkId;
Vm.Log log;
string destinationChain;
string destinationContract;
bytes payload;
}

function _help(
string memory fromChain,
address toGateway,
Expand All @@ -94,64 +102,58 @@ contract AxelarHelper is Test {
bytes32 eventSelector,
Vm.Log[] calldata logs
) internal {
uint256 prevForkId = vm.activeFork();
LocalVars memory v;
v.prevForkId = vm.activeFork();

vm.selectFork(forkId);
vm.startBroadcast(toGateway);

for (uint256 i; i < logs.length; i++) {
Vm.Log memory log = logs[i];

if (log.topics[0] == eventSelector) {
string memory destinationChain;
string memory destinationContract;

bytes memory payload;
v.log = logs[i];

(destinationChain, destinationContract, payload) = abi.decode(
log.data,
(string, string, bytes)
);
if (v.log.topics[0] == eventSelector) {
(v.destinationChain, v.destinationContract, v.payload) = abi
.decode(v.log.data, (string, string, bytes));

/// FIXME: length based checks aren't sufficient
if (isStringsEqual(expDstChain, destinationChain)) {
if (isStringsEqual(expDstChain, v.destinationChain)) {
string memory srcAddress = AddressHelper.toString(
address(uint160(uint256(log.topics[1])))
address(uint160(uint256(v.log.topics[1])))
);
address dstContract = AddressHelper.fromString(
destinationContract
v.destinationContract
);

IAxelarGateway(toGateway).approveContractCall(
abi.encode(
fromChain,
srcAddress,
dstContract,
keccak256(payload),
keccak256(v.payload),
bytes32(0),
i
),
log.topics[2]
v.log.topics[2]
);

IAxelarExecutable(dstContract).execute(
log.topics[2], /// payloadHash
v.log.topics[2], /// payloadHash
fromChain,
srcAddress,
payload
v.payload
);
}
}
}

vm.stopBroadcast();
vm.selectFork(prevForkId);
vm.selectFork(v.prevForkId);
}

function isStringsEqual(
string memory a,
string memory b
) public view returns (bool) {
) public pure returns (bool) {
return (keccak256(abi.encodePacked((a))) ==
keccak256(abi.encodePacked((b))));
}
Expand Down
2 changes: 0 additions & 2 deletions src/hyperlane/HyperlaneHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ contract HyperlaneHelper is Test {
if (
log.emitter == fromMailbox && log.topics[0] == dispatchSelector
) {
bytes32 sender = log.topics[1];
uint32 destinationDomain = uint32(uint256(log.topics[2]));
bytes32 recipient = log.topics[3];
bytes memory message = abi.decode(log.data, (bytes));

if (expDstDomain == destinationDomain || expDstDomain == 0) {
Expand Down
2 changes: 0 additions & 2 deletions src/layerzero/lib/LZPacket.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ library LayerZeroPacket {
srcAddressBuffer.init(sizeOfSrcAddress);
srcAddressBuffer.writeRawBytes(0, data, 106, sizeOfSrcAddress);

uint256 nonPayloadSize = sizeOfSrcAddress + 32; // 2 + 2 + 8 + 20, 32 + 20 = 52 if sizeOfSrcAddress == 20
uint256 payloadSize = realSize - nonPayloadSize;
Buffer.buffer memory payloadBuffer;
// payloadBuffer.init(payloadSize);
// payloadBuffer.writeRawBytes(0, data, nonPayloadSize + 96, payloadSize);
Expand Down
24 changes: 14 additions & 10 deletions src/wormhole/WormholeHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,11 @@ contract WormholeHelper is Test {
//////////////////////////////////////////////////////////////*/

struct LocalVars {
uint256 prevForkId;
uint64 sequence;
uint32 nonce;
bytes payload;
address dstAddress;
}

/// @dev helper to process cross-chain messages
Expand All @@ -167,41 +169,43 @@ contract WormholeHelper is Test {
bytes32 eventSelector,
Vm.Log[] calldata logs
) internal {
uint256 prevForkId = vm.activeFork();
LocalVars memory v;
v.prevForkId = vm.activeFork();

vm.selectFork(dstForkId);
vm.startBroadcast(dstRelayer);

for (uint256 i; i < logs.length; i++) {
Vm.Log memory log = logs[i];

if (log.topics[0] == eventSelector) {
LocalVars memory vars;

(vars.sequence, vars.nonce, vars.payload, ) = abi.decode(
(v.sequence, v.nonce, v.payload, ) = abi.decode(
log.data,
(uint64, uint32, bytes, uint8)
);

DeliveryInstruction memory instruction = PayloadDecoder
.decodeDeliveryInstruction(vars.payload);
.decodeDeliveryInstruction(v.payload);

address dstAddress = TypeCasts.bytes32ToAddress(
v.dstAddress = TypeCasts.bytes32ToAddress(
instruction.targetAddress
);

if (expDstAddress == address(0) || expDstAddress == dstAddress)
IWormholeReceiver(dstAddress).receiveWormholeMessages(
if (
expDstAddress == address(0) || expDstAddress == v.dstAddress
)
IWormholeReceiver(v.dstAddress).receiveWormholeMessages(
instruction.payload,
new bytes[](0),
instruction.senderAddress,
srcChainId,
keccak256(abi.encodePacked(vars.sequence, vars.nonce)) /// @dev generating some random hash
keccak256(abi.encodePacked(v.sequence, v.nonce)) /// @dev generating some random hash
);
}
}

vm.stopBroadcast();
vm.selectFork(prevForkId);
vm.selectFork(v.prevForkId);
}

/// @dev helper to get logs
Expand Down
6 changes: 3 additions & 3 deletions test/Axelar.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ contract Target {
uint256 public value;

function execute(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes32, /// commandId
string calldata, /// sourceChain
string calldata, /// sourceAddress
bytes calldata payload
) external {
value = abi.decode(payload, (uint256));
Expand Down
18 changes: 9 additions & 9 deletions test/Stargate.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ contract Target {
uint256 public value;

function sgReceive(
uint16 _srcChainId,
bytes memory _srcAddress,
uint256 _nonce,
address _token,
uint256 amountLD,
uint16, /// _srcChainId
bytes memory, /// _srcAddress
uint256, /// _nonce
address, /// _token
uint256, /// amountLD
bytes memory payload
) external {
value = abi.decode(payload, (uint256));
Expand All @@ -61,10 +61,10 @@ contract AnotherTarget {

function sgReceive(
uint16 _srcChainId,
bytes memory _srcAddress,
uint256 _nonce,
address _token,
uint256 amountLD,
bytes memory, /// _srcAddress
uint256, /// _nonce
address, /// _token
uint256, /// _amount
bytes memory payload
) external {
require(_srcChainId == expectedId, "Unexpected id");
Expand Down

0 comments on commit c6ac7b8

Please sign in to comment.