Skip to content

Commit 20bd374

Browse files
Merge pull request #498 from EYBlockchain/westlad/unique-proposers
bug - proposers can register twice
2 parents 8a213cd + e6a9f3b commit 20bd374

File tree

3 files changed

+49
-17
lines changed

3 files changed

+49
-17
lines changed

‎nightfall-deployer/contracts/Proposers.sol

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ contract Proposers is Stateful, Structures, Config {
3131
//add the proposer to the circular linked list
3232
function registerProposer() external payable {
3333
require(REGISTRATION_BOND <= msg.value, 'The registration payment is incorrect');
34+
require(state.getProposer(msg.sender).thisAddress == address(0), 'This proposer is already registered');
3435
payable(address(state)).transfer(REGISTRATION_BOND);
3536
state.setBondAccount(msg.sender,REGISTRATION_BOND);
3637
LinkedAddress memory currentProposer = state.getCurrentProposer();

‎test/http.mjs

+39-13
Original file line numberDiff line numberDiff line change
@@ -257,19 +257,25 @@ describe('Testing the http API', () => {
257257

258258
describe('Basic Proposer tests', () => {
259259
after(async () => {
260-
// After the proposer tests, re-register proposers
261-
const myAddress = (await getAccounts())[0];
262-
const res = await chai
263-
.request(optimistUrl)
264-
.post('/proposer/register')
265-
.send({ address: myAddress });
266-
const { txDataToSign } = res.body;
267-
expect(txDataToSign).to.be.a('string');
268-
const bond = 10;
269-
const count = logCounts.registerProposer;
270-
await submitTransaction(txDataToSign, privateKey, proposersAddress, gas, bond);
271-
await waitForTxExecution(count, 'registerProposer');
272-
stateBalance += bond;
260+
// After the proposer tests, re-register proposers, if needed
261+
try {
262+
const myAddress = (await getAccounts())[0];
263+
const res = await chai
264+
.request(optimistUrl)
265+
.post('/proposer/register')
266+
.send({ address: myAddress });
267+
const { txDataToSign } = res.body;
268+
expect(txDataToSign).to.be.a('string');
269+
const bond = 10;
270+
const count = logCounts.registerProposer;
271+
await submitTransaction(txDataToSign, privateKey, proposersAddress, gas, bond);
272+
await waitForTxExecution(count, 'registerProposer');
273+
stateBalance += bond;
274+
} catch (err) {
275+
// an EVM revert almost certainly indicates that the proposer is already registered. That's
276+
// fine, it's ok to continue
277+
if (!err.message.includes('Transaction has been reverted by the EVM')) throw new Error(err);
278+
}
273279
});
274280

275281
it('should register a proposer', async () => {
@@ -306,6 +312,26 @@ describe('Testing the http API', () => {
306312
});
307313
});
308314

315+
it('should fail to register a proposer twice', async () => {
316+
const myAddress = (await getAccounts())[0];
317+
const res = await chai
318+
.request(optimistUrl)
319+
.post('/proposer/register')
320+
.send({ address: myAddress });
321+
const { txDataToSign } = res.body;
322+
expect(txDataToSign).to.be.a('string');
323+
// we have to pay 10 ETH to be registered
324+
const bond = 10;
325+
// now we need to sign the transaction and send it to the blockchain
326+
console.log('submitting tx');
327+
try {
328+
await submitTransaction(txDataToSign, privateKey, proposersAddress, gas, bond);
329+
expect.fail('Submitting the same proposer registration should have caused an EVM revert');
330+
} catch (err) {
331+
expect(err.message).to.include('Transaction has been reverted by the EVM');
332+
}
333+
});
334+
309335
it('should de-register a proposer', async () => {
310336
const myAddress = (await getAccounts())[0];
311337
const res = await chai.request(optimistUrl).post('/proposer/de-register');

‎test/neg-http.mjs

+9-4
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,15 @@ describe('Testing the challenge http API', () => {
192192
// should register a proposer
193193
const myAddress = (await getAccounts())[0];
194194
const bond = 10;
195-
res = await chai.request(optimistUrl).post('/proposer/register').send({ address: myAddress });
196-
txToSign = res.body.txDataToSign;
197-
await submitTransaction(txToSign, privateKey, proposersAddress, gas, bond);
198-
195+
try {
196+
res = await chai.request(optimistUrl).post('/proposer/register').send({ address: myAddress });
197+
txToSign = res.body.txDataToSign;
198+
await submitTransaction(txToSign, privateKey, proposersAddress, gas, bond);
199+
} catch (err) {
200+
// an EVM revert almost certainly indicates that the proposer is already registered. That's
201+
// fine, it's ok to continue
202+
if (!err.message.includes('Transaction has been reverted by the EVM')) throw new Error(err);
203+
}
199204
// should subscribe to block proposed event with the provided incoming viewing key
200205
await chai
201206
.request(url)

0 commit comments

Comments
 (0)