add check for the zero address in storeGuardianSet
Change-Id: Ic3c5fce71f687d98380d39dc62923d9c6423e194
This commit is contained in:
parent
52737f8455
commit
6c6b25ab2a
|
@ -15,6 +15,10 @@ contract Setters is State {
|
||||||
}
|
}
|
||||||
|
|
||||||
function storeGuardianSet(Structs.GuardianSet memory set, uint32 index) internal {
|
function storeGuardianSet(Structs.GuardianSet memory set, uint32 index) internal {
|
||||||
|
uint setLength = set.keys.length;
|
||||||
|
for (uint i = 0; i < setLength; i++) {
|
||||||
|
require(set.keys[i] != address(0), "Invalid key");
|
||||||
|
}
|
||||||
_state.guardianSets[index] = set;
|
_state.guardianSets[index] = set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -490,6 +490,61 @@ contract("Wormhole", function () {
|
||||||
assert.equal(receiverAfter - receiverBefore, 11);
|
assert.equal(receiverAfter - receiverBefore, 11);
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should revert when submitting a new guardian set with the zero address", async function () {
|
||||||
|
const initialized = new web3.eth.Contract(ImplementationFullABI, Wormhole.address);
|
||||||
|
const accounts = await web3.eth.getAccounts();
|
||||||
|
|
||||||
|
const timestamp = 1000;
|
||||||
|
const nonce = 1001;
|
||||||
|
const emitterChainId = testGovernanceChainId;
|
||||||
|
const emitterAddress = testGovernanceContract;
|
||||||
|
const zeroAddress = "0x0000000000000000000000000000000000000000";
|
||||||
|
|
||||||
|
let oldIndex = Number(await initialized.methods.getCurrentGuardianSetIndex().call());
|
||||||
|
|
||||||
|
data = [
|
||||||
|
// Core
|
||||||
|
core,
|
||||||
|
// Action 2 (Guardian Set Upgrade)
|
||||||
|
actionGuardianSetUpgrade,
|
||||||
|
web3.eth.abi.encodeParameter("uint16", testChainId).substring(2 + (64 - 4)),
|
||||||
|
web3.eth.abi.encodeParameter("uint32", oldIndex + 1).substring(2 + (64 - 8)),
|
||||||
|
web3.eth.abi.encodeParameter("uint8", 3).substring(2 + (64 - 2)),
|
||||||
|
web3.eth.abi.encodeParameter("address", testSigner1.address).substring(2 + (64 - 40)),
|
||||||
|
web3.eth.abi.encodeParameter("address", testSigner2.address).substring(2 + (64 - 40)),
|
||||||
|
web3.eth.abi.encodeParameter("address", zeroAddress).substring(2 + (64 - 40)),
|
||||||
|
].join('')
|
||||||
|
|
||||||
|
const vm = await signAndEncodeVM(
|
||||||
|
timestamp,
|
||||||
|
nonce,
|
||||||
|
emitterChainId,
|
||||||
|
emitterAddress,
|
||||||
|
0,
|
||||||
|
data,
|
||||||
|
[
|
||||||
|
testSigner1PK
|
||||||
|
],
|
||||||
|
0,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
|
||||||
|
// try to submit a new guardian set including the zero address
|
||||||
|
failed = false;
|
||||||
|
try {
|
||||||
|
await initialized.methods.submitNewGuardianSet("0x" + vm).send({
|
||||||
|
value: 0,
|
||||||
|
from: accounts[0],
|
||||||
|
gasLimit: 1000000
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
assert.equal(e.message, "Returned error: VM Exception while processing transaction: revert Invalid key");
|
||||||
|
failed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.ok(failed);
|
||||||
|
})
|
||||||
|
|
||||||
it("should accept a new guardian set", async function () {
|
it("should accept a new guardian set", async function () {
|
||||||
const initialized = new web3.eth.Contract(ImplementationFullABI, Wormhole.address);
|
const initialized = new web3.eth.Contract(ImplementationFullABI, Wormhole.address);
|
||||||
const accounts = await web3.eth.getAccounts();
|
const accounts = await web3.eth.getAccounts();
|
||||||
|
|
Loading…
Reference in New Issue