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

Layer Zero integration #52

Merged
merged 65 commits into from
Jun 24, 2024
Merged
Changes from 1 commit
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
5c49a2a
forge install: LayerZero
reednaa May 27, 2024
3b4f5ec
feat: initial lz sketch
reednaa May 27, 2024
94fce29
feat: inits
reednaa May 27, 2024
223d1ab
feat: move requirements into our repo
reednaa May 27, 2024
0a53131
feat: compiling in on 0.8
reednaa May 27, 2024
185c277
feat: send in endpoint v2
reednaa May 27, 2024
fe93270
feat: optimise gas queries for LZ
reednaa May 27, 2024
a1f7010
feat: verify LZ packages
reednaa May 27, 2024
cf99735
feat: doc
reednaa May 27, 2024
5bf66f0
feat: save gas by calling verifyable directly
reednaa May 27, 2024
34ec03c
feat: cleanup packet verification
reednaa May 27, 2024
6fbe4e2
feat: cleanup implementation
reednaa May 27, 2024
351f0f9
feat: clean up
reednaa May 27, 2024
51676dd
test: prepare tests
reednaa May 27, 2024
bdab3a9
forge install: LayerZero-v2
reednaa May 27, 2024
afb16e0
feat: Directly import OZ to remove interfaces and simplify testing
reednaa May 27, 2024
4f79b65
test: prepare testing suite for lz
reednaa May 27, 2024
4e8cfba
test: expose allowExternalCall
reednaa May 27, 2024
e1f5ce8
fix: allow contracts to be compiled
reednaa May 27, 2024
98998c8
feat: improve LZ refund
reednaa May 27, 2024
44cee2d
doc: questions for LZ working
reednaa May 27, 2024
34e2d78
feat: setallowInitializePath
reednaa May 27, 2024
3977910
feat: set configs of LZ
reednaa May 27, 2024
8352e12
Modify bridge_contracts
ajimeno04 May 27, 2024
b2327bc
modify .env.example
ajimeno04 May 27, 2024
5e37aa8
update deploy script
ajimeno04 May 27, 2024
7e2df82
feat: update much of the LZ implementation to better fit how LZ is in…
reednaa May 27, 2024
258a1c6
feat: update tests to match ULN removal
reednaa May 27, 2024
c112a30
feat: set options to TYPE_3 only
reednaa May 27, 2024
0196787
feat: documentation updates
reednaa May 27, 2024
df38b56
chore: remove unused comments
reednaa May 27, 2024
4ec0a69
fix: set LAYERZERO_OPTIONS to hex''
reednaa May 27, 2024
7d9c76e
Revert "fix: set LAYERZERO_OPTIONS to hex''"
reednaa May 27, 2024
3fb4a4d
feat: add comment regarding the minimum option length
reednaa May 27, 2024
8051276
feat: make test for LZ
reednaa May 30, 2024
066d731
forge install: solidity-bytes-utils
reednaa May 30, 2024
563215c
test: init config & send packet
reednaa May 31, 2024
5639765
Update deployment contract for new LayerZero escrow contracts
ajimeno04 Jun 2, 2024
689a907
fix: correctly provide all of the package in rawMessage
reednaa Jun 3, 2024
d81d6d8
test: verify packages
reednaa Jun 3, 2024
dffd805
feat: simplify contract very slightly
reednaa Jun 3, 2024
60766c4
feat: more LZ testing
reednaa Jun 3, 2024
f001dbf
test: invalid receiver
reednaa Jun 3, 2024
3129a0f
test: finsh LZ testing
reednaa Jun 3, 2024
1f723ab
update condig and deploy
ajimeno04 Jun 4, 2024
bcdd39c
Bridge contract
ajimeno04 Jun 5, 2024
287daaa
feat: initConfig script for LZ
reednaa Jun 5, 2024
1f9ae2f
feat: add broadcast to git ignore
reednaa Jun 5, 2024
fc4bcb3
feat: small fix for LZ contracts
reednaa Jun 5, 2024
b464270
feat: submit message script
reednaa Jun 5, 2024
869d3f7
feat: process message script
reednaa Jun 6, 2024
d092375
feat: set proofValidPeriod to 1 month
reednaa Jun 6, 2024
f4a4458
test: fix test with proof valid period
reednaa Jun 6, 2024
69a7905
feat: add additional estimateAdditionalCost view function
reednaa Jun 6, 2024
bb8c4d9
feat: final LZ changes & code documentation
reednaa Jun 6, 2024
040e175
feat: set license to MIT
reednaa Jun 17, 2024
0d9f2ba
fix: remove unused import and error
reednaa Jun 17, 2024
2cf24c6
fix: typos
reednaa Jun 17, 2024
f40e0fa
Merge pull request #53 from catalystdao/I4-typos
reednaa Jun 17, 2024
8126d94
Merge pull request #55 from catalystdao/W11-incorrect-SPDX-license-id…
reednaa Jun 17, 2024
5e016f8
Merge pull request #54 from catalystdao/W12-Unused-code
reednaa Jun 17, 2024
15bdf09
fix: Last types of verifiable
reednaa Jun 21, 2024
db0c96e
feat: further types
reednaa Jun 21, 2024
aea83f4
Merge pull request #56 from catalystdao/I4-typos
reednaa Jun 21, 2024
948ad86
feat: update ackee audit
reednaa Jun 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: save gas by calling verifyable directly
reednaa committed May 27, 2024
commit 5bf66f09246c229accb2517623454900323dd987
14 changes: 7 additions & 7 deletions src/apps/layerzero/IncentivizedLayerZeroEscrow.sol
Original file line number Diff line number Diff line change
@@ -5,21 +5,20 @@ import { IncentivizedMessageEscrow } from "../../IncentivizedMessageEscrow.sol";
import { ILayerZeroEndpointV2, MessagingParams, MessagingFee } from "./interfaces/ILayerZeroEndpointV2.sol";
import { PacketV1Codec } from "./libs/PacketV1Codec.sol";
import { UlnConfig } from "./interfaces/IUlnBase.sol";
import { SimpleLZULN } from "./SimpleLZULN.sol";
import { IReceiveUlnBase, UlnConfig, Verification } from "./interfaces/IUlnBase.sol";

/**
* @notice LayerZero escrow.
* TODO: Set config such that we are the executor.
* TODO: Figure out if we can verify
* If not, then figure out how to decode the payload and then do both the composer and the executor step in 1.
*/
abstract contract BareIncentivizedLayerZeroEscrow is IncentivizedMessageEscrow, SimpleLZULN {
abstract contract BareIncentivizedLayerZeroEscrow is IncentivizedMessageEscrow {
using PacketV1Codec for bytes;

error LayerZeroCannotBeAddress0();
error LZ_ULN_Verifying();

ILayerZeroEndpointV2 immutable ENDPOINT;
IReceiveUlnBase immutable ULTRA_LIGHT_NODE;

// TODO: Are these values packed?
uint128 excessPaid = 1; // Set to 1 so we never have to pay zero to non-zero cost.
@@ -29,10 +28,11 @@ abstract contract BareIncentivizedLayerZeroEscrow is IncentivizedMessageEscrow,
uint32 public immutable chainId;
address private constant DEFAULT_CONFIG = address(0);

constructor(address sendLostGasTo, address lzEndpointV2, address ULN) IncentivizedMessageEscrow(sendLostGasTo) SimpleLZULN(ULN) {
constructor(address sendLostGasTo, address lzEndpointV2, address ULN) IncentivizedMessageEscrow(sendLostGasTo) {
if (lzEndpointV2 == address(0)) revert LayerZeroCannotBeAddress0();
ENDPOINT = ILayerZeroEndpointV2(lzEndpointV2);
chainId = ENDPOINT.eid();
ULTRA_LIGHT_NODE = IReceiveUlnBase(ULN);
// TODO: Set executor as this contract.
}

@@ -76,8 +76,8 @@ abstract contract BareIncentivizedLayerZeroEscrow is IncentivizedMessageEscrow,

bytes32 _headerHash = keccak256(_packetHeader);
bytes32 _payloadHash = keccak256(_payload);
if (!_checkVerifiable(srcEid, _headerHash, _payloadHash)) revert LZ_ULN_Verifying();

UlnConfig memory _config = ULTRA_LIGHT_NODE.getUlnConfig(address(this), srcEid);
if (ULTRA_LIGHT_NODE.verifiable(_config, _headerHash, _payloadHash)) revert LZ_ULN_Verifying();

// TODO: everything below.
// Load the identifier for the calling contract.
49 changes: 0 additions & 49 deletions src/apps/layerzero/SimpleLZULN.sol
Original file line number Diff line number Diff line change
@@ -13,53 +13,4 @@ contract SimpleLZULN {
ULTRA_LIGHT_NODE = IReceiveUlnBase(ULN);
}

/// @dev for verifiable view function
/// @dev checks if this verification is ready to be committed to the endpoint
function _checkVerifiable(
uint32 _srcEid,
bytes32 _headerHash,
bytes32 _payloadHash
) internal view returns (bool) {
UlnConfig memory _config = ULTRA_LIGHT_NODE.getUlnConfig(address(this), _srcEid);
// iterate the required DVNs
if (_config.requiredDVNCount > 0) {
for (uint8 i = 0; i < _config.requiredDVNCount; ++i) {
if (!_verified(_config.requiredDVNs[i], _headerHash, _payloadHash, _config.confirmations)) {
// return if any of the required DVNs haven't signed
return false;
}
}
if (_config.optionalDVNCount == 0) {
// returns early if all required DVNs have signed and there are no optional DVNs
return true;
}
}

// then it must require optional validations
uint8 threshold = _config.optionalDVNThreshold;
for (uint8 i = 0; i < _config.optionalDVNCount; ++i) {
if (_verified(_config.optionalDVNs[i], _headerHash, _payloadHash, _config.confirmations)) {
// increment the optional count if the optional DVN has signed
threshold--;
if (threshold == 0) {
// early return if the optional threshold has hit
return true;
}
}
}

// return false as a catch-all
return false;
}

function _verified(
address _dvn,
bytes32 _headerHash,
bytes32 _payloadHash,
uint64 _requiredConfirmation
) internal view returns (bool verified) {
Verification memory verification = ULTRA_LIGHT_NODE.hashLookup(_headerHash, _payloadHash, _dvn);
// return true if the dvn has signed enough confirmations
verified = verification.submitted && verification.confirmations >= _requiredConfirmation;
}
}
7 changes: 5 additions & 2 deletions src/apps/layerzero/interfaces/IUlnBase.sol
Original file line number Diff line number Diff line change
@@ -20,8 +20,11 @@ struct Verification {
}

interface IReceiveUlnBase {
// mapping(bytes32 headerHash => mapping(bytes32 payloadHash => mapping(address dvn => Verification))) public hashLookup;
function hashLookup(bytes32 headerHash, bytes32 payloadHash, address dvn) external view returns (Verification memory);
function verifiable(
UlnConfig memory _config,
bytes32 _headerHash,
bytes32 _payloadHash
) external view returns (bool);

function getUlnConfig(address _oapp, uint32 _remoteEid) external view returns (UlnConfig memory rtnConfig);
}