-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'vincent/v2' into ron/v2
- Loading branch information
Showing
79 changed files
with
1,001 additions
and
865 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.25; | ||
pragma solidity 0.8.28; | ||
|
||
import {Script} from "forge-std/Script.sol"; | ||
import {GatewayProxy} from "../src/GatewayProxy.sol"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.25; | ||
pragma solidity 0.8.28; | ||
|
||
import {Script} from "forge-std/Script.sol"; | ||
import {BeefyClient} from "../src/BeefyClient.sol"; | ||
|
@@ -18,7 +18,7 @@ contract DeployBeefyClient is Script { | |
function readConfig() internal pure returns (Config memory config) { | ||
// Checkpoint generated using the script `./beefy-checkpoint.js` script in Polkadot-JS. | ||
config = Config({ | ||
startBlock: 21087413, | ||
startBlock: 21_087_413, | ||
current: BeefyClient.ValidatorSet({ | ||
id: 644, | ||
length: 297, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.25; | ||
pragma solidity 0.8.28; | ||
|
||
import {WETH9} from "canonical-weth/WETH9.sol"; | ||
import {Script} from "forge-std/Script.sol"; | ||
|
@@ -52,17 +52,11 @@ contract DeployLocal is Script { | |
uint256 randaoCommitExpiration = vm.envUint("RANDAO_COMMIT_EXP"); | ||
uint256 minimumSignatures = vm.envUint("MINIMUM_REQUIRED_SIGNATURES"); | ||
BeefyClient beefyClient = new BeefyClient( | ||
randaoCommitDelay, | ||
randaoCommitExpiration, | ||
minimumSignatures, | ||
startBlock, | ||
current, | ||
next | ||
randaoCommitDelay, randaoCommitExpiration, minimumSignatures, startBlock, current, next | ||
); | ||
|
||
uint8 foreignTokenDecimals = uint8(vm.envUint("FOREIGN_TOKEN_DECIMALS")); | ||
uint128 maxDestinationFee = | ||
uint128(vm.envUint("RESERVE_TRANSFER_MAX_DESTINATION_FEE")); | ||
uint128 maxDestinationFee = uint128(vm.envUint("RESERVE_TRANSFER_MAX_DESTINATION_FEE")); | ||
|
||
AgentExecutor executor = new AgentExecutor(); | ||
Gateway gatewayLogic = new Gateway(address(beefyClient), address(executor)); | ||
|
@@ -92,17 +86,15 @@ contract DeployLocal is Script { | |
weth: weth | ||
}); | ||
|
||
GatewayProxy gateway = | ||
new GatewayProxy(address(gatewayLogic), abi.encode(config)); | ||
GatewayProxy gateway = new GatewayProxy(address(gatewayLogic), abi.encode(config)); | ||
|
||
// Fund the sovereign account for the BridgeHub parachain. Used to reward relayers | ||
// of messages originating from BridgeHub | ||
uint256 initialDeposit = vm.envUint("BRIDGE_HUB_INITIAL_DEPOSIT"); | ||
|
||
address bridgeHubAgent = | ||
IGatewayV2(address(gateway)).agentOf(Constants.BRIDGE_HUB_AGENT_ID); | ||
address assetHubAgent = | ||
IGatewayV2(address(gateway)).agentOf(Constants.ASSET_HUB_AGENT_ID); | ||
address assetHubAgent = IGatewayV2(address(gateway)).agentOf(Constants.ASSET_HUB_AGENT_ID); | ||
|
||
payable(bridgeHubAgent).safeNativeTransfer(initialDeposit); | ||
payable(assetHubAgent).safeNativeTransfer(initialDeposit); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.25; | ||
pragma solidity 0.8.28; | ||
|
||
import {AgentExecutor} from "../src/AgentExecutor.sol"; | ||
import {Gateway} from "../src//Gateway.sol"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.25; | ||
pragma solidity 0.8.28; | ||
|
||
import {WETH9} from "canonical-weth/WETH9.sol"; | ||
import {Script} from "forge-std/Script.sol"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.25; | ||
pragma solidity 0.8.28; | ||
|
||
import {WETH9} from "canonical-weth/WETH9.sol"; | ||
import {Script} from "forge-std/Script.sol"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.25; | ||
pragma solidity 0.8.28; | ||
|
||
import {WETH9} from "canonical-weth/WETH9.sol"; | ||
import {Script} from "forge-std/Script.sol"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.25; | ||
pragma solidity 0.8.28; | ||
|
||
/// @title An agent contract that acts on behalf of a consensus system on Polkadot | ||
/// @dev Instances of this contract act as an agents for arbitrary consensus systems on Polkadot. These consensus systems | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.25; | ||
pragma solidity 0.8.28; | ||
|
||
import {ParaID} from "./Types.sol"; | ||
import {SubstrateTypes} from "./SubstrateTypes.sol"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.25; | ||
pragma solidity 0.8.28; | ||
|
||
import {ECDSA} from "openzeppelin/utils/cryptography/ECDSA.sol"; | ||
import {SubstrateMerkleProof} from "./utils/SubstrateMerkleProof.sol"; | ||
|
@@ -247,9 +247,11 @@ contract BeefyClient { | |
* @param bitfield a bitfield claiming which validators have signed the commitment | ||
* @param proof a proof that a single validator from currentValidatorSet has signed the commitment | ||
*/ | ||
function submitInitial(Commitment calldata commitment, uint256[] calldata bitfield, ValidatorProof calldata proof) | ||
external | ||
{ | ||
function submitInitial( | ||
Commitment calldata commitment, | ||
uint256[] calldata bitfield, | ||
ValidatorProof calldata proof | ||
) external { | ||
if (commitment.blockNumber <= latestBeefyBlock) { | ||
revert StaleCommitment(); | ||
} | ||
|
@@ -258,7 +260,9 @@ contract BeefyClient { | |
uint16 signatureUsageCount; | ||
if (commitment.validatorSetID == currentValidatorSet.id) { | ||
signatureUsageCount = currentValidatorSet.usageCounters.get(proof.index); | ||
currentValidatorSet.usageCounters.set(proof.index, signatureUsageCount.saturatingAdd(1)); | ||
currentValidatorSet.usageCounters.set( | ||
proof.index, signatureUsageCount.saturatingAdd(1) | ||
); | ||
vset = currentValidatorSet; | ||
} else if (commitment.validatorSetID == nextValidatorSet.id) { | ||
signatureUsageCount = nextValidatorSet.usageCounters.get(proof.index); | ||
|
@@ -269,8 +273,10 @@ contract BeefyClient { | |
} | ||
|
||
// Check if merkle proof is valid based on the validatorSetRoot and if proof is included in bitfield | ||
if (!isValidatorInSet(vset, proof.account, proof.index, proof.proof) || !Bitfield.isSet(bitfield, proof.index)) | ||
{ | ||
if ( | ||
!isValidatorInSet(vset, proof.account, proof.index, proof.proof) | ||
|| !Bitfield.isSet(bitfield, proof.index) | ||
) { | ||
revert InvalidValidatorProof(); | ||
} | ||
|
||
|
@@ -291,7 +297,9 @@ contract BeefyClient { | |
blockNumber: uint64(block.number), | ||
validatorSetLen: uint32(vset.length), | ||
numRequiredSignatures: uint32( | ||
computeNumRequiredSignatures(vset.length, signatureUsageCount, minNumRequiredSignatures) | ||
computeNumRequiredSignatures( | ||
vset.length, signatureUsageCount, minNumRequiredSignatures | ||
) | ||
), | ||
prevRandao: 0, | ||
bitfieldHash: keccak256(abi.encodePacked(bitfield)) | ||
|
@@ -371,8 +379,9 @@ contract BeefyClient { | |
if (leaf.nextAuthoritySetID != nextValidatorSet.id + 1) { | ||
revert InvalidMMRLeaf(); | ||
} | ||
bool leafIsValid = | ||
MMRProof.verifyLeafProof(newMMRRoot, keccak256(encodeMMRLeaf(leaf)), leafProof, leafProofOrder); | ||
bool leafIsValid = MMRProof.verifyLeafProof( | ||
newMMRRoot, keccak256(encodeMMRLeaf(leaf)), leafProof, leafProofOrder | ||
); | ||
if (!leafIsValid) { | ||
revert InvalidMMRLeafProof(); | ||
} | ||
|
@@ -434,13 +443,19 @@ contract BeefyClient { | |
if (ticket.bitfieldHash != keccak256(abi.encodePacked(bitfield))) { | ||
revert InvalidBitfield(); | ||
} | ||
return Bitfield.subsample(ticket.prevRandao, bitfield, ticket.numRequiredSignatures, ticket.validatorSetLen); | ||
return Bitfield.subsample( | ||
ticket.prevRandao, bitfield, ticket.numRequiredSignatures, ticket.validatorSetLen | ||
); | ||
} | ||
|
||
/* Internal Functions */ | ||
|
||
// Creates a unique ticket ID for a new interactive prover-verifier session | ||
function createTicketID(address account, bytes32 commitmentHash) internal pure returns (bytes32 value) { | ||
function createTicketID(address account, bytes32 commitmentHash) | ||
internal | ||
pure | ||
returns (bytes32 value) | ||
{ | ||
assembly { | ||
mstore(0x00, account) | ||
mstore(0x20, commitmentHash) | ||
|
@@ -525,7 +540,11 @@ contract BeefyClient { | |
} | ||
|
||
// Ensure that the commitment provides a new MMR root | ||
function ensureProvidesMMRRoot(Commitment calldata commitment) internal pure returns (bytes32) { | ||
function ensureProvidesMMRRoot(Commitment calldata commitment) | ||
internal | ||
pure | ||
returns (bytes32) | ||
{ | ||
for (uint256 i = 0; i < commitment.payload.length; i++) { | ||
if (commitment.payload[i].payloadID == MMR_ROOT_ID) { | ||
if (commitment.payload[i].data.length != 32) { | ||
|
@@ -538,19 +557,30 @@ contract BeefyClient { | |
revert CommitmentNotRelevant(); | ||
} | ||
|
||
function encodeCommitment(Commitment calldata commitment) internal pure returns (bytes memory) { | ||
function encodeCommitment(Commitment calldata commitment) | ||
internal | ||
pure | ||
returns (bytes memory) | ||
{ | ||
return bytes.concat( | ||
encodeCommitmentPayload(commitment.payload), | ||
ScaleCodec.encodeU32(commitment.blockNumber), | ||
ScaleCodec.encodeU64(commitment.validatorSetID) | ||
); | ||
} | ||
|
||
function encodeCommitmentPayload(PayloadItem[] calldata items) internal pure returns (bytes memory) { | ||
function encodeCommitmentPayload(PayloadItem[] calldata items) | ||
internal | ||
pure | ||
returns (bytes memory) | ||
{ | ||
bytes memory payload = ScaleCodec.checkedEncodeCompactU32(items.length); | ||
for (uint256 i = 0; i < items.length; i++) { | ||
payload = bytes.concat( | ||
payload, items[i].payloadID, ScaleCodec.checkedEncodeCompactU32(items[i].data.length), items[i].data | ||
payload, | ||
items[i].payloadID, | ||
ScaleCodec.checkedEncodeCompactU32(items[i].data.length), | ||
items[i].data | ||
); | ||
} | ||
|
||
|
@@ -577,22 +607,24 @@ contract BeefyClient { | |
* @param proof Merkle proof required for validation of the address | ||
* @return true if the validator is in the set | ||
*/ | ||
function isValidatorInSet(ValidatorSetState storage vset, address account, uint256 index, bytes32[] calldata proof) | ||
internal | ||
view | ||
returns (bool) | ||
{ | ||
function isValidatorInSet( | ||
ValidatorSetState storage vset, | ||
address account, | ||
uint256 index, | ||
bytes32[] calldata proof | ||
) internal view returns (bool) { | ||
bytes32 hashedLeaf = keccak256(abi.encodePacked(account)); | ||
return SubstrateMerkleProof.verify(vset.root, hashedLeaf, index, vset.length, proof); | ||
} | ||
|
||
/** | ||
* @dev Basic validation of a ticket for submitFinal | ||
*/ | ||
function validateTicket(bytes32 ticketID, Commitment calldata commitment, uint256[] calldata bitfield) | ||
internal | ||
view | ||
{ | ||
function validateTicket( | ||
bytes32 ticketID, | ||
Commitment calldata commitment, | ||
uint256[] calldata bitfield | ||
) internal view { | ||
Ticket storage ticket = tickets[ticketID]; | ||
|
||
if (ticket.blockNumber == 0) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.25; | ||
pragma solidity 0.8.28; | ||
|
||
import {ParaID, ChannelID} from "./v1/Types.sol"; | ||
|
||
|
@@ -14,8 +14,7 @@ library Constants { | |
0x03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314; | ||
|
||
// ChannelIDs | ||
ChannelID internal constant PRIMARY_GOVERNANCE_CHANNEL_ID = | ||
ChannelID.wrap(bytes32(uint256(1))); | ||
ChannelID internal constant PRIMARY_GOVERNANCE_CHANNEL_ID = ChannelID.wrap(bytes32(uint256(1))); | ||
ChannelID internal constant SECONDARY_GOVERNANCE_CHANNEL_ID = | ||
ChannelID.wrap(bytes32(uint256(2))); | ||
} |
Oops, something went wrong.