Skip to content

Commit f11a0f2

Browse files
committed
feat: add chain id to quote fields
1 parent 482efe5 commit f11a0f2

20 files changed

+120
-25
lines changed

src/PegInContract.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,9 @@ contract PegInContract is
516516
}
517517

518518
function _validatePegInQuote(Quotes.PegInQuote calldata quote) private view {
519+
if (quote.chainId != block.chainid) {
520+
revert Flyover.InvalidChainId(block.chainid, quote.chainId);
521+
}
519522
if (address(this) != quote.lbcAddress) {
520523
revert Flyover.IncorrectContract(address(this), quote.lbcAddress);
521524
}

src/PegOutContract.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ contract PegOutContract is
274274
/// @notice This function is used to validate a peg out quote before hashing it
275275
/// @param quote The peg out quote to validate
276276
function _validatePegOutQuote(Quotes.PegOutQuote calldata quote) private view {
277+
if (quote.chainId != block.chainid) {
278+
revert Flyover.InvalidChainId(block.chainid, quote.chainId);
279+
}
277280
if (address(this) != quote.lbcAddress) {
278281
revert Flyover.IncorrectContract(address(this), quote.lbcAddress);
279282
}

src/libraries/Flyover.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@ library Flyover {
3131
error InsufficientAmount(uint256 amount, uint256 target);
3232
error Overflow(uint256 passedAmount);
3333
error InvalidAddress(address addr);
34+
/// @notice Quote was created for a different chain
35+
/// @param expected The current chain id (block.chainid)
36+
/// @param actual The chain id in the quote
37+
error InvalidChainId(uint256 expected, uint256 actual);
3438
}

src/libraries/Quotes.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pragma solidity 0.8.25;
33

44
library Quotes {
55
struct PegInQuote {
6+
uint256 chainId;
67
uint256 callFee;
78
uint256 penaltyFee;
89
uint256 value;
@@ -25,6 +26,7 @@ library Quotes {
2526
}
2627

2728
struct PegOutQuote {
29+
uint256 chainId;
2830
uint256 callFee;
2931
uint256 penaltyFee;
3032
uint256 value;
@@ -130,6 +132,7 @@ library Quotes {
130132
) private pure returns (bytes memory) {
131133
return
132134
abi.encode(
135+
quote.chainId,
133136
quote.fedBtcAddress,
134137
quote.lbcAddress,
135138
quote.liquidityProviderRskAddress,
@@ -165,6 +168,7 @@ library Quotes {
165168
) private pure returns (bytes memory) {
166169
return
167170
abi.encode(
171+
quote.chainId,
168172
quote.lbcAddress,
169173
quote.lpRskAddress,
170174
quote.btcRefundAddress,

test/collateral/CollateralTestBase.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,15 @@ abstract contract CollateralTestBase is Test {
119119
/// @notice Helper to create an empty PegIn quote
120120
function getEmptyPegInQuote()
121121
internal
122-
pure
122+
view
123123
returns (Quotes.PegInQuote memory)
124124
{
125125
bytes memory emptyBytes = new bytes(0);
126126
bytes memory testAddress = new bytes(20);
127127

128128
return
129129
Quotes.PegInQuote({
130+
chainId: block.chainid,
130131
callFee: 0,
131132
penaltyFee: 0,
132133
value: 0,
@@ -152,13 +153,14 @@ abstract contract CollateralTestBase is Test {
152153
/// @notice Helper to create an empty PegOut quote
153154
function getEmptyPegOutQuote()
154155
internal
155-
pure
156+
view
156157
returns (Quotes.PegOutQuote memory)
157158
{
158159
bytes memory testAddress = new bytes(20);
159160

160161
return
161162
Quotes.PegOutQuote({
163+
chainId: block.chainid,
162164
callFee: 0,
163165
penaltyFee: 0,
164166
value: 0,

test/deployment/DeployFlyoverDiscovery.t.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ contract DeployFlyoverDiscoveryTest is Test {
147147
)
148148
);
149149

150-
FlyoverDiscovery fd = FlyoverDiscovery(fdProxy);
151150
CollateralManagementContract cm = CollateralManagementContract(
152151
payable(collateralManagementProxy)
153152
);

test/fuzz/pegin/PegInFuzzTestBase.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ abstract contract PegInFuzzTestBase is PegInTestBase {
101101

102102
return
103103
Quotes.PegInQuote({
104+
chainId: block.chainid,
104105
callFee: DEFAULT_CALL_FEE,
105106
penaltyFee: DEFAULT_PENALTY_FEE,
106107
value: value,

test/fuzz/pegout/PegOutFuzzTestBase.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ abstract contract PegOutFuzzTestBase is PegOutTestBase {
6868

6969
return
7070
Quotes.PegOutQuote({
71+
chainId: block.chainid,
7172
callFee: DEFAULT_CALL_FEE,
7273
penaltyFee: DEFAULT_PENALTY_FEE,
7374
value: value,
@@ -129,6 +130,7 @@ abstract contract PegOutFuzzTestBase is PegOutTestBase {
129130

130131
return
131132
Quotes.PegOutQuote({
133+
chainId: block.chainid,
132134
callFee: DEFAULT_CALL_FEE,
133135
penaltyFee: DEFAULT_PENALTY_FEE,
134136
value: value,

test/helpers/FlyoverTestBase.sol

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,14 +475,15 @@ abstract contract FlyoverTestBase is Test {
475475
/// @notice Create an empty PegIn quote for testing
476476
function getEmptyPegInQuote()
477477
internal
478-
pure
478+
view
479479
returns (Quotes.PegInQuote memory)
480480
{
481481
bytes memory emptyBytes = new bytes(0);
482482
bytes memory testAddress = new bytes(20);
483483

484484
return
485485
Quotes.PegInQuote({
486+
chainId: block.chainid,
486487
callFee: 0,
487488
penaltyFee: 0,
488489
value: 0,
@@ -508,13 +509,14 @@ abstract contract FlyoverTestBase is Test {
508509
/// @notice Create an empty PegOut quote for testing
509510
function getEmptyPegOutQuote()
510511
internal
511-
pure
512+
view
512513
returns (Quotes.PegOutQuote memory)
513514
{
514515
bytes memory testAddress = new bytes(20);
515516

516517
return
517518
Quotes.PegOutQuote({
519+
chainId: block.chainid,
518520
callFee: 0,
519521
penaltyFee: 0,
520522
value: 0,
@@ -547,6 +549,7 @@ abstract contract FlyoverTestBase is Test {
547549

548550
return
549551
Quotes.PegInQuote({
552+
chainId: block.chainid,
550553
callFee: 100000000000000,
551554
penaltyFee: 10000000000000,
552555
value: 0.5 ether,
@@ -582,6 +585,7 @@ abstract contract FlyoverTestBase is Test {
582585

583586
return
584587
Quotes.PegOutQuote({
588+
chainId: block.chainid,
585589
callFee: 100000000000000,
586590
penaltyFee: 10000000000000,
587591
value: 0.5 ether,

test/integration/CollateralManagement.t.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,12 @@ contract CollateralManagementIntegrationTest is Test {
7373

7474
function getEmptyPegInQuote()
7575
internal
76-
pure
76+
view
7777
returns (Quotes.PegInQuote memory)
7878
{
7979
return
8080
Quotes.PegInQuote({
81+
chainId: block.chainid,
8182
callFee: 0,
8283
value: 0,
8384
gasFee: 0,

0 commit comments

Comments
 (0)