Skip to content

Commit 7e5aa59

Browse files
authored
fix: remove getAttesters from solidity contract (#16561)
Please read [contributing guidelines](CONTRIBUTING.md) and remove this line. For audit-related pull requests, please use the [audit PR template](?expand=1&template=audit.md).
2 parents 84397c2 + 6951cf9 commit 7e5aa59

File tree

12 files changed

+75
-59
lines changed

12 files changed

+75
-59
lines changed

l1-contracts/src/core/Rollup.sol

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -389,17 +389,6 @@ contract Rollup is IStaking, IValidatorSelection, IRollup, RollupCore {
389389
return ValidatorOperationsExtLib.getSampleSeedAt(getCurrentEpoch());
390390
}
391391

392-
/**
393-
* @notice Get the attester set
394-
*
395-
* @dev Consider removing this to replace with a `size` and individual getter.
396-
*
397-
* @return The validator set
398-
*/
399-
function getAttesters() external view override(IValidatorSelection) returns (address[] memory) {
400-
return StakingLib.getAttestersAtTime(Timestamp.wrap(block.timestamp));
401-
}
402-
403392
/**
404393
* @notice Get the current slot number
405394
*

l1-contracts/src/core/interfaces/IValidatorSelection.sol

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ interface IValidatorSelection is IValidatorSelectionCore, IEmperor {
3535
// Consider removing below this point
3636
function getTimestampForSlot(Slot _slotNumber) external view returns (Timestamp);
3737

38-
// Likely removal of these to replace with a size and individual getter
39-
// Get the current epoch committee
40-
function getAttesters() external view returns (address[] memory);
41-
4238
function getSampleSeedAt(Timestamp _ts) external view returns (uint256);
4339
function getCurrentSampleSeed() external view returns (uint256);
4440

l1-contracts/src/core/libraries/rollup/StakingLib.sol

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,6 @@ library StakingLib {
450450
return getStorage().gse.getAttesterCountAtTime(address(this), _timestamp);
451451
}
452452

453-
function getAttestersAtTime(Timestamp _timestamp) internal view returns (address[] memory) {
454-
return getStorage().gse.getAttestersAtTime(address(this), _timestamp);
455-
}
456-
457453
function getAttesterAtIndex(uint256 _index) internal view returns (address) {
458454
return getStorage().gse.getAttesterFromIndexAtTime(address(this), _index, Timestamp.wrap(block.timestamp));
459455
}

l1-contracts/src/governance/GSE.sol

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ interface IGSE is IGSECore {
8080
view
8181
returns (address[] memory);
8282
function getG1PublicKeysFromAddresses(address[] memory _attesters) external view returns (G1Point[] memory);
83-
function getAttestersAtTime(address _instance, Timestamp _timestamp) external view returns (address[] memory);
8483
function getAttesterFromIndexAtTime(address _instance, uint256 _index, Timestamp _timestamp)
8584
external
8685
view
@@ -698,29 +697,6 @@ contract GSE is IGSE, GSECore {
698697
return delegation.getVotingPower(_delegatee);
699698
}
700699

701-
/**
702-
* @notice Get the addresses of the attesters at the instance at the time of `_timestamp`
703-
*
704-
* @param _instance - The instance to look at
705-
* @param _timestamp - The timestamp to lookup
706-
*
707-
* @return The attesters at the instance at the time of `_timestamp`
708-
*/
709-
function getAttestersAtTime(address _instance, Timestamp _timestamp)
710-
external
711-
view
712-
override(IGSE)
713-
returns (address[] memory)
714-
{
715-
uint256 count = getAttesterCountAtTime(_instance, _timestamp);
716-
uint256[] memory indices = new uint256[](count);
717-
for (uint256 i = 0; i < count; i++) {
718-
indices[i] = i;
719-
}
720-
721-
return _getAddressFromIndicesAtTimestamp(_instance, indices, _timestamp);
722-
}
723-
724700
function getAttestersFromIndicesAtTime(address _instance, Timestamp _timestamp, uint256[] memory _indices)
725701
external
726702
view

l1-contracts/test/governance/gse/gse/static.t.sol

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,17 +83,26 @@ contract StaticTest is WithGSE {
8383
// As _instance is latest, it will also get attesters[1]
8484
assertEq(gse.getAttesterFromIndexAtTime(_instance, 1, ts), _attesters[1], "invalid attester");
8585

86-
address[] memory attesters = gse.getAttestersAtTime(_instance, ts);
86+
address[] memory attesters = getAttestersAtTime(_instance, ts);
8787
assertEq(attesters.length, 2, "invalid attesters");
8888
assertEq(attesters[0], _attesters[0], "invalid attester");
8989
assertEq(attesters[1], _attesters[1], "invalid attester");
9090

9191
// Note the indexes of this can look strange as it first the specific then the bonus
92-
attesters = gse.getAttestersAtTime(_instance, ts2);
92+
attesters = getAttestersAtTime(_instance, ts2);
9393
assertEq(attesters.length, 4, "invalid attesters");
9494
assertEq(attesters[0], _attesters[0], "invalid attester");
9595
assertEq(attesters[1], _attesters[2], "invalid attester");
9696
assertEq(attesters[2], _attesters[1], "invalid attester");
9797
assertEq(attesters[3], _attesters[3], "invalid attester");
9898
}
99+
100+
function getAttestersAtTime(address _instance, Timestamp _timestamp) internal view returns (address[] memory) {
101+
uint256 count = gse.getAttesterCountAtTime(_instance, _timestamp);
102+
address[] memory attesters = new address[](count);
103+
for (uint256 i = 0; i < count; i++) {
104+
attesters[i] = gse.getAttesterFromIndexAtTime(_instance, i, _timestamp);
105+
}
106+
return attesters;
107+
}
99108
}

l1-contracts/test/staking/flushEntryQueue.t.sol

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,9 @@ contract FlushEntryQueueTest is StakingBase {
205205
GSE gse = staking.getGSE();
206206
address bonusInstanceAddress = gse.BONUS_INSTANCE_ADDRESS();
207207
uint256 initialActiveAttesterCount = staking.getActiveAttesterCount();
208-
uint256 initialCanonicalCount = gse.getAttestersAtTime(bonusInstanceAddress, Timestamp.wrap(block.timestamp)).length;
209-
uint256 initialInstanceCount = gse.getAttestersAtTime(address(staking), Timestamp.wrap(block.timestamp)).length;
208+
uint256 initialCanonicalCount =
209+
getAttestersAtTime(gse, bonusInstanceAddress, Timestamp.wrap(block.timestamp)).length;
210+
uint256 initialInstanceCount = getAttestersAtTime(gse, address(staking), Timestamp.wrap(block.timestamp)).length;
210211

211212
for (uint256 i = 1; i <= _numValidators; i++) {
212213
bool onCanonical = i % 2 == 0;
@@ -293,7 +294,7 @@ contract FlushEntryQueueTest is StakingBase {
293294

294295
// Check the canonical set has the proper validators
295296
address[] memory attestersOnCanonical =
296-
gse.getAttestersAtTime(bonusInstanceAddress, Timestamp.wrap(block.timestamp));
297+
getAttestersAtTime(gse, bonusInstanceAddress, Timestamp.wrap(block.timestamp));
297298
assertEq(
298299
attestersOnCanonical.length, initialCanonicalCount + onCanonicalCount, "invalid number of attesters on canonical"
299300
);
@@ -304,7 +305,7 @@ contract FlushEntryQueueTest is StakingBase {
304305
}
305306

306307
// Check the instance set has the proper validators
307-
address[] memory attestersOnInstance = gse.getAttestersAtTime(address(staking), Timestamp.wrap(block.timestamp));
308+
address[] memory attestersOnInstance = getAttestersAtTime(gse, address(staking), Timestamp.wrap(block.timestamp));
308309
assertEq(attestersOnInstance.length, initialInstanceCount + depositCount, "invalid number of attesters on instance");
309310
emit log_named_uint("depositCount", depositCount);
310311
emit log_named_uint("onCanonicalCount", onCanonicalCount);
@@ -318,4 +319,17 @@ contract FlushEntryQueueTest is StakingBase {
318319
);
319320
}
320321
}
322+
323+
function getAttestersAtTime(GSE _gse, address _instance, Timestamp _timestamp)
324+
internal
325+
view
326+
returns (address[] memory)
327+
{
328+
uint256 count = _gse.getAttesterCountAtTime(_instance, _timestamp);
329+
address[] memory attesters = new address[](count);
330+
for (uint256 i = 0; i < count; i++) {
331+
attesters[i] = _gse.getAttesterFromIndexAtTime(_instance, i, _timestamp);
332+
}
333+
return attesters;
334+
}
321335
}

l1-contracts/test/validator-selection/ValidatorSelection.t.sol

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,19 @@ contract ValidatorSelectionTest is ValidatorSelectionTestBase {
116116
bytes4 NO_REVERT = bytes4(0);
117117
bytes4 ANY_REVERT = bytes4(0xFFFFFFFF);
118118

119+
function getAttesters() internal view returns (address[] memory) {
120+
GSE gse = rollup.getGSE();
121+
uint256 count = rollup.getActiveAttesterCount();
122+
address[] memory attesters = new address[](count);
123+
for (uint256 i = 0; i < count; i++) {
124+
attesters[i] = gse.getAttesterFromIndexAtTime(address(rollup), i, Timestamp.wrap(block.timestamp));
125+
}
126+
127+
return attesters;
128+
}
129+
119130
function testInitialCommitteeMatch() public setup(4, 4) progressEpochs(2) {
120-
address[] memory attesters = rollup.getAttesters();
131+
address[] memory attesters = getAttesters();
121132
address[] memory committee = rollup.getCurrentEpochCommittee();
122133
assertEq(rollup.getCurrentEpoch(), 2);
123134
assertEq(attesters.length, 4, "Invalid validator set size");
@@ -165,7 +176,7 @@ contract ValidatorSelectionTest is ValidatorSelectionTestBase {
165176

166177
Epoch post = rollup.getCurrentEpoch();
167178

168-
uint256 validatorSetSize = rollup.getAttesters().length;
179+
uint256 validatorSetSize = rollup.getActiveAttesterCount();
169180
uint256 targetCommitteeSize = rollup.getTargetCommitteeSize();
170181
uint256 expectedSize = validatorSetSize > targetCommitteeSize ? targetCommitteeSize : validatorSetSize;
171182

@@ -220,7 +231,7 @@ contract ValidatorSelectionTest is ValidatorSelectionTestBase {
220231
function testValidatorSetLargerThanCommittee(bool _insufficientSigs) public setup(100, 48) progressEpochs(2) {
221232
uint256 committeeSize = rollup.getTargetCommitteeSize();
222233
uint256 signatureCount = committeeSize * 2 / 3 + (_insufficientSigs ? 0 : 1);
223-
assertGt(rollup.getAttesters().length, committeeSize, "Not enough validators");
234+
assertGt(rollup.getActiveAttesterCount(), committeeSize, "Not enough validators");
224235

225236
ProposeTestData memory ree =
226237
_testBlock("mixed_block_1", NO_REVERT, signatureCount, committeeSize, TestFlagsLib.empty());
@@ -280,7 +291,7 @@ contract ValidatorSelectionTest is ValidatorSelectionTestBase {
280291
_testBlock("mixed_block_1", NO_REVERT, 3, 4, TestFlagsLib.empty());
281292
_testBlock("mixed_block_2", NO_REVERT, 3, 4, TestFlagsLib.empty());
282293

283-
address[] memory attesters = rollup.getAttesters();
294+
address[] memory attesters = getAttesters();
284295
uint256[] memory stakes = new uint256[](attesters.length);
285296
uint128[][] memory offenses = new uint128[][](attesters.length);
286297
uint96[] memory amounts = new uint96[](attesters.length);

yarn-project/end-to-end/src/e2e_p2p/gossip_network_no_cheat.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { Archiver } from '@aztec/archiver';
22
import type { AztecNodeService } from '@aztec/aztec-node';
33
import { EthAddress, Fr, sleep } from '@aztec/aztec.js';
44
import { addL1Validator } from '@aztec/cli/l1';
5+
import { RollupContract } from '@aztec/ethereum';
56
import { MockZKPassportVerifierAbi } from '@aztec/l1-artifacts/MockZKPassportVerifierAbi';
67
import { RollupAbi } from '@aztec/l1-artifacts/RollupAbi';
78
import { StakingAssetHandlerAbi } from '@aztec/l1-artifacts/StakingAssetHandlerAbi';
@@ -91,6 +92,8 @@ describe('e2e_p2p_network', () => {
9192

9293
const { validators } = t.getValidators();
9394

95+
const rollupWrapper = RollupContract.getFromL1ContractsValues(t.ctx.deployL1ContractsValues);
96+
9497
const rollup = getContract({
9598
address: t.ctx.deployL1ContractsValues.l1ContractAddresses.rollupAddress.toString(),
9699
abi: RollupAbi,
@@ -109,7 +112,7 @@ describe('e2e_p2p_network', () => {
109112
client: t.ctx.deployL1ContractsValues.l1Client,
110113
});
111114

112-
expect((await rollup.read.getAttesters()).length).toBe(0);
115+
expect((await rollupWrapper.getAttesters()).length).toBe(0);
113116

114117
// Add the validators to the rollup using the same function as the CLI
115118
for (let i = 0; i < validators.length; i++) {
@@ -140,21 +143,21 @@ describe('e2e_p2p_network', () => {
140143
hash: await rollup.write.flushEntryQueue(),
141144
});
142145

143-
const attestersImmedatelyAfterAdding = await rollup.read.getAttesters();
146+
const attestersImmedatelyAfterAdding = await rollupWrapper.getAttesters();
144147
expect(attestersImmedatelyAfterAdding.length).toBe(validators.length);
145148

146149
// Check that the validators are added correctly
147150
const withdrawer = await stakingAssetHandler.read.withdrawer();
148151
for (const validator of validators) {
149-
const info = await rollup.read.getAttesterView([validator.attester.toString()]);
152+
const info = await rollupWrapper.getAttesterView(validator.attester.toString());
150153
expect(info.config.withdrawer).toBe(withdrawer);
151154
}
152155

153156
// Wait for the validators to be added to the rollup
154157
const timestamp = await t.ctx.cheatCodes.rollup.advanceToEpoch(2n);
155158

156159
// Changes have now taken effect
157-
const attesters = await rollup.read.getAttesters();
160+
const attesters = await rollupWrapper.getAttesters();
158161
expect(attesters.length).toBe(validators.length);
159162
expect(attesters.length).toBe(NUM_VALIDATORS);
160163

yarn-project/ethereum/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@aztec/l1-artifacts": "workspace:^",
3737
"@viem/anvil": "^0.0.10",
3838
"dotenv": "^16.0.3",
39+
"lodash.chunk": "^4.2.0",
3940
"lodash.pickby": "^4.5.0",
4041
"tslib": "^2.4.0",
4142
"viem": "2.23.7",

yarn-project/ethereum/src/contracts/gse.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ export class GSEContract {
3939
this.gse = getContract({ address, abi: GSEAbi, client });
4040
}
4141

42+
getAttestersFromIndicesAtTime(instance: Hex | EthAddress, ts: bigint, indices: bigint[]) {
43+
if (instance instanceof EthAddress) {
44+
instance = instance.toString();
45+
}
46+
return this.gse.read.getAttestersFromIndicesAtTime([instance, ts, indices]);
47+
}
48+
4249
public async getRegistrationDigest(publicKey: ProjPointType<bigint>): Promise<ProjPointType<bigint>> {
4350
const affinePublicKey = publicKey.toAffine();
4451
const g1PointDigest = await this.gse.read.getRegistrationDigest([{ x: affinePublicKey.x, y: affinePublicKey.y }]);

0 commit comments

Comments
 (0)