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

ethereum: add check for the zero address in storeGuardianSet #1432

Merged
merged 1 commit into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions ethereum/contracts/Setters.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ contract Setters is State {
}

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;
}

Expand Down
57 changes: 56 additions & 1 deletion ethereum/test/wormhole.js
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,61 @@ contract("Wormhole", function () {
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 () {
const initialized = new web3.eth.Contract(ImplementationFullABI, Wormhole.address);
const accounts = await web3.eth.getAccounts();
Expand Down Expand Up @@ -621,7 +676,7 @@ contract("Wormhole", function () {
web3.eth.abi.encodeParameter("uint16", testChainId).substring(2 + (64 - 4)),
// Amount
web3.eth.abi.encodeParameter("uint256", 1).substring(2),
// Recipient
// Recipient
web3.eth.abi.encodeParameter("address", "0x0000000000000000000000000000000000000000").substring(2),
].join('')

Expand Down