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

Block hash publisher #51

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3120b71
apply getVerifiedWarpMessage and sourceChainID changes
Sep 8, 2023
2eb3587
Merge remote-tracking branch 'origin/main' into integrate-warp-changes
Sep 20, 2023
4174ab2
update subnet-evm commit to v0.5.6
Sep 20, 2023
2edfb9b
update golang version and genesis template
Sep 20, 2023
7ee3a09
reformat genesis template
Sep 20, 2023
33b8d4c
add dupgrade config to genesis template
Sep 20, 2023
bd3656f
add index to receiveCrossChainMessage
Sep 22, 2023
e496ee0
fix unit test
Sep 22, 2023
e72ddb9
test added buffer gas
Sep 26, 2023
93ec7bd
add unit test for receive index
Sep 26, 2023
d6b1fe4
fix comment
Sep 26, 2023
9118693
remove abi
Sep 26, 2023
65b6110
update naming and parameter order
Sep 26, 2023
00fc76a
Update contracts/src/Teleporter/ITeleporterMessenger.sol
Sep 26, 2023
a52b2b9
basic block hash receiver
cam-schultz Sep 26, 2023
442e9d2
Merge branch 'main' into block-hash-publisher
cam-schultz Sep 27, 2023
c08725f
block hash go binding
cam-schultz Sep 27, 2023
43ad4b3
block hash packing
cam-schultz Sep 28, 2023
4544d91
Merge branch 'main' into block-hash-publisher
cam-schultz Sep 29, 2023
feb8fe1
Merge branch 'main' into block-hash-publisher
cam-schultz Oct 5, 2023
9b7af3f
cleanup var
cam-schultz Oct 5, 2023
a8e949b
block hash receiver abigen
cam-schultz Oct 5, 2023
cab06ce
Merge branch 'main' into block-hash-publisher
cam-schultz Oct 5, 2023
0810228
set up third test subnet
cam-schultz Oct 13, 2023
cc3978f
cleanup
cam-schultz Oct 19, 2023
d5b8203
update binding
cam-schultz Oct 19, 2023
050fbd0
update pack function
cam-schultz Oct 19, 2023
8b7ddde
Merge branch 'main' into block-hash-publisher
cam-schultz Dec 6, 2023
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

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions abi-bindings/Teleporter/TeleporterBlockHashReceiver/packing.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package teleporterblockhashreceiver

// Pack packs a ReceiveCrossChainMessageInput to form a call to the receiveCrossChainMessage function
func PackReceiveBlockHash(messageIndex uint32) ([]byte, error) {
abi, err := TeleporterBlockHashReceiverMetaData.GetAbi()
if err != nil {
return nil, err
}
return abi.Pack("receiveBlockHash", messageIndex)
}
1 change: 1 addition & 0 deletions contracts/src/.solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
}
],
"reason-string": ["off"],
"custom-errors": "off",
"ordering": "warn",
"immutable-vars-naming": [
"warn",
Expand Down
29 changes: 29 additions & 0 deletions contracts/src/Teleporter/ITeleporterBlockHashReceiver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// (c) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

// SPDX-License-Identifier: Ecosystem

pragma solidity 0.8.18;

/**
* @dev Interface that describes functionalities for receiving block hashes from other chains.
*/
interface ITeleporterBlockHashReceiver {
/**
* @dev Emitted when a block hash is successfully received.
*/
event ReceiveBlockHash(
bytes32 indexed originChainID,
bytes32 indexed blockHash
);

/**
* @dev Receives a block hash from another chain.
*
* The message specified by `messageIndex` must be provided at that index in the access list storage slots of the transaction,
* and is verified in the precompile predicate.
*/
function receiveBlockHash(
uint32 messageIndex
) external;
}
41 changes: 41 additions & 0 deletions contracts/src/Teleporter/TeleporterBlockHashReceiver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// (c) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

// SPDX-License-Identifier: Ecosystem

pragma solidity 0.8.18;

import "@subnet-evm-contracts/interfaces/IWarpMessenger.sol";
import "./ReentrancyGuards.sol";
import "./ITeleporterBlockHashReceiver.sol";

/**
* @dev Implementation of the {ITeleporterBlockHashReceiver} interface.
*
* This implementation is used to receive block hashes from other chains using the WarpMessenger precompile
*/
contract TeleporterBlockHashReceiver is ITeleporterBlockHashReceiver, ReentrancyGuards {
WarpMessenger public constant WARP_MESSENGER =
WarpMessenger(0x0200000000000000000000000000000000000005);

/**
* @dev See {ITeleporterBlockHashReceiver-receiveBlockHash}
*
* Emits a {ReceiveBlockHash} event when a block hash is verified..
*/
function receiveBlockHash(
uint32 messageIndex
) external receiverNonReentrant {
// Verify and parse the block hash payload included in the transaction access list
// using the warp message precompile.
(WarpBlockHash memory warpBlockHash, bool success) = WARP_MESSENGER
.getVerifiedWarpBlockHash(messageIndex);

require(success, "TeleporterBlockHashReceiver: invalid warp message");

emit ReceiveBlockHash(
warpBlockHash.sourceChainID,
warpBlockHash.blockHash
);
}
}
2 changes: 1 addition & 1 deletion scripts/abi_go_bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ TELEPORTER_PATH=$(
cd .. && pwd
)

DEFAULT_CONTRACT_LIST="TeleporterMessenger ERC20Bridge ExampleCrossChainMessenger BlockHashPublisher BlockHashReceiver BridgeToken"
DEFAULT_CONTRACT_LIST="TeleporterMessenger TeleporterBlockHashReceiver ERC20Bridge ExampleCrossChainMessenger BlockHashPublisher BlockHashReceiver BridgeToken"

CONTRACT_LIST=
HELP=
Expand Down
67 changes: 54 additions & 13 deletions tests/utils/network_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ const (
)

var (
teleporterContractAddress common.Address
subnetA, subnetB ids.ID
blockchainIDA, blockchainIDB ids.ID
chainANodeURIs, chainBNodeURIs []string
fundedAddress = common.HexToAddress("0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC")
fundedKey *ecdsa.PrivateKey
chainAWSClient, chainBWSClient ethclient.Client
chainAWSURI, chainBWSURI string
chainAIDInt, chainBIDInt *big.Int
teleporterContractAddress common.Address
subnetA, subnetB, subnetC ids.ID
blockchainIDA, blockchainIDB, blockchainIDC ids.ID
chainANodeURIs, chainBNodeURIs, chainCNodeURIs []string
fundedAddress = common.HexToAddress("0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC")
fundedKey *ecdsa.PrivateKey
chainAWSClient, chainBWSClient, chainCWSClient ethclient.Client
chainAWSURI, chainBWSURI, chainCWSURI string
chainAIDInt, chainBIDInt, chainCIDInt *big.Int

// Internal vars only used to set up the local network
anrConfig = runner.NewDefaultANRConfig()
Expand All @@ -60,6 +60,7 @@ func GetSubnetsInfo() []SubnetTestInfo {
return []SubnetTestInfo{
GetSubnetATestInfo(),
GetSubnetBTestInfo(),
GetSubnetCTestInfo(),
}
}

Expand All @@ -83,6 +84,16 @@ func GetSubnetBTestInfo() SubnetTestInfo {
ChainIDInt: big.NewInt(0).Set(chainBIDInt),
}
}
func GetSubnetCTestInfo() SubnetTestInfo {
return SubnetTestInfo{
SubnetID: subnetC,
BlockchainID: blockchainIDC,
ChainNodeURIs: chainCNodeURIs,
ChainWSClient: chainCWSClient,
ChainWSURI: chainCWSURI,
ChainIDInt: big.NewInt(0).Set(chainCIDInt),
}
}
func GetTeleporterContractAddress() common.Address {
return teleporterContractAddress
}
Expand All @@ -100,15 +111,18 @@ func SetupNetwork(warpGenesisFile string) {
ctx := context.Background()
var err error

// Name 10 new validators (which should have BLS key registered)
// Name 15 new validators (which should have BLS key registered)
subnetANodeNames := []string{}
subnetBNodeNames := []string{}
for i := 1; i <= 10; i++ {
subnetCNodeNames := []string{}
for i := 1; i <= 15; i++ {
n := fmt.Sprintf("node%d-bls", i)
if i <= 5 {
subnetANodeNames = append(subnetANodeNames, n)
} else {
} else if i <= 10 {
subnetBNodeNames = append(subnetBNodeNames, n)
} else {
subnetCNodeNames = append(subnetCNodeNames, n)
}
}
f, err := os.CreateTemp(os.TempDir(), "config.json")
Expand Down Expand Up @@ -146,6 +160,15 @@ func SetupNetwork(warpGenesisFile string) {
Participants: subnetBNodeNames,
},
},
{
VmName: evm.IDStr,
Genesis: warpGenesisFile,
ChainConfig: warpChainConfigPath,
SubnetSpec: &rpcpb.SubnetSpec{
SubnetConfig: "",
Participants: subnetCNodeNames,
},
},
},
)
Expect(err).Should(BeNil())
Expand All @@ -155,10 +178,11 @@ func SetupNetwork(warpGenesisFile string) {
Expect(err).Should(BeNil())
SetupProposerVM(ctx, fundedKey, manager, 0)
SetupProposerVM(ctx, fundedKey, manager, 1)
SetupProposerVM(ctx, fundedKey, manager, 2)

// Set up subnet URIs
subnetIDs := manager.GetSubnets()
Expect(len(subnetIDs)).Should(Equal(2))
Expect(len(subnetIDs)).Should(Equal(3))

subnetA = subnetIDs[0]
subnetADetails, ok := manager.GetSubnet(subnetA)
Expand All @@ -174,12 +198,21 @@ func SetupNetwork(warpGenesisFile string) {
blockchainIDB = subnetBDetails.BlockchainID
chainBNodeURIs = append(chainBNodeURIs, subnetBDetails.ValidatorURIs...)

subnetC = subnetIDs[2]
subnetCDetails, ok := manager.GetSubnet(subnetC)
Expect(ok).Should(BeTrue())
Expect(len(subnetCDetails.ValidatorURIs)).Should(Equal(5))
blockchainIDC = subnetCDetails.BlockchainID
chainCNodeURIs = append(chainCNodeURIs, subnetCDetails.ValidatorURIs...)

log.Info(
"Created URIs for subnets",
"chainAURIs", chainANodeURIs,
"chainBURIs", chainBNodeURIs,
"chainCURIs", chainCNodeURIs,
"blockchainIDA", blockchainIDA,
"blockchainIDB", blockchainIDB,
"blockchainIDC", blockchainIDC,
)

chainAWSURI := HttpToWebsocketURI(chainANodeURIs[0], blockchainIDA.String())
Expand All @@ -198,6 +231,14 @@ func SetupNetwork(warpGenesisFile string) {
chainBIDInt, err = chainBWSClient.ChainID(context.Background())
Expect(err).Should(BeNil())

chainCWSURI := HttpToWebsocketURI(chainCNodeURIs[0], blockchainIDC.String())
log.Info("Creating ethclient for blockchainC", "wsURI", chainCWSURI)
chainCWSClient, err = ethclient.Dial(chainCWSURI)
Expect(err).Should(BeNil())

chainCIDInt, err = chainCWSClient.ChainID(context.Background())
Expect(err).Should(BeNil())

log.Info("Finished setting up e2e test subnet variables")
}

Expand Down
4 changes: 2 additions & 2 deletions tests/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ func SendTransactionAndWaitForAcceptance(
tx *types.Transaction) *types.Receipt {

newHeads := make(chan *types.Header, 1)
subA, err := wsClient.SubscribeNewHead(ctx, newHeads)
sub, err := wsClient.SubscribeNewHead(ctx, newHeads)
Expect(err).Should(BeNil())
defer subA.Unsubscribe()
defer sub.Unsubscribe()

err = wsClient.SendTransaction(ctx, tx)
Expect(err).Should(BeNil())
Expand Down