Update VAA structure
This commit is contained in:
parent
135b98e556
commit
59449a30b3
|
@ -3,105 +3,233 @@ package main
|
|||
import (
|
||||
"crypto/ecdsa"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/crypto"
|
||||
|
||||
"github.com/certusone/wormhole/bridge/pkg/devnet"
|
||||
"github.com/certusone/wormhole/bridge/pkg/vaa"
|
||||
)
|
||||
|
||||
func main() {
|
||||
addr := devnet.GanacheClientDefaultAccountAddress
|
||||
addrP := common.LeftPadBytes(addr[:], 32)
|
||||
addrTarget := vaa.Address{}
|
||||
copy(addrTarget[:], addrP)
|
||||
type signerInfo struct {
|
||||
signer *ecdsa.PrivateKey
|
||||
index int
|
||||
}
|
||||
|
||||
tAddr := common.HexToAddress("0x0000000000000000000000009561c133dd8580860b6b7e504bc5aa500f0f06a7")
|
||||
tAddrP := common.LeftPadBytes(tAddr[:], 32)
|
||||
tAddrTarget := vaa.Address{}
|
||||
copy(tAddrTarget[:], tAddrP)
|
||||
v := &vaa.VAA{
|
||||
func main() {
|
||||
|
||||
keys := generateKeys(6)
|
||||
for i, key := range keys {
|
||||
fmt.Printf("Key [%d]: %s\n", i, crypto.PubkeyToAddress(key.PublicKey).String())
|
||||
}
|
||||
|
||||
signAndPrintVAA(&vaa.VAA{
|
||||
Version: 1,
|
||||
GuardianSetIndex: 2,
|
||||
Timestamp: time.Unix(4000, 0),
|
||||
GuardianSetIndex: 0,
|
||||
Timestamp: time.Unix(2000, 0),
|
||||
Payload: &vaa.BodyTransfer{
|
||||
Nonce: 56,
|
||||
SourceChain: 1,
|
||||
TargetChain: 2,
|
||||
SourceAddress: vaa.Address{2, 1, 4},
|
||||
TargetAddress: addrTarget,
|
||||
TargetAddress: padAddress(devnet.GanacheClientDefaultAccountAddress),
|
||||
Asset: &vaa.AssetMeta{
|
||||
Chain: vaa.ChainIDSolana,
|
||||
Address: tAddrTarget,
|
||||
Address: hexToAddress("0x347ef34687bdc9f189e87a9200658d9c40e9988"),
|
||||
},
|
||||
Amount: big.NewInt(1000000000000000000),
|
||||
},
|
||||
}
|
||||
}, []*signerInfo{{keys[0], 0}})
|
||||
|
||||
r := rand.New(rand.NewSource(555))
|
||||
key, err := ecdsa.GenerateKey(crypto.S256(), r)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
key2, err := ecdsa.GenerateKey(crypto.S256(), r)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
key3, err := ecdsa.GenerateKey(crypto.S256(), r)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
key4, err := ecdsa.GenerateKey(crypto.S256(), r)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
key5, err := ecdsa.GenerateKey(crypto.S256(), r)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
key6, err := ecdsa.GenerateKey(crypto.S256(), r)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
signAndPrintVAA(&vaa.VAA{
|
||||
Version: 1,
|
||||
GuardianSetIndex: 0,
|
||||
Timestamp: time.Unix(2000, 0),
|
||||
Payload: &vaa.BodyTransfer{
|
||||
Nonce: 56,
|
||||
SourceChain: 1,
|
||||
TargetChain: 2,
|
||||
SourceAddress: vaa.Address{2, 1, 4},
|
||||
TargetAddress: padAddress(devnet.GanacheClientDefaultAccountAddress),
|
||||
Asset: &vaa.AssetMeta{
|
||||
Chain: vaa.ChainIDEthereum,
|
||||
Address: hexToAddress("0xd833215cbcc3f914bd1c9ece3ee7bf8b14f841bb"),
|
||||
},
|
||||
Amount: big.NewInt(1000000000000000000),
|
||||
},
|
||||
}, []*signerInfo{{keys[0], 0}})
|
||||
|
||||
//v = &vaa.VAA{
|
||||
// Version: 1,
|
||||
// GuardianSetIndex: 1,
|
||||
// Timestamp: time.Unix(5000, 0),
|
||||
// Payload: &vaa.BodyGuardianSetUpdate{
|
||||
// Keys: []common.Address{
|
||||
// crypto.PubkeyToAddress(key.PublicKey),
|
||||
// crypto.PubkeyToAddress(key2.PublicKey),
|
||||
// crypto.PubkeyToAddress(key3.PublicKey),
|
||||
// crypto.PubkeyToAddress(key4.PublicKey),
|
||||
// crypto.PubkeyToAddress(key5.PublicKey),
|
||||
// crypto.PubkeyToAddress(key6.PublicKey),
|
||||
// },
|
||||
// NewIndex: 2,
|
||||
// },
|
||||
//}
|
||||
signAndPrintVAA(&vaa.VAA{
|
||||
Version: 1,
|
||||
GuardianSetIndex: 0,
|
||||
Timestamp: time.Unix(2000, 0),
|
||||
Payload: &vaa.BodyGuardianSetUpdate{
|
||||
Keys: []common.Address{
|
||||
crypto.PubkeyToAddress(keys[1].PublicKey),
|
||||
},
|
||||
NewIndex: 1,
|
||||
},
|
||||
}, []*signerInfo{{keys[0], 0}})
|
||||
|
||||
v.AddSignature(key, 0)
|
||||
v.AddSignature(key2, 1)
|
||||
v.AddSignature(key3, 2)
|
||||
v.AddSignature(key5, 4)
|
||||
v.AddSignature(key6, 5)
|
||||
sigAddr := crypto.PubkeyToAddress(key.PublicKey)
|
||||
println(sigAddr.String())
|
||||
println(crypto.PubkeyToAddress(key2.PublicKey).String())
|
||||
println(crypto.PubkeyToAddress(key3.PublicKey).String())
|
||||
println(crypto.PubkeyToAddress(key4.PublicKey).String())
|
||||
println(crypto.PubkeyToAddress(key5.PublicKey).String())
|
||||
println(crypto.PubkeyToAddress(key6.PublicKey).String())
|
||||
signAndPrintVAA(&vaa.VAA{
|
||||
Version: 1,
|
||||
GuardianSetIndex: 0,
|
||||
Timestamp: time.Unix(2000, 0),
|
||||
Payload: &vaa.BodyGuardianSetUpdate{
|
||||
Keys: []common.Address{
|
||||
crypto.PubkeyToAddress(keys[2].PublicKey),
|
||||
},
|
||||
NewIndex: 1,
|
||||
},
|
||||
}, []*signerInfo{{keys[0], 0}})
|
||||
|
||||
vData, err := v.Marshal()
|
||||
signAndPrintVAA(&vaa.VAA{
|
||||
Version: 1,
|
||||
GuardianSetIndex: 0,
|
||||
Timestamp: time.Unix(1000, 0),
|
||||
Payload: &vaa.BodyTransfer{
|
||||
Nonce: 56,
|
||||
SourceChain: 1,
|
||||
TargetChain: 2,
|
||||
SourceAddress: vaa.Address{2, 1, 4},
|
||||
TargetAddress: padAddress(devnet.GanacheClientDefaultAccountAddress),
|
||||
Asset: &vaa.AssetMeta{
|
||||
Chain: vaa.ChainIDSolana,
|
||||
Address: hexToAddress("0x347ef34687bdc9f189e87a9200658d9c40e9988"),
|
||||
},
|
||||
Amount: big.NewInt(1000000000000000000),
|
||||
},
|
||||
}, []*signerInfo{{keys[0], 0}})
|
||||
|
||||
signAndPrintVAA(&vaa.VAA{
|
||||
Version: 1,
|
||||
GuardianSetIndex: 0,
|
||||
Timestamp: time.Unix(2000, 0),
|
||||
Payload: &vaa.BodyTransfer{
|
||||
Nonce: 56,
|
||||
SourceChain: 1,
|
||||
TargetChain: 2,
|
||||
SourceAddress: vaa.Address{2, 1, 5},
|
||||
TargetAddress: padAddress(devnet.GanacheClientDefaultAccountAddress),
|
||||
Asset: &vaa.AssetMeta{
|
||||
Chain: vaa.ChainIDSolana,
|
||||
Address: hexToAddress("0x347ef34687bdc9f189e87a9200658d9c40e9988"),
|
||||
},
|
||||
Amount: big.NewInt(1000000000000000000),
|
||||
},
|
||||
}, []*signerInfo{{keys[0], 0}})
|
||||
|
||||
signAndPrintVAA(&vaa.VAA{
|
||||
Version: 1,
|
||||
GuardianSetIndex: 1,
|
||||
Timestamp: time.Unix(2000, 0),
|
||||
Payload: &vaa.BodyTransfer{
|
||||
Nonce: 56,
|
||||
SourceChain: 1,
|
||||
TargetChain: 2,
|
||||
SourceAddress: vaa.Address{2, 1, 5},
|
||||
TargetAddress: padAddress(devnet.GanacheClientDefaultAccountAddress),
|
||||
Asset: &vaa.AssetMeta{
|
||||
Chain: vaa.ChainIDSolana,
|
||||
Address: hexToAddress("0x347ef34687bdc9f189e87a9200658d9c40e9988"),
|
||||
},
|
||||
Amount: big.NewInt(1000000000000000000),
|
||||
},
|
||||
}, []*signerInfo{{keys[1], 0}})
|
||||
|
||||
signAndPrintVAA(&vaa.VAA{
|
||||
Version: 1,
|
||||
GuardianSetIndex: 1,
|
||||
Timestamp: time.Unix(4000, 0),
|
||||
Payload: &vaa.BodyGuardianSetUpdate{
|
||||
Keys: []common.Address{
|
||||
crypto.PubkeyToAddress(keys[0].PublicKey),
|
||||
crypto.PubkeyToAddress(keys[1].PublicKey),
|
||||
crypto.PubkeyToAddress(keys[2].PublicKey),
|
||||
crypto.PubkeyToAddress(keys[3].PublicKey),
|
||||
crypto.PubkeyToAddress(keys[4].PublicKey),
|
||||
crypto.PubkeyToAddress(keys[5].PublicKey),
|
||||
},
|
||||
NewIndex: 2,
|
||||
},
|
||||
}, []*signerInfo{{keys[1], 0}})
|
||||
|
||||
signAndPrintVAA(&vaa.VAA{
|
||||
Version: 1,
|
||||
GuardianSetIndex: 2,
|
||||
Timestamp: time.Unix(4000, 0),
|
||||
Payload: &vaa.BodyTransfer{
|
||||
Nonce: 57,
|
||||
SourceChain: 1,
|
||||
TargetChain: 2,
|
||||
SourceAddress: vaa.Address{2, 1, 5},
|
||||
TargetAddress: padAddress(devnet.GanacheClientDefaultAccountAddress),
|
||||
Asset: &vaa.AssetMeta{
|
||||
Chain: vaa.ChainIDSolana,
|
||||
Address: hexToAddress("0x347ef34687bdc9f189e87a9200658d9c40e9988"),
|
||||
},
|
||||
Amount: big.NewInt(1000000000000000000),
|
||||
},
|
||||
}, []*signerInfo{{keys[0], 0}, {keys[1], 1}, {keys[2], 2}})
|
||||
|
||||
signAndPrintVAA(&vaa.VAA{
|
||||
Version: 1,
|
||||
GuardianSetIndex: 2,
|
||||
Timestamp: time.Unix(4000, 0),
|
||||
Payload: &vaa.BodyTransfer{
|
||||
Nonce: 57,
|
||||
SourceChain: 1,
|
||||
TargetChain: 2,
|
||||
SourceAddress: vaa.Address{2, 1, 5},
|
||||
TargetAddress: padAddress(devnet.GanacheClientDefaultAccountAddress),
|
||||
Asset: &vaa.AssetMeta{
|
||||
Chain: vaa.ChainIDSolana,
|
||||
Address: hexToAddress("0x347ef34687bdc9f189e87a9200658d9c40e9988"),
|
||||
},
|
||||
Amount: big.NewInt(1000000000000000000),
|
||||
},
|
||||
}, []*signerInfo{{keys[0], 0}, {keys[1], 1}, {keys[3], 3}, {keys[4], 4}, {keys[5], 5}})
|
||||
}
|
||||
|
||||
func signAndPrintVAA(vaa *vaa.VAA, signers []*signerInfo) {
|
||||
for _, signer := range signers {
|
||||
vaa.AddSignature(signer.signer, uint8(signer.index))
|
||||
}
|
||||
vData, err := vaa.Marshal()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
println(hex.EncodeToString(vData))
|
||||
}
|
||||
|
||||
func generateKeys(n int) (keys []*ecdsa.PrivateKey) {
|
||||
r := rand.New(rand.NewSource(555))
|
||||
|
||||
for i := 0; i < n; i++ {
|
||||
key, err := ecdsa.GenerateKey(crypto.S256(), r)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
keys = append(keys, key)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func hexToAddress(hex string) vaa.Address {
|
||||
hexAddr := common.HexToAddress(hex)
|
||||
return padAddress(hexAddr)
|
||||
}
|
||||
|
||||
func padAddress(address common.Address) vaa.Address {
|
||||
paddedAddress := common.LeftPadBytes(address[:], 32)
|
||||
|
||||
addr := vaa.Address{}
|
||||
copy(addr[:], paddedAddress)
|
||||
|
||||
return addr
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"encoding/binary"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
|
@ -145,15 +144,16 @@ func Unmarshal(data []byte) (*VAA, error) {
|
|||
}
|
||||
v.Timestamp = time.Unix(int64(unixSeconds), 0)
|
||||
|
||||
currentPos := len(data) - reader.Len()
|
||||
action := data[currentPos]
|
||||
payloadLength := data[currentPos+1]
|
||||
|
||||
if len(data[currentPos+2:]) != int(payloadLength) {
|
||||
return nil, fmt.Errorf("payload length does not match given payload data size")
|
||||
var (
|
||||
action uint8
|
||||
)
|
||||
if err := binary.Read(reader, binary.BigEndian, &action); err != nil {
|
||||
return nil, fmt.Errorf("failed to read action: %w", err)
|
||||
}
|
||||
|
||||
payloadReader := bytes.NewReader(data[currentPos+2:])
|
||||
currentPos := len(data) - reader.Len()
|
||||
|
||||
payloadReader := bytes.NewReader(data[currentPos:])
|
||||
var err error
|
||||
switch Action(action) {
|
||||
case ActionGuardianSetUpdate:
|
||||
|
@ -250,10 +250,6 @@ func (v *VAA) serializeBody() ([]byte, error) {
|
|||
return nil, fmt.Errorf("failed to serialize payload: %w", err)
|
||||
}
|
||||
|
||||
if len(payloadData) > math.MaxUint8 {
|
||||
return nil, fmt.Errorf("payload size exceeds maximum")
|
||||
}
|
||||
MustWrite(buf, binary.BigEndian, uint8(len(payloadData)))
|
||||
buf.Write(payloadData)
|
||||
|
||||
return buf.Bytes(), nil
|
||||
|
|
|
@ -12,7 +12,6 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
|
||||
func TestSerializeDeserialize(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
|
@ -66,11 +65,11 @@ func TestSerializeDeserialize(t *testing.T) {
|
|||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
||||
vaaData, err := test.vaa.Serialize()
|
||||
vaaData, err := test.vaa.Marshal()
|
||||
require.NoError(t, err)
|
||||
|
||||
println(hex.EncodeToString(vaaData))
|
||||
vaaParsed, err := ParseVAA(vaaData)
|
||||
vaaParsed, err := Unmarshal(vaaData)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.EqualValues(t, test.vaa, vaaParsed)
|
||||
|
|
|
@ -145,7 +145,6 @@ uint8 index of the signer (in guardian keys)
|
|||
body:
|
||||
uint32 unix seconds
|
||||
uint8 action
|
||||
uint8 payload_size
|
||||
[payload_size]uint8 payload
|
||||
```
|
||||
|
||||
|
|
|
@ -111,8 +111,7 @@ contract Wormhole {
|
|||
}
|
||||
|
||||
uint8 action = vaa.toUint8(offset + 4);
|
||||
uint8 payload_len = vaa.toUint8(offset + 5);
|
||||
bytes memory payload = vaa.slice(offset + 6, payload_len);
|
||||
bytes memory payload = vaa.slice(offset + 5, vaa.length - (offset + 5));
|
||||
|
||||
// Process VAA
|
||||
if (action == 0x01) {
|
||||
|
|
|
@ -2,11 +2,9 @@ const WrappedAsset = artifacts.require("WrappedAsset");
|
|||
const Wormhole = artifacts.require("Wormhole");
|
||||
|
||||
module.exports = async function (deployer) {
|
||||
await deployer.deploy(WrappedAsset);
|
||||
// FIXME: this offsets the deleted Schnorr contract to keep the previous deterministic addresses
|
||||
await deployer.deploy(WrappedAsset);
|
||||
await deployer.deploy(Wormhole, {
|
||||
keys: ["0x7E5F4552091A69125d5DfCb7b8C2659029395Bdf"],
|
||||
keys: ["0xbeFA429d57cD18b7F8A4d91A2da9AB4AF05d0FBe"],
|
||||
expiration_time: 0
|
||||
}, WrappedAsset.address, 1000);
|
||||
};
|
||||
|
|
|
@ -54,25 +54,24 @@ contract("Wormhole", function () {
|
|||
let bridge = await Wormhole.deployed();
|
||||
|
||||
// User locked an asset on the foreign chain and the VAA proving this is transferred in.
|
||||
await bridge.submitVAA("0x0100000000010092737a1504f3b3df8c93cb85c64a4860bb270e26026b6e37f095356a406f6af439c6b2e9775fa1c6669525f06edab033ba5d447308f4e3bdb33c0f361dc32ec3015f3700081087000000350102020104000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000000347ef34687bdc9f189e87a9200658d9c40e99880000000000000000000000000000000000000000000000004563918244f40000")
|
||||
|
||||
await bridge.submitVAA("0x01000000000100eecb367540286d326e333ea06542b82d3feaeb0dc33b1b14bda8cdf8287da2a630a9a6692112bcedee501c0947c607081d51426fa1982ef342c07f4502b584c801000007d010000000380102020104000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000000347ef34687bdc9f189e87a9200658d9c40e99880000000000000000000000000000000000000000000000000de0b6b3a7640000")
|
||||
// Expect user to have a balance of a new wrapped asset
|
||||
|
||||
// submitVAA has automatically created a new WrappedAsset for the foreign asset that has been transferred in.
|
||||
// We know the address because deterministic network. A user would see the address in the submitVAA tx log.
|
||||
let wa = new WrappedAsset("0x79183957Be84C0F4dA451E534d5bA5BA3FB9c696");
|
||||
let wa = new WrappedAsset("0x3c63250aFA2470359482d98749f2d60D2971c818");
|
||||
assert.equal(await wa.assetChain(), 1)
|
||||
// Remote asset's contract address.
|
||||
assert.equal(await wa.assetAddress(), "0x0000000000000000000000000347ef34687bdc9f189e87a9200658d9c40e9988")
|
||||
// Account that the user requests the transfer to.
|
||||
let balance = await wa.balanceOf("0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1");
|
||||
assert.equal(balance, "5000000000000000000");
|
||||
assert.equal(balance, "1000000000000000000");
|
||||
});
|
||||
|
||||
it("should not accept the same VAA twice", async function () {
|
||||
let bridge = await Wormhole.deployed();
|
||||
try {
|
||||
await bridge.submitVAA("0x0100000000010092737a1504f3b3df8c93cb85c64a4860bb270e26026b6e37f095356a406f6af439c6b2e9775fa1c6669525f06edab033ba5d447308f4e3bdb33c0f361dc32ec3015f3700081087000000350102020104000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000000347ef34687bdc9f189e87a9200658d9c40e99880000000000000000000000000000000000000000000000004563918244f40000");
|
||||
await bridge.submitVAA("0x01000000000100eecb367540286d326e333ea06542b82d3feaeb0dc33b1b14bda8cdf8287da2a630a9a6692112bcedee501c0947c607081d51426fa1982ef342c07f4502b584c801000007d010000000380102020104000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000000347ef34687bdc9f189e87a9200658d9c40e99880000000000000000000000000000000000000000000000000de0b6b3a7640000");
|
||||
} catch (e) {
|
||||
assert.equal(e.reason, "VAA was already executed")
|
||||
return
|
||||
|
@ -83,13 +82,13 @@ contract("Wormhole", function () {
|
|||
it("should burn tokens on lock", async function () {
|
||||
let bridge = await Wormhole.deployed();
|
||||
// Expect user to have a balance
|
||||
let wa = new WrappedAsset("0x79183957Be84C0F4dA451E534d5bA5BA3FB9c696")
|
||||
let wa = new WrappedAsset("0x3c63250aFA2470359482d98749f2d60D2971c818")
|
||||
|
||||
await bridge.lockAssets(wa.address, "4000000000000000000", "0x0", 2);
|
||||
await bridge.lockAssets(wa.address, "500000000000000000", "0x0", 2);
|
||||
let balance = await wa.balanceOf("0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1");
|
||||
|
||||
// Expect user balance to decrease
|
||||
assert.equal(balance, "1000000000000000000");
|
||||
assert.equal(balance, "500000000000000000");
|
||||
|
||||
// Expect contract balance to be 0 since tokens have been burned
|
||||
balance = await wa.balanceOf(bridge.address);
|
||||
|
@ -110,7 +109,7 @@ contract("Wormhole", function () {
|
|||
// Transfer of that token out of the contract should not work
|
||||
let threw = false;
|
||||
try {
|
||||
await bridge.submitVAA("0x01000000000100f0c5e4e6087c6af17ce51d6e51842a766834e252266fcccd9ad39222a262af4725ff3cd3d954fca7b9964c09f0290dfacefdcaa441f62b5128ec10dce888c0cc005f37017a1087000000350102020104000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1020000000000000000000000009561c133dd8580860b6b7e504bc5aa500f0f06a70000000000000000000000000000000000000000000000000de0b6b3a7640000");
|
||||
await bridge.submitVAA("0x01000000000100e2d8610a6cf10587ba2e4f43dc639eeacd3fb4297338955b00b7653094278082505de82418b9e0925d9dd889d0850252aa7c613e63c8b2c27ff22c0001c6336600000007d010000000380102020104000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c102000000000000000000000000d833215cbcc3f914bd1c9ece3ee7bf8b14f841bb0000000000000000000000000000000000000000000000000de0b6b3a7640000");
|
||||
} catch (e) {
|
||||
threw = true;
|
||||
}
|
||||
|
@ -124,7 +123,7 @@ contract("Wormhole", function () {
|
|||
assert.equal(ev.logs[0].event, "LogTokensLocked")
|
||||
assert.equal(ev.logs[0].args.target_chain, "3")
|
||||
assert.equal(ev.logs[0].args.token_chain, "2")
|
||||
assert.equal(ev.logs[0].args.token, "0x0000000000000000000000009561c133dd8580860b6b7e504bc5aa500f0f06a7")
|
||||
assert.equal(ev.logs[0].args.token, "0x000000000000000000000000d833215cbcc3f914bd1c9ece3ee7bf8b14f841bb")
|
||||
assert.equal(ev.logs[0].args.sender, "0x00000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1")
|
||||
assert.equal(ev.logs[0].args.recipient, "0x1230000000000000000000000000000000000000000000000000000000000000")
|
||||
assert.equal(ev.logs[0].args.amount, "1000000000000000000")
|
||||
|
@ -134,7 +133,7 @@ contract("Wormhole", function () {
|
|||
assert.equal(await token.balanceOf(bridge.address), "1000000000000000000");
|
||||
|
||||
// Transfer this token back
|
||||
await bridge.submitVAA("0x01000000000100f0c5e4e6087c6af17ce51d6e51842a766834e252266fcccd9ad39222a262af4725ff3cd3d954fca7b9964c09f0290dfacefdcaa441f62b5128ec10dce888c0cc005f37017a1087000000350102020104000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1020000000000000000000000009561c133dd8580860b6b7e504bc5aa500f0f06a70000000000000000000000000000000000000000000000000de0b6b3a7640000");
|
||||
await bridge.submitVAA("0x01000000000100e2d8610a6cf10587ba2e4f43dc639eeacd3fb4297338955b00b7653094278082505de82418b9e0925d9dd889d0850252aa7c613e63c8b2c27ff22c0001c6336600000007d010000000380102020104000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c102000000000000000000000000d833215cbcc3f914bd1c9ece3ee7bf8b14f841bb0000000000000000000000000000000000000000000000000de0b6b3a7640000");
|
||||
assert.equal(await token.balanceOf("0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1"), "1000000000000000000");
|
||||
assert.equal(await token.balanceOf(bridge.address), "0");
|
||||
});
|
||||
|
@ -144,7 +143,7 @@ contract("Wormhole", function () {
|
|||
|
||||
// Push time by 1000
|
||||
await advanceTimeAndBlock(1000);
|
||||
let ev = await bridge.submitVAA("0x010000000001003382c71a4c79e1518a6ce29c91569f6427a60a95696a3515b8c2340b6acffd723315bd1011aa779f22573882a4edfe1b8206548e134871a23f8ba0c1c7d0b5ed0100000bb801190000000101befa429d57cd18b7f8a4d91a2da9ab4af05d0fbe")
|
||||
let ev = await bridge.submitVAA("0x01000000000100a33c022217ccb87a5bc83b71e6377fff6639e7904d9e9995a42dc0867dc2b0bc5d1aacc3752ea71cf4d85278526b5dd40b0343667a2d4434a44cbf7844181a1000000007d0010000000101e06a9adfeb38a8ee4d00e89307c016d0749679bd")
|
||||
assert.lengthOf(ev.logs, 1)
|
||||
assert.equal(ev.logs[0].event, "LogGuardianSetChanged")
|
||||
|
||||
|
@ -158,7 +157,7 @@ contract("Wormhole", function () {
|
|||
// Test update guardian set VAA from guardian set 0; timestamp 2000
|
||||
let threw = false;
|
||||
try {
|
||||
await bridge.submitVAA("0x01000000000100686c37a81f0895d0db88c5c348bba8df53dedd579116327c999dc0229157c04e0304f9f8223b4e7b538ccf140de112d456d88e040bce025c1022bb840acb88390100000bb801190000000201befa429d57cd18b7f8a4d91a2da9ab4af05d0fbe")
|
||||
await bridge.submitVAA("0x01000000000100d90d6f9cbc0458599cbe4d267bc9221b54955b94cb5cb338aeb845bdc9dd275f558871ea479de9cc0b44cfb2a07344431a3adbd2f98aa86f4e12ff4aba061b7f00000007d00100000001018575df9b3c97b4e267deb92d93137844a97a0132")
|
||||
} catch (e) {
|
||||
threw = true;
|
||||
assert.equal(e.reason, "only the current guardian set can change the guardian set")
|
||||
|
@ -170,14 +169,14 @@ contract("Wormhole", function () {
|
|||
let bridge = await Wormhole.deployed();
|
||||
|
||||
// Test VAA from guardian set 0; timestamp 1000
|
||||
await bridge.submitVAA("0x01000000000100a60fd865ceee4cf34048fec8edc540f257d05c186d1ac6904d959d35ab2b6c0518feeb01fc3927b44d92746461d0ddb5ea0008de529b8a4862e18acf1fea364c00000003e81087000000360102020104000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000009561c133dd8580860b6b7e504bc5aa500f0f06a70000000000000000000000000000000000000000000000000de0b6b3a7640000")
|
||||
await bridge.submitVAA("0x0100000000010000b61ecc7b9de12de6fc7f01d8a89f8c2911329e44198d0a47768344c69eadd510fd5ab6474a24aa11a6751465fb4e2f8c81a4dbc2fc2427b4c5a981e8e63ed900000003e810000000380102020104000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000000347ef34687bdc9f189e87a9200658d9c40e99880000000000000000000000000000000000000000000000000de0b6b3a7640000")
|
||||
|
||||
await advanceTimeAndBlock(1000);
|
||||
|
||||
// Test VAA from guardian set 0; timestamp 2000 - should not work anymore
|
||||
let threw = false;
|
||||
try {
|
||||
await bridge.submitVAA("0x010000000001002a17cefb8242bc6865d3e38abd764359fcb4cb774637d483aa8690a223b334217e75d1e808dcc6999fa73fabdf20d28455fe4c3abcf565db351456df418f0b7900000007d01087000000360102020104000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000009561c133dd8580860b6b7e504bc5aa500f0f06a70000000000000000000000000000000000000000000000000de0b6b3a7640000")
|
||||
await bridge.submitVAA("0x01000000000100b7e82826980fb9f2389a6e22f7db12d5872e7900775c2c5d6ad1c3558ee7a1314f0f7f171cad73caaac0599c8914009ea9d0ef0e416404b141f844b85a5d254701000007d010000000380102020105000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000000347ef34687bdc9f189e87a9200658d9c40e99880000000000000000000000000000000000000000000000000de0b6b3a7640000")
|
||||
} catch (e) {
|
||||
threw = true;
|
||||
assert.equal(e.reason, "guardian set has expired")
|
||||
|
@ -185,7 +184,7 @@ contract("Wormhole", function () {
|
|||
assert.isTrue(threw, "guardian set did not expire")
|
||||
|
||||
// Test same transaction with guardian set 1; timestamp 2000
|
||||
await bridge.submitVAA("0x010000000101005cae5dc08ebab209640fb5b8051261a5cff25bd84a69f93ec36a4106fde6a53e7275267596a4833607aae8ae9426b7bd10d8062f06c96dc9c820e30516e32e0400000007d01087000000350102020104000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000009561c133dd8580860b6b7e504bc5aa500f0f06a70000000000000000000000000000000000000000000000000de0b6b3a7640000")
|
||||
await bridge.submitVAA("0x01000000010100a3f58fb72b3c7e242d6934718eafb3076cb0764e65d8df3e0746b0c72cca791027ac649fa0095a1c3537611f4adc0dc90aaa01fce31fac722eae898cfb06e96d01000007d010000000380102020105000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000000347ef34687bdc9f189e87a9200658d9c40e99880000000000000000000000000000000000000000000000000de0b6b3a7640000")
|
||||
});
|
||||
|
||||
it("should expire VAA", async function () {
|
||||
|
@ -224,12 +223,12 @@ contract("Wormhole", function () {
|
|||
let bridge = await Wormhole.deployed();
|
||||
|
||||
// Update to validator set 2 with 6 signers
|
||||
await bridge.submitVAA("0x010000000101006ec1d2ab1b9c24fecfc43265366038ea06d465c422cb92348d757436846fe908068e92d0bdca740c583a717da7cd525e46d80b0b945a51baae72007e456b8a240100001388017d00000002067e5f4552091a69125d5dfcb7b8c2659029395bdfbefa429d57cd18b7f8a4d91a2da9ab4af05d0fbebefa429d57cd18b7f8a4d91a2da9ab4af05d0fbebefa429d57cd18b7f8a4d91a2da9ab4af05d0fbebefa429d57cd18b7f8a4d91a2da9ab4af05d0fbebefa429d57cd18b7f8a4d91a2da9ab4af05d0fbe")
|
||||
await bridge.submitVAA("0x010000000101007a8681fbb4eb93fe71d2608bacdd6ac8d7f07987d531435fc4e0e9224fcf5d087991860eb61b73671db864e7b33894ec82f7ffb17ba5a888712fb6be11df4b030100000fa0010000000206befa429d57cd18b7f8a4d91a2da9ab4af05d0fbee06a9adfeb38a8ee4d00e89307c016d0749679bd8575df9b3c97b4e267deb92d93137844a97a01320427cda59902dc6eb0c1bd2b6d38f87c5552b348bfea822f75c42e1764c791b8fe04a7b10ddb38572f5fe0b158147e7260f14062556afc94eece55ff")
|
||||
|
||||
// Test VAA signed by only 3 signers
|
||||
let threw = false;
|
||||
try {
|
||||
await bridge.submitVAA("0x01000000020300d943f7e2f94fdb2d23d8ce270c1b981ce8058a94c46358e4fb486f9b80c685d234fe7fee41c054c5ed5aa26548e39bc23875549e72100b02aabe1e9bd4c7d9b601018ce763f32e07d8d2d69907575425ad9ffbda4be1917a64ea2f90172ae8212e2c2c04917956ab5a72b6ef4642f1673e28465567de3ad3197d1a773e28c03c40c100028ce763f32e07d8d2d69907575425ad9ffbda4be1917a64ea2f90172ae8212e2c2c04917956ab5a72b6ef4642f1673e28465567de3ad3197d1a773e28c03c40c10000000fa01087000000380102020104000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000009561c133dd8580860b6b7e504bc5aa500f0f06a70000000000000000000000000000000000000000000000000de0b6b3a7640000")
|
||||
await bridge.submitVAA("0x010000000203001dbccdb06c91929042b20a136d226890e22b07120d2854aa5c17bc1cce934cf66e2f5e31a3d883bc928346c35352a7627fb0aa7e420b73a89dc0c205780f98bc0001eadd27047cb0988ed4a7c681af758e88c628f2a3c424186044e3fd9ad8c3425f401bfc29674db720f62f08a251ff6aa3b982adb57186422cdad03cc4bfc07bb001020193d92acf2ecadad96273f122ada995700225c18d65db636db7f52e2c77906e3e0153a163c4d123b68f78cc1a8c5dbd4bdf1a26718cfc850c8278ec4a39bb470100000fa010000000390102020105000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000000347ef34687bdc9f189e87a9200658d9c40e99880000000000000000000000000000000000000000000000000de0b6b3a7640000")
|
||||
} catch (e) {
|
||||
threw = true;
|
||||
assert.equal(e.reason, "no quorum")
|
||||
|
@ -237,6 +236,6 @@ contract("Wormhole", function () {
|
|||
assert.isTrue(threw, "accepted only 3 signatures")
|
||||
|
||||
// Test VAA signed by 5 signers (all except i=3)
|
||||
await bridge.submitVAA("0x01000000020500d943f7e2f94fdb2d23d8ce270c1b981ce8058a94c46358e4fb486f9b80c685d234fe7fee41c054c5ed5aa26548e39bc23875549e72100b02aabe1e9bd4c7d9b601018ce763f32e07d8d2d69907575425ad9ffbda4be1917a64ea2f90172ae8212e2c2c04917956ab5a72b6ef4642f1673e28465567de3ad3197d1a773e28c03c40c100028ce763f32e07d8d2d69907575425ad9ffbda4be1917a64ea2f90172ae8212e2c2c04917956ab5a72b6ef4642f1673e28465567de3ad3197d1a773e28c03c40c100048ce763f32e07d8d2d69907575425ad9ffbda4be1917a64ea2f90172ae8212e2c2c04917956ab5a72b6ef4642f1673e28465567de3ad3197d1a773e28c03c40c100058ce763f32e07d8d2d69907575425ad9ffbda4be1917a64ea2f90172ae8212e2c2c04917956ab5a72b6ef4642f1673e28465567de3ad3197d1a773e28c03c40c10000000fa01087000000380102020104000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000009561c133dd8580860b6b7e504bc5aa500f0f06a70000000000000000000000000000000000000000000000000de0b6b3a7640000")
|
||||
await bridge.submitVAA("0x010000000205001dbccdb06c91929042b20a136d226890e22b07120d2854aa5c17bc1cce934cf66e2f5e31a3d883bc928346c35352a7627fb0aa7e420b73a89dc0c205780f98bc0001eadd27047cb0988ed4a7c681af758e88c628f2a3c424186044e3fd9ad8c3425f401bfc29674db720f62f08a251ff6aa3b982adb57186422cdad03cc4bfc07bb0010393f4821a0fc8248ad8eccfb6e1b6a1fb70d0294a6a2b53cb6e222205f3d9f960491fdda4e23e2dde46b084f4ac101050deecbe871eeec218217037d7974b41a301049571b8d3fbcebad1e868331570120a27cf122d33f3d5b95355fde3712ecdbd5233888ec51e5d9e960beaa9a0697f5ac69f9deae37782b874fbe8aecf064087e00105ddd37a55e2a654f5898b1863eaf8efa464797bfa602893d0bcbcc06269df6a3b4ba88c01f3ad22d23a02c8dc1cb34d28b6eb4dd3e2030b8b42ff6909537faf430000000fa010000000390102020105000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000000347ef34687bdc9f189e87a9200658d9c40e99880000000000000000000000000000000000000000000000000de0b6b3a7640000")
|
||||
});
|
||||
});
|
||||
|
|
|
@ -108,7 +108,6 @@ impl VAA {
|
|||
v.write_u8(payload.action_id())?;
|
||||
|
||||
let payload_data = payload.serialize()?;
|
||||
v.write_u8(payload_data.len() as u8)?;
|
||||
v.write(payload_data.as_slice())?;
|
||||
|
||||
Ok(v.into_inner())
|
||||
|
@ -177,7 +176,6 @@ impl VAABody {
|
|||
fn deserialize(data: &Vec<u8>) -> Result<VAABody, Error> {
|
||||
let mut payload_data = Cursor::new(data);
|
||||
let action = payload_data.read_u8()?;
|
||||
let _length = payload_data.read_u8()?;
|
||||
|
||||
let payload = match action {
|
||||
0x01 => {
|
||||
|
@ -385,7 +383,7 @@ mod tests {
|
|||
]],
|
||||
})),
|
||||
};
|
||||
let data = hex::decode("010000000001003382c71a4c79e1518a6ce29c91569f6427a60a95696a3515b8c2340b6acffd723315bd1011aa779f22573882a4edfe1b8206548e134871a23f8ba0c1c7d0b5ed0100000bb801190000000101befa429d57cd18b7f8a4d91a2da9ab4af05d0fbe").unwrap();
|
||||
let data = hex::decode("010000000001003382c71a4c79e1518a6ce29c91569f6427a60a95696a3515b8c2340b6acffd723315bd1011aa779f22573882a4edfe1b8206548e134871a23f8ba0c1c7d0b5ed0100000bb8010000000101befa429d57cd18b7f8a4d91a2da9ab4af05d0fbe").unwrap();
|
||||
let parsed_vaa = VAA::deserialize(data.as_slice()).unwrap();
|
||||
assert_eq!(vaa, parsed_vaa);
|
||||
|
||||
|
@ -433,7 +431,7 @@ mod tests {
|
|||
amount: U256::from_dec_str("5000000000000000000").unwrap(),
|
||||
})),
|
||||
};
|
||||
let data = hex::decode("0100000000010092737a1504f3b3df8c93cb85c64a4860bb270e26026b6e37f095356a406f6af439c6b2e9775fa1c6669525f06edab033ba5d447308f4e3bdb33c0f361dc32ec3015f3700081087000000350102020104000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000000347ef34687bdc9f189e87a9200658d9c40e99880000000000000000000000000000000000000000000000004563918244f40000").unwrap();
|
||||
let data = hex::decode("0100000000010092737a1504f3b3df8c93cb85c64a4860bb270e26026b6e37f095356a406f6af439c6b2e9775fa1c6669525f06edab033ba5d447308f4e3bdb33c0f361dc32ec3015f37000810000000350102020104000000000000000000000000000000000000000000000000000000000000000000000000000000000090f8bf6a479f320ead074411a4b0e7944ea8c9c1010000000000000000000000000347ef34687bdc9f189e87a9200658d9c40e99880000000000000000000000000000000000000000000000004563918244f40000").unwrap();
|
||||
let parsed_vaa = VAA::deserialize(data.as_slice()).unwrap();
|
||||
assert_eq!(vaa, parsed_vaa);
|
||||
|
||||
|
|
Loading…
Reference in New Issue