Skip to content

Commit

Permalink
Remove maxDeposits arg from depositBufferedEther()
Browse files Browse the repository at this point in the history
  • Loading branch information
bulbozaur committed Oct 18, 2021
1 parent 39b013d commit 5af2875
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 207 deletions.
13 changes: 5 additions & 8 deletions contracts/0.8.9/DepositSecurityModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,14 @@ contract DepositSecurityModule {


/**
* Returns `MAX_DEPOSITS` (see `depositBufferedEther`).
* Returns `maxDepositsPerBlock` (see `depositBufferedEther`).
*/
function getMaxDeposits() external view returns (uint256) {
return maxDepositsPerBlock;
}

/**
* Sets `MAX_DEPOSITS`. Only callable by the owner.
* Sets `maxDepositsPerBlock`. Only callable by the owner.
*/
function setMaxDeposits(uint256 newValue) external onlyOwner {
_setMaxDeposits(newValue);
Expand Down Expand Up @@ -386,17 +386,15 @@ contract DepositSecurityModule {
* 2. INodeOperatorsRegistry.getKeysOpIndex() != keysOpIndex.
* 3. The number of guardian signatures is less than getGuardianQuorum().
* 4. An invalid or non-guardian signature received.
* 5. maxDeposits > MAX_DEPOSITS
* 6. block.number - lastLidoDepositBlock < MIN_DEPOSIT_BLOCK_DISTANCE
* 7. blockhash(blockNumber) == blockHash
* 5. block.number - lastLidoDepositBlock < MIN_DEPOSIT_BLOCK_DISTANCE
* 6. blockhash(blockNumber) == blockHash
*
* Signatures must be sorted in ascending order by index of the guardian. Each signature must
* be produced for keccak256 hash of the following message (each component taking 32 bytes):
*
* | ATTEST_MESSAGE_PREFIX | depositRoot | keysOpIndex | blockNumber | blockHash |
*/
function depositBufferedEther(
uint256 maxDeposits,
bytes32 depositRoot,
uint256 keysOpIndex,
uint256 blockNumber,
Expand All @@ -409,7 +407,6 @@ contract DepositSecurityModule {
require(!paused, "deposits are paused");
require(quorum > 0 && sortedGuardianSignatures.length >= quorum, "no guardian quorum");

require(maxDeposits <= maxDepositsPerBlock, "too many deposits");
require(block.number - lastDepositBlock >= minDepositBlockDistance, "too frequent deposits");
require(blockHash != bytes32(0) && blockhash(blockNumber) == blockHash, "unexpected block hash");

Expand All @@ -424,7 +421,7 @@ contract DepositSecurityModule {
sortedGuardianSignatures
);

ILido(LIDO).depositBufferedEther(maxDeposits);
ILido(LIDO).depositBufferedEther(maxDepositsPerBlock);
lastDepositBlock = block.number;
}

Expand Down
119 changes: 28 additions & 91 deletions test/0.8.9/deposit-security-module.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
}

describe('depositBufferedEther', () => {
const MAX_DEPOSITS = 24
const KEYS_OP_INDEX = 12
const DEPOSIT_ROOT = '0xd151867719c94ad8458feaf491809f9bc8096c702a72747403ecaac30c179137'

Expand All @@ -91,7 +90,7 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
})
it('deposits are impossible', async () => {
await assertRevert(
depositSecurityModule.depositBufferedEther(MAX_DEPOSITS, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, [], {
depositSecurityModule.depositBufferedEther(DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, [], {
from: stranger
}),
'no guardian quorum'
Expand All @@ -112,16 +111,9 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
const signatures = [
signDepositData(ATTEST_MESSAGE_PREFIX, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, GUARDIAN_PRIVATE_KEYS[GUARDIAN1])
]
const tx = await depositSecurityModule.depositBufferedEther(
MAX_DEPOSITS,
DEPOSIT_ROOT,
KEYS_OP_INDEX,
block.number,
block.hash,
signatures
)
const tx = await depositSecurityModule.depositBufferedEther(DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures)
assertEvent(tx.receipt, 'Deposited', {
expectedArgs: { maxDeposits: MAX_DEPOSITS },
expectedArgs: { maxDeposits: MAX_DEPOSITS_PER_BLOCK },
decodeForAbi: LidoMockForDepositSecurityModule._json.abi
})
})
Expand All @@ -131,13 +123,13 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
]

await assertRevert(
depositSecurityModule.depositBufferedEther(MAX_DEPOSITS, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures),
depositSecurityModule.depositBufferedEther(DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures),
'invalid signature'
)
})
it('cannot deposit with no sigs', async () => {
await assertRevert(
depositSecurityModule.depositBufferedEther(MAX_DEPOSITS, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, []),
depositSecurityModule.depositBufferedEther(DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, []),
'no guardian quorum'
)
})
Expand All @@ -151,7 +143,7 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
signDepositData(ATTEST_MESSAGE_PREFIX, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, GUARDIAN_PRIVATE_KEYS[GUARDIAN1])
]
await assertRevert(
depositSecurityModule.depositBufferedEther(MAX_DEPOSITS, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures),
depositSecurityModule.depositBufferedEther(DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures),
'deposit root changed'
)
})
Expand All @@ -164,45 +156,22 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
signDepositData(ATTEST_MESSAGE_PREFIX, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, GUARDIAN_PRIVATE_KEYS[GUARDIAN1])
]
await assertRevert(
depositSecurityModule.depositBufferedEther(MAX_DEPOSITS, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures),
depositSecurityModule.depositBufferedEther(DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures),
'keys op index changed'
)
})
it('cannot deposit more than allowed number of validators', async () => {
const signatures = [
signDepositData(ATTEST_MESSAGE_PREFIX, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, GUARDIAN_PRIVATE_KEYS[GUARDIAN1])
]
await assertRevert(
depositSecurityModule.depositBufferedEther(
MAX_DEPOSITS_PER_BLOCK + 1,
DEPOSIT_ROOT,
KEYS_OP_INDEX,
block.number,
block.hash,
signatures
),
'too many deposits'
)
})

it('cannot deposit more frequently than allowed', async () => {
const signatures = [
signDepositData(ATTEST_MESSAGE_PREFIX, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, GUARDIAN_PRIVATE_KEYS[GUARDIAN1])
]
const tx = await depositSecurityModule.depositBufferedEther(
MAX_DEPOSITS,
DEPOSIT_ROOT,
KEYS_OP_INDEX,
block.number,
block.hash,
signatures
)
const tx = await depositSecurityModule.depositBufferedEther(DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures)
assertEvent(tx.receipt, 'Deposited', {
expectedArgs: { maxDeposits: MAX_DEPOSITS },
expectedArgs: { maxDeposits: MAX_DEPOSITS_PER_BLOCK },
decodeForAbi: LidoMockForDepositSecurityModule._json.abi
})
await assertRevert(
depositSecurityModule.depositBufferedEther(MAX_DEPOSITS, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures),
depositSecurityModule.depositBufferedEther(DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures),
'too frequent deposits'
)
})
Expand All @@ -213,7 +182,7 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
const staleBlockHash = block.hash
await waitBlocks(1)
await assertRevert(
depositSecurityModule.depositBufferedEther(MAX_DEPOSITS, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, staleBlockHash, signatures),
depositSecurityModule.depositBufferedEther(DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, staleBlockHash, signatures),
'unexpected block hash'
)
})
Expand All @@ -231,7 +200,7 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
)
]
await assertRevert(
depositSecurityModule.depositBufferedEther(MAX_DEPOSITS, DEPOSIT_ROOT, KEYS_OP_INDEX, staleBlock.number, '0x', signatures),
depositSecurityModule.depositBufferedEther(DEPOSIT_ROOT, KEYS_OP_INDEX, staleBlock.number, '0x', signatures),
'unexpected block hash'
)
})
Expand All @@ -253,16 +222,9 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
signDepositData(ATTEST_MESSAGE_PREFIX, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, GUARDIAN_PRIVATE_KEYS[GUARDIAN3])
]

const tx = await depositSecurityModule.depositBufferedEther(
MAX_DEPOSITS,
DEPOSIT_ROOT,
KEYS_OP_INDEX,
block.number,
block.hash,
signatures
)
const tx = await depositSecurityModule.depositBufferedEther(DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures)
assertEvent(tx.receipt, 'Deposited', {
expectedArgs: { maxDeposits: MAX_DEPOSITS },
expectedArgs: { maxDeposits: MAX_DEPOSITS_PER_BLOCK },
decodeForAbi: LidoMockForDepositSecurityModule._json.abi
})
})
Expand All @@ -272,16 +234,9 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
signDepositData(ATTEST_MESSAGE_PREFIX, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, GUARDIAN_PRIVATE_KEYS[GUARDIAN2])
]

const tx = await depositSecurityModule.depositBufferedEther(
MAX_DEPOSITS,
DEPOSIT_ROOT,
KEYS_OP_INDEX,
block.number,
block.hash,
signatures
)
const tx = await depositSecurityModule.depositBufferedEther(DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures)
assertEvent(tx.receipt, 'Deposited', {
expectedArgs: { maxDeposits: MAX_DEPOSITS },
expectedArgs: { maxDeposits: MAX_DEPOSITS_PER_BLOCK },
decodeForAbi: LidoMockForDepositSecurityModule._json.abi
})
})
Expand All @@ -291,16 +246,9 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
signDepositData(ATTEST_MESSAGE_PREFIX, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, GUARDIAN_PRIVATE_KEYS[GUARDIAN3])
]

const tx = await depositSecurityModule.depositBufferedEther(
MAX_DEPOSITS,
DEPOSIT_ROOT,
KEYS_OP_INDEX,
block.number,
block.hash,
signatures
)
const tx = await depositSecurityModule.depositBufferedEther(DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures)
assertEvent(tx.receipt, 'Deposited', {
expectedArgs: { maxDeposits: MAX_DEPOSITS },
expectedArgs: { maxDeposits: MAX_DEPOSITS_PER_BLOCK },
decodeForAbi: LidoMockForDepositSecurityModule._json.abi
})
})
Expand All @@ -309,22 +257,15 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
signDepositData(ATTEST_MESSAGE_PREFIX, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, GUARDIAN_PRIVATE_KEYS[GUARDIAN2]),
signDepositData(ATTEST_MESSAGE_PREFIX, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, GUARDIAN_PRIVATE_KEYS[GUARDIAN3])
]
const tx = await depositSecurityModule.depositBufferedEther(
MAX_DEPOSITS,
DEPOSIT_ROOT,
KEYS_OP_INDEX,
block.number,
block.hash,
signatures
)
const tx = await depositSecurityModule.depositBufferedEther(DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures)
assertEvent(tx.receipt, 'Deposited', {
expectedArgs: { maxDeposits: MAX_DEPOSITS },
expectedArgs: { maxDeposits: MAX_DEPOSITS_PER_BLOCK },
decodeForAbi: LidoMockForDepositSecurityModule._json.abi
})
})
it('cannot deposit with no sigs', async () => {
await assertRevert(
depositSecurityModule.depositBufferedEther(MAX_DEPOSITS, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, []),
depositSecurityModule.depositBufferedEther(DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, []),
'no guardian quorum'
)
})
Expand All @@ -334,7 +275,7 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
signDepositData(ATTEST_MESSAGE_PREFIX, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, GUARDIAN_PRIVATE_KEYS[GUARDIAN1])
]
await assertRevert(
depositSecurityModule.depositBufferedEther(MAX_DEPOSITS, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures),
depositSecurityModule.depositBufferedEther(DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures),
'signatures not sorted'
)
})
Expand All @@ -345,7 +286,7 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
signDepositData(ATTEST_MESSAGE_PREFIX, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, GUARDIAN_PRIVATE_KEYS[GUARDIAN2])
]
await assertRevert(
depositSecurityModule.depositBufferedEther(MAX_DEPOSITS, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures),
depositSecurityModule.depositBufferedEther(DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures),
'signatures not sorted'
)
})
Expand All @@ -370,7 +311,7 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
)
]
await assertRevert(
depositSecurityModule.depositBufferedEther(MAX_DEPOSITS, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signature),
depositSecurityModule.depositBufferedEther(DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signature),
'invalid signature'
)
})
Expand Down Expand Up @@ -716,7 +657,6 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
})
describe('canDeposit', () => {
it('true if not paused and quorum > 0 and currentBlock - lastDepositBlock >= minDepositBlockDistance', async () => {
const MAX_DEPOSITS = 24
const KEYS_OP_INDEX = 12
const DEPOSIT_ROOT = '0xd151867719c94ad8458feaf491809f9bc8096c702a72747403ecaac30c179137'

Expand All @@ -728,7 +668,7 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
const signatures = [
signDepositData(ATTEST_MESSAGE_PREFIX, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, GUARDIAN_PRIVATE_KEYS[GUARDIAN1])
]
await depositSecurityModule.depositBufferedEther(MAX_DEPOSITS, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures)
await depositSecurityModule.depositBufferedEther(DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures)

const lastDepositBlockNumber = await web3.eth.getBlockNumber()
await waitBlocks(2 * MIN_DEPOSIT_BLOCK_DISTANCE)
Expand All @@ -740,7 +680,6 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
assert.isTrue(await depositSecurityModule.canDeposit())
})
it('false if paused and quorum > 0 and currentBlock - lastDepositBlock >= minDepositBlockDistance', async () => {
const MAX_DEPOSITS = 24
const KEYS_OP_INDEX = 12
const DEPOSIT_ROOT = '0xd151867719c94ad8458feaf491809f9bc8096c702a72747403ecaac30c179137'

Expand All @@ -750,7 +689,7 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
const signatures = [
signDepositData(ATTEST_MESSAGE_PREFIX, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, GUARDIAN_PRIVATE_KEYS[GUARDIAN1])
]
await depositSecurityModule.depositBufferedEther(MAX_DEPOSITS, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures)
await depositSecurityModule.depositBufferedEther(DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures)

const lastDepositBlockNumber = await web3.eth.getBlockNumber()
await waitBlocks(2 * MIN_DEPOSIT_BLOCK_DISTANCE)
Expand All @@ -765,7 +704,6 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
assert.isFalse(await depositSecurityModule.canDeposit())
})
it('false if not paused and quorum == 0 and currentBlock - lastDepositBlock >= minDepositBlockDistance', async () => {
const MAX_DEPOSITS = 24
const KEYS_OP_INDEX = 12
const DEPOSIT_ROOT = '0xd151867719c94ad8458feaf491809f9bc8096c702a72747403ecaac30c179137'

Expand All @@ -775,7 +713,7 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
const signatures = [
signDepositData(ATTEST_MESSAGE_PREFIX, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, GUARDIAN_PRIVATE_KEYS[GUARDIAN1])
]
await depositSecurityModule.depositBufferedEther(MAX_DEPOSITS, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures)
await depositSecurityModule.depositBufferedEther(DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures)

const lastDepositBlockNumber = await web3.eth.getBlockNumber()
await waitBlocks(2 * MIN_DEPOSIT_BLOCK_DISTANCE)
Expand All @@ -789,7 +727,6 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
assert.isFalse(await depositSecurityModule.canDeposit())
})
it('false if not paused and quorum > 0 and currentBlock - lastDepositBlock < minDepositBlockDistance', async () => {
const MAX_DEPOSITS = 24
const KEYS_OP_INDEX = 12
const DEPOSIT_ROOT = '0xd151867719c94ad8458feaf491809f9bc8096c702a72747403ecaac30c179137'

Expand All @@ -801,7 +738,7 @@ contract('DepositSecurityModule', ([owner, stranger, guardian]) => {
const signatures = [
signDepositData(ATTEST_MESSAGE_PREFIX, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, GUARDIAN_PRIVATE_KEYS[GUARDIAN1])
]
await depositSecurityModule.depositBufferedEther(MAX_DEPOSITS, DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures)
await depositSecurityModule.depositBufferedEther(DEPOSIT_ROOT, KEYS_OP_INDEX, block.number, block.hash, signatures)

const lastDepositBlockNumber = await web3.eth.getBlockNumber()
await waitBlocks(Math.floor(MIN_DEPOSIT_BLOCK_DISTANCE / 2))
Expand Down
Loading

0 comments on commit 5af2875

Please sign in to comment.