-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'proxy-contracts' into proxy-contracts-comments
- Loading branch information
Showing
38 changed files
with
2,098 additions
and
454 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,44 +1,70 @@ | ||
BeefyClientTest:testScaleEncodeCommit() (gas: 32228) | ||
BeefyClientTest:testSubmit() (gas: 640426) | ||
BeefyClientTest:testSubmitFailForPrevRandaoCapturedMoreThanOnce() (gas: 269498) | ||
BeefyClientTest:testSubmitFailForPrevRandaoTooEarlyOrTooLate() (gas: 210184) | ||
BeefyClientTest:testSubmitFailInvalidSignature() (gas: 581588) | ||
BeefyClientTest:testSubmitFailValidatorNotInBitfield() (gas: 568657) | ||
BeefyClientTest:testSubmitFailWithInvalidBitfield() (gas: 559304) | ||
BeefyClientTest:testSubmitFailWithStaleCommitment() (gas: 757824) | ||
BeefyClientTest:testSubmitFailWithoutPrevRandao() (gas: 535343) | ||
BeefyClientTest:testSubmitWithHandover() (gas: 668392) | ||
BeefyClientTest:testSubmitWithHandoverFailStaleCommitment() (gas: 781735) | ||
BeefyClientTest:testSubmitWithHandoverFailWithoutPrevRandao() (gas: 559560) | ||
InboundQueueTest:testSubmit() (gas: 117979) | ||
InboundQueueTest:testSubmitShouldFailInsufficientBalance() (gas: 92436) | ||
InboundQueueTest:testSubmitShouldFailInvalidNonce() (gas: 66955) | ||
InboundQueueTest:testSubmitShouldFailInvalidProof() (gas: 62637) | ||
InboundQueueTest:testSubmitShouldNotFailOnHandlerFailure() (gas: 142351) | ||
InboundQueueTest:testSubmitShouldNotFailOnHandlerOOG() (gas: 641523) | ||
NativeTokensTest:testCreateFailOnBadFeePayment() (gas: 11593) | ||
NativeTokensTest:testCreateFailOnBadToken() (gas: 19174) | ||
NativeTokensTest:testCreateSuccessful() (gas: 79603) | ||
NativeTokensTest:testHandleRevertsUnknownOrigin() (gas: 12280) | ||
NativeTokensTest:testHandleRevertsUnknownSender() (gas: 44241) | ||
NativeTokensTest:testHandleUnlockMessageSuccessful() (gas: 154612) | ||
NativeTokensTest:testLockRevertsZeroAmount() (gas: 11361) | ||
NativeTokensTest:testLockSuccessful() (gas: 161012) | ||
OutboundQueueTest:testSubmit() (gas: 82052) | ||
OutboundQueueTest:testSubmitFailFeePaymentTooLow() (gas: 30057) | ||
ParachainClientTest:testCreateParachainHeaderMerkleFailInvalidHeader() (gas: 12690) | ||
ParachainClientTest:testCreateParachainHeaderMerkleLeaf() (gas: 23474) | ||
ParachainClientTest:testIsCommitmentInHeaderDigest() (gas: 23454) | ||
ScaleCodecTest:testEncodeU128() (gas: 193) | ||
ScaleCodecTest:testEncodeU16() (gas: 414) | ||
ScaleCodecTest:testEncodeU256() (gas: 453) | ||
ScaleCodecTest:testEncodeU32() (gas: 171) | ||
ScaleCodecTest:testEncodeU64() (gas: 281) | ||
TokenVaultTest:testDepositSuccessful() (gas: 106091) | ||
TokenVaultTest:testInsufficientBalance() (gas: 17425) | ||
TokenVaultTest:testNonOwnerCannotWithdraw() (gas: 44613) | ||
TokenVaultTest:testTokenTransferFailedInsufficientAllowance() (gas: 69957) | ||
TokenVaultTest:testWithdrawSuccessful() (gas: 121381) | ||
UpgradeProxyTest:testUpgrade() (gas: 35658) | ||
UpgradeProxyTest:testUpgradeFail() (gas: 20802) | ||
UpgradeProxyTest:testUpgradeFailBadOrigin() (gas: 11326) | ||
AgentTest:testInvoke() (gas: 20810) | ||
AgentTest:testInvokeFail() (gas: 13429) | ||
AgentTest:testInvokeUnauthorized() (gas: 13974) | ||
BeefyClientTest:testCreateFinalBitfield() (gas: 278225) | ||
BeefyClientTest:testCreateFinalBitfieldInvalid() (gas: 265008) | ||
BeefyClientTest:testCreateInitialBitfield() (gas: 650507) | ||
BeefyClientTest:testCreateInitialBitfieldInvalid() (gas: 578841) | ||
BeefyClientTest:testScaleEncodeCommit() (gas: 32353) | ||
BeefyClientTest:testSubmit():((uint32,uint64,(bytes2,bytes)[])) (gas: 708627) | ||
BeefyClientTest:testSubmitFailForPrevRandaoCapturedMoreThanOnce() (gas: 266184) | ||
BeefyClientTest:testSubmitFailForPrevRandaoTooEarlyOrTooLate() (gas: 207388) | ||
BeefyClientTest:testSubmitFailInvalidSignature() (gas: 657123) | ||
BeefyClientTest:testSubmitFailValidatorNotInBitfield() (gas: 645077) | ||
BeefyClientTest:testSubmitFailWithInvalidBitfield() (gas: 634383) | ||
BeefyClientTest:testSubmitFailWithInvalidMMRLeaf() (gas: 748779) | ||
BeefyClientTest:testSubmitFailWithInvalidMMRLeafProof() (gas: 752764) | ||
BeefyClientTest:testSubmitFailWithInvalidTicket() (gas: 638107) | ||
BeefyClientTest:testSubmitFailWithInvalidValidatorSet() (gas: 642432) | ||
BeefyClientTest:testSubmitFailWithNotEnoughClaims() (gas: 197586) | ||
BeefyClientTest:testSubmitFailWithStaleCommitment() (gas: 835952) | ||
BeefyClientTest:testSubmitFailWithoutPrevRandao() (gas: 532261) | ||
BeefyClientTest:testSubmitWithHandover() (gas: 736139) | ||
BeefyClientTest:testSubmitWithHandoverFailStaleCommitment() (gas: 859922) | ||
BeefyClientTest:testSubmitWithHandoverFailWithInvalidValidatorSet() (gas: 666242) | ||
BeefyClientTest:testSubmitWithHandoverFailWithoutPrevRandao() (gas: 556301) | ||
GatewayTest:testAgentExecution() (gas: 52791) | ||
GatewayTest:testAgentExecutionBadOrigin() (gas: 23354) | ||
GatewayTest:testAgentExecutionBadPayload() (gas: 22077) | ||
GatewayTest:testCreateAgent() (gas: 254909) | ||
GatewayTest:testCreateAgentAlreadyCreated() (gas: 256489) | ||
GatewayTest:testCreateChannel() (gas: 332117) | ||
GatewayTest:testCreateChannelFailsAgentDoesNotExist() (gas: 19185) | ||
GatewayTest:testCreateChannelFailsChannelAlreadyExists() (gas: 335995) | ||
GatewayTest:testDisableOutboundMessaging() (gas: 67040) | ||
GatewayTest:testDisableOutboundMessagingForChannel() (gas: 161374) | ||
GatewayTest:testGetters() (gas: 37883) | ||
GatewayTest:testHandlersNotExternallyCallable() (gas: 52292) | ||
GatewayTest:testInitializeNotExternallyCallable() (gas: 16762) | ||
GatewayTest:testRegisterToken() (gas: 85845) | ||
GatewayTest:testRelayerNotRewarded() (gas: 75289) | ||
GatewayTest:testRelayerRewardedFromAgent() (gas: 310728) | ||
GatewayTest:testSendTokenAddress20() (gas: 128049) | ||
GatewayTest:testSendTokenAddress20FailsInvalidDestination() (gas: 59703) | ||
GatewayTest:testSendTokenAddress32() (gas: 129387) | ||
GatewayTest:testSendTokenAddress32ToAssetHub() (gas: 128776) | ||
GatewayTest:testSetOperatingMode() (gas: 39208) | ||
GatewayTest:testSubmitFailInvalidChannel() (gas: 27926) | ||
GatewayTest:testSubmitFailInvalidNonce() (gas: 318948) | ||
GatewayTest:testSubmitHappyPath() (gas: 312342) | ||
GatewayTest:testUpdateChannel() (gas: 58121) | ||
GatewayTest:testUpdateChannelFailDoesNotExist() (gas: 20107) | ||
GatewayTest:testUpdateChannelSanityChecksForBridgeHubChannel() (gas: 22147) | ||
GatewayTest:testUpgrade() (gas: 208455) | ||
GatewayTest:testUpgradeFailCodeHashMismatch() (gas: 178843) | ||
GatewayTest:testUpgradeFailOnInitializationFailure() (gas: 182568) | ||
GatewayTest:testUserDoesNotProvideEnoughFees() (gas: 218463) | ||
GatewayTest:testUserPaysFees() (gas: 244678) | ||
GatewayTest:testWithdrawAgentFunds() (gas: 64315) | ||
MMRProofTest:testVerifyLeafProof() (gas: 370749) | ||
MMRProofTest:testVerifyLeafProofFailsExceededProofSize() (gas: 358741) | ||
ScaleCodecTest:testCheckedEncodeCompactU32() (gas: 5120) | ||
ScaleCodecTest:testEncodeCompactU32() (gas: 9722) | ||
ScaleCodecTest:testEncodeU128() (gas: 192) | ||
ScaleCodecTest:testEncodeU16() (gas: 434) | ||
ScaleCodecTest:testEncodeU256() (gas: 478) | ||
ScaleCodecTest:testEncodeU32() (gas: 170) | ||
ScaleCodecTest:testEncodeU64() (gas: 280) | ||
VerificationTest:testCreateParachainHeaderMerkleFailInvalidHeader() (gas: 11341) | ||
VerificationTest:testCreateParachainHeaderMerkleLeaf() (gas: 20830) | ||
VerificationTest:testIsCommitmentInHeaderDigest() (gas: 21863) |
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 was deleted.
Oops, something went wrong.
98 changes: 98 additions & 0 deletions
98
core/packages/contracts/scripts/generateBeefyTestFixture.ts
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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#!/usr/bin/env ts-node | ||
import { ValidatorSet, createRandomSubset, readSetBits } from "./helpers" | ||
import { BigNumber, ethers } from "ethers" | ||
import fs from "fs" | ||
import type { BeefyClient } from "../types/BeefyClient" | ||
import { accounts } from "./wallets" | ||
import path from "path" | ||
const encoder = new ethers.utils.AbiCoder() | ||
|
||
const run = async () => { | ||
const fixtureData = JSON.parse( | ||
fs.readFileSync( | ||
path.join(process.env.contract_dir || ".", "test/data/beefy-commitment.json"), | ||
"utf8" | ||
) | ||
) | ||
const BeefyValidatorSetFile = path.join( | ||
process.env.contract_dir || ".", | ||
"test/data/beefy-validator-set.json" | ||
) | ||
const BeefyBitFieldFile = path.join( | ||
process.env.contract_dir || ".", | ||
"test/data/beefy-final-bitfield.json" | ||
) | ||
const BeefyValidatorProofFile = path.join( | ||
process.env.contract_dir || ".", | ||
"test/data/beefy-final-proof.json" | ||
) | ||
const command = process.argv[2] | ||
const validatorSetID = fixtureData.params.id | ||
const validatorSetSize = | ||
process.env["FixedSet"] == "true" | ||
? accounts.length | ||
: process.env["ValidatorSetSize"] | ||
? parseInt(process.env["ValidatorSetSize"]) | ||
: 300 | ||
const commitHash = fixtureData.commitmentHash | ||
let validatorSet: ValidatorSet | ||
if (process.env["FixedSet"] == "true") { | ||
validatorSet = new ValidatorSet( | ||
validatorSetID, | ||
validatorSetSize, | ||
accounts.map((account) => account.privateKey) | ||
) | ||
} else { | ||
validatorSet = new ValidatorSet(validatorSetID, validatorSetSize) | ||
} | ||
|
||
if (command == "GenerateInitialSet") { | ||
const mmrLeaf: BeefyClient.MMRLeafStruct = fixtureData.params.leaf | ||
|
||
const absentSubsetSize = Math.floor((validatorSetSize - 1) / 3) | ||
const subsetSize = validatorSetSize - absentSubsetSize | ||
const randomSet = createRandomSubset(validatorSetSize, subsetSize) | ||
const participants = randomSet.participants | ||
const absentees = randomSet.absentees | ||
|
||
const testFixture = { | ||
validatorSetSize, | ||
participants, | ||
absentees, | ||
validatorRoot: validatorSet.root, | ||
} | ||
fs.writeFileSync(BeefyValidatorSetFile, JSON.stringify(testFixture, null, 2), "utf8") | ||
console.log("Beefy fixture writing to dest file: " + BeefyValidatorSetFile) | ||
} else if (command == "GenerateProofs") { | ||
const testFixture = JSON.parse(fs.readFileSync(BeefyBitFieldFile, "utf8")) | ||
const bitField = encoder.decode(["uint256[]"], testFixture.final.finalBitFieldRaw)[0] | ||
console.log(bitField) | ||
let finalBitfield: BigNumber[] = [] | ||
for (let i = 0; i < bitField.length; i++) { | ||
finalBitfield.push(bitField[i]) | ||
} | ||
const finalValidatorsProof: BeefyClient.ValidatorProofStruct[] = readSetBits( | ||
finalBitfield | ||
).map((i) => validatorSet.createSignatureProof(i, commitHash)) | ||
console.log("Final Validator proofs:", finalValidatorsProof) | ||
const finalValidatorsProofRaw = encoder.encode( | ||
[ | ||
"tuple(uint8 v, bytes32 r, bytes32 s, uint256 index,address account,bytes32[] proof)[]", | ||
], | ||
[finalValidatorsProof] | ||
) | ||
fs.writeFileSync( | ||
BeefyValidatorProofFile, | ||
JSON.stringify({ finalValidatorsProof, finalValidatorsProofRaw }, null, 2), | ||
"utf8" | ||
) | ||
console.log("Beefy fixture writing to dest file: " + BeefyValidatorProofFile) | ||
} | ||
} | ||
|
||
run() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.error(error) | ||
process.exit(1) | ||
}) |
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
pragma solidity 0.8.20; | ||
|
||
import {ParaID} from "./Types.sol"; | ||
import {AgentExecuteCommand, ParaID} from "./Types.sol"; | ||
import {SubstrateTypes} from "./SubstrateTypes.sol"; | ||
|
||
import {IERC20} from "./interfaces/IERC20.sol"; | ||
|
@@ -14,15 +14,13 @@ contract AgentExecutor { | |
using SafeTokenTransfer for IERC20; | ||
using SafeNativeTransfer for address payable; | ||
|
||
bytes32 internal constant COMMAND_TRANSFER_TOKEN = keccak256("transferToken"); | ||
|
||
/// @dev Execute a message which originated from the Polkadot side of the bridge. In other terms, | ||
/// the `data` parameter is constructed by the BridgeHub parachain. | ||
/// | ||
/// NOTE: There are no authorization checks here. Since this contract is only used for its code. | ||
function execute(address, bytes memory data) external { | ||
(bytes32 command, bytes memory params) = abi.decode(data, (bytes32, bytes)); | ||
if (command == COMMAND_TRANSFER_TOKEN) { | ||
(AgentExecuteCommand command, bytes memory params) = abi.decode(data, (AgentExecuteCommand, bytes)); | ||
if (command == AgentExecuteCommand.TransferToken) { | ||
(address token, address recipient, uint128 amount) = abi.decode(params, (address, address, uint128)); | ||
_transferToken(token, recipient, amount); | ||
} | ||
|
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
Oops, something went wrong.