From 9fc1304cd8fc7170dea655be722e8064fdd042af Mon Sep 17 00:00:00 2001 From: Yuri Tkachenko Date: Fri, 29 Nov 2024 13:51:13 +0000 Subject: [PATCH 1/4] test(integration): fix unbuffered flow --- test/integration/protocol-happy-path.integration.ts | 5 +---- .../{second-opinion.ts => second-opinion.integration.ts} | 0 2 files changed, 1 insertion(+), 4 deletions(-) rename test/integration/{second-opinion.ts => second-opinion.integration.ts} (100%) diff --git a/test/integration/protocol-happy-path.integration.ts b/test/integration/protocol-happy-path.integration.ts index ee010216c..d4920dc46 100644 --- a/test/integration/protocol-happy-path.integration.ts +++ b/test/integration/protocol-happy-path.integration.ts @@ -217,7 +217,7 @@ describe("Protocol Happy Path", () => { const depositNorReceipt = await trace("lido.deposit (Curated Module)", depositNorTx); const unbufferedEventNor = ctx.getEvents(depositNorReceipt, "Unbuffered")[0]; - const unbufferedAmountNor = unbufferedEventNor.args[0]; + const unbufferedAmountNor = unbufferedEventNor?.args[0] || 0n; // 0 if no deposit was made to NOR & SDVT const depositCountsNor = unbufferedAmountNor / ether("32"); let expectedBufferedEtherAfterDeposit = bufferedEtherBeforeDeposit - unbufferedAmountNor; @@ -234,15 +234,12 @@ describe("Protocol Happy Path", () => { const depositCountsTotal = depositCountsNor + unbufferedAmountSdvt / ether("32"); expectedBufferedEtherAfterDeposit -= unbufferedAmountSdvt; - expect(depositCountsTotal).to.be.gt(0n, "Deposit counts"); expect(newValidatorsCountSdvt).to.equal( depositedValidatorsBefore + depositCountsTotal, "New validators count after deposit", ); const bufferedEtherAfterDeposit = await lido.getBufferedEther(); - - expect(depositCountsNor).to.be.gt(0n, "Deposit counts"); expect(bufferedEtherAfterDeposit).to.equal(expectedBufferedEtherAfterDeposit, "Buffered ether after deposit"); log.debug("After deposit", { diff --git a/test/integration/second-opinion.ts b/test/integration/second-opinion.integration.ts similarity index 100% rename from test/integration/second-opinion.ts rename to test/integration/second-opinion.integration.ts From 70bfb7fdf86364dbac65f2a4eb5f752fe2b761d7 Mon Sep 17 00:00:00 2001 From: Yuri Tkachenko Date: Fri, 29 Nov 2024 13:51:36 +0000 Subject: [PATCH 2/4] chore: update ci and dedupe deps --- .github/workflows/analyse.yml | 7 +- .github/workflows/coverage.yml | 2 +- .../workflows/tests-integration-scratch.yml | 2 +- yarn.lock | 96 ++----------------- 4 files changed, 17 insertions(+), 90 deletions(-) diff --git a/.github/workflows/analyse.yml b/.github/workflows/analyse.yml index 48228c8af..c85dfc476 100644 --- a/.github/workflows/analyse.yml +++ b/.github/workflows/analyse.yml @@ -1,6 +1,9 @@ name: Analysis -on: [pull_request] +on: + pull_request: + push: + branches: [master] jobs: slither: @@ -41,7 +44,7 @@ jobs: --no-fail-pedantic \ --compile-force-framework hardhat \ --sarif results.sarif \ - --exclude pess-strange-setter,pess-arbitrary-call-calldata-tainted + --exclude pess-strange-setter,pess-arbitrary-call-calldata-tainted,pess-multiple-storage-read,pess-dubious-typecast - name: Check results.sarif presence id: results diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 4a63e36b8..68271dc5a 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -3,7 +3,7 @@ name: Coverage on: pull_request: push: - branches: [ master ] + branches: [master] jobs: coverage: diff --git a/.github/workflows/tests-integration-scratch.yml b/.github/workflows/tests-integration-scratch.yml index 0093a125f..670afcc53 100644 --- a/.github/workflows/tests-integration-scratch.yml +++ b/.github/workflows/tests-integration-scratch.yml @@ -1,6 +1,6 @@ name: Integration Tests -on: [ push ] +on: [push] jobs: test_hardhat_integration_scratch: diff --git a/yarn.lock b/yarn.lock index 4c077d30b..1b7ce6f34 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2036,14 +2036,7 @@ __metadata: languageName: node linkType: hard -"@types/chai@npm:*": - version: 4.3.17 - resolution: "@types/chai@npm:4.3.17" - checksum: 10c0/322a74489cdfde9c301b593d086c539584924c4c92689a858e0930708895a5ab229c31c64ac26b137615ef3ffbff1866851c280c093e07b3d3de05983d3793e0 - languageName: node - linkType: hard - -"@types/chai@npm:^4.3.19": +"@types/chai@npm:*, @types/chai@npm:^4.3.19": version: 4.3.19 resolution: "@types/chai@npm:4.3.19" checksum: 10c0/8fd573192e486803c4d04185f2b0fab554660d9a1300dbed5bde9747ab8bef15f462a226f560ed5ca48827eecaf8d71eed64aa653ff9aec72fb2eae272e43a84 @@ -2068,17 +2061,7 @@ __metadata: languageName: node linkType: hard -"@types/eslint@npm:*": - version: 9.6.0 - resolution: "@types/eslint@npm:9.6.0" - dependencies: - "@types/estree": "npm:*" - "@types/json-schema": "npm:*" - checksum: 10c0/69301356bc73b85e381ae00931291de2e96d1cc49a112c592c74ee32b2f85412203dea6a333b4315fd9839bb14f364f265cbfe7743fc5a78492ee0326dd6a2c1 - languageName: node - linkType: hard - -"@types/eslint@npm:^9.6.1": +"@types/eslint@npm:*, @types/eslint@npm:^9.6.1": version: 9.6.1 resolution: "@types/eslint@npm:9.6.1" dependencies: @@ -2097,14 +2080,7 @@ __metadata: languageName: node linkType: hard -"@types/estree@npm:*": - version: 1.0.5 - resolution: "@types/estree@npm:1.0.5" - checksum: 10c0/b3b0e334288ddb407c7b3357ca67dbee75ee22db242ca7c56fe27db4e1a31989cb8af48a84dd401deb787fe10cc6b2ab1ee82dc4783be87ededbe3d53c79c70d - languageName: node - linkType: hard - -"@types/estree@npm:^1.0.6": +"@types/estree@npm:*, @types/estree@npm:^1.0.6": version: 1.0.6 resolution: "@types/estree@npm:1.0.6" checksum: 10c0/cdfd751f6f9065442cd40957c07fd80361c962869aa853c1c2fd03e101af8b9389d8ff4955a43a6fcfa223dd387a089937f95be0f3eec21ca527039fd2d9859a @@ -2165,19 +2141,12 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:*": - version: 22.5.0 - resolution: "@types/node@npm:22.5.0" +"@types/node@npm:*, @types/node@npm:22.7.5": + version: 22.7.5 + resolution: "@types/node@npm:22.7.5" dependencies: undici-types: "npm:~6.19.2" - checksum: 10c0/45aa75c5e71645fac42dced4eff7f197c3fdfff6e8a9fdacd0eb2e748ff21ee70ffb73982f068a58e8d73b2c088a63613142c125236cdcf3c072ea97eada1559 - languageName: node - linkType: hard - -"@types/node@npm:18.15.13": - version: 18.15.13 - resolution: "@types/node@npm:18.15.13" - checksum: 10c0/6e5f61c559e60670a7a8fb88e31226ecc18a21be103297ca4cf9848f0a99049dae77f04b7ae677205f2af494f3701b113ba8734f4b636b355477a6534dbb8ada + checksum: 10c0/cf11f74f1a26053ec58066616e3a8685b6bcd7259bc569738b8f752009f9f0f7f85a1b2d24908e5b0f752482d1e8b6babdf1fbb25758711ec7bb9500bfcd6e60 languageName: node linkType: hard @@ -2190,15 +2159,6 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:22.7.5": - version: 22.7.5 - resolution: "@types/node@npm:22.7.5" - dependencies: - undici-types: "npm:~6.19.2" - checksum: 10c0/cf11f74f1a26053ec58066616e3a8685b6bcd7259bc569738b8f752009f9f0f7f85a1b2d24908e5b0f752482d1e8b6babdf1fbb25758711ec7bb9500bfcd6e60 - languageName: node - linkType: hard - "@types/node@npm:^10.0.3": version: 10.17.60 resolution: "@types/node@npm:10.17.60" @@ -5693,7 +5653,7 @@ __metadata: languageName: node linkType: hard -"ethers@npm:^6.13.4": +"ethers@npm:^6.13.4, ethers@npm:^6.7.0": version: 6.13.4 resolution: "ethers@npm:6.13.4" dependencies: @@ -5708,21 +5668,6 @@ __metadata: languageName: node linkType: hard -"ethers@npm:^6.7.0": - version: 6.13.2 - resolution: "ethers@npm:6.13.2" - dependencies: - "@adraffy/ens-normalize": "npm:1.10.1" - "@noble/curves": "npm:1.2.0" - "@noble/hashes": "npm:1.3.2" - "@types/node": "npm:18.15.13" - aes-js: "npm:4.0.0-beta.5" - tslib: "npm:2.4.0" - ws: "npm:8.17.1" - checksum: 10c0/5956389a180992f8b6d90bc21b2e0f28619a098513d3aeb7a350a0b7c5852d635a9d7fd4ced1af50c985dd88398716f66dfd4a2de96c5c3a67150b93543d92af - languageName: node - linkType: hard - "ethjs-unit@npm:0.1.6": version: 0.1.6 resolution: "ethjs-unit@npm:0.1.6" @@ -9429,14 +9374,7 @@ __metadata: languageName: node linkType: hard -"picocolors@npm:^1.0.0, picocolors@npm:^1.0.1": - version: 1.0.1 - resolution: "picocolors@npm:1.0.1" - checksum: 10c0/c63cdad2bf812ef0d66c8db29583802355d4ca67b9285d846f390cc15c2f6ccb94e8cb7eb6a6e97fc5990a6d3ad4ae42d86c84d3146e667c739a4234ed50d400 - languageName: node - linkType: hard - -"picocolors@npm:^1.1.0": +"picocolors@npm:^1.0.0, picocolors@npm:^1.0.1, picocolors@npm:^1.1.0": version: 1.1.1 resolution: "picocolors@npm:1.1.1" checksum: 10c0/e2e3e8170ab9d7c7421969adaa7e1b31434f789afb9b3f115f6b96d91945041ac3ceb02e9ec6fe6510ff036bcc0bf91e69a1772edc0b707e12b19c0f2d6bcf58 @@ -11538,14 +11476,7 @@ __metadata: languageName: node linkType: hard -"tslib@npm:2.4.0": - version: 2.4.0 - resolution: "tslib@npm:2.4.0" - checksum: 10c0/eb19bda3ae545b03caea6a244b34593468e23d53b26bf8649fbc20fce43e9b21a71127fd6d2b9662c0fe48ee6ff668ead48fd00d3b88b2b716b1c12edae25b5d - languageName: node - linkType: hard - -"tslib@npm:2.7.0": +"tslib@npm:2.7.0, tslib@npm:^2.6.2": version: 2.7.0 resolution: "tslib@npm:2.7.0" checksum: 10c0/469e1d5bf1af585742128827000711efa61010b699cb040ab1800bcd3ccdd37f63ec30642c9e07c4439c1db6e46345582614275daca3e0f4abae29b0083f04a6 @@ -11559,13 +11490,6 @@ __metadata: languageName: node linkType: hard -"tslib@npm:^2.6.2": - version: 2.6.3 - resolution: "tslib@npm:2.6.3" - checksum: 10c0/2598aef53d9dbe711af75522464b2104724d6467b26a60f2bdac8297d2b5f1f6b86a71f61717384aa8fd897240467aaa7bcc36a0700a0faf751293d1331db39a - languageName: node - linkType: hard - "tsort@npm:0.0.1": version: 0.0.1 resolution: "tsort@npm:0.0.1" From 9b54fe41e85e8e24189e0c0efddf411d8697083a Mon Sep 17 00:00:00 2001 From: Yuri Tkachenko Date: Fri, 29 Nov 2024 14:22:19 +0000 Subject: [PATCH 3/4] chore: improve slither config --- .github/workflows/analyse.yml | 6 +----- slither.config.json | 4 +++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/analyse.yml b/.github/workflows/analyse.yml index c85dfc476..016a2b748 100644 --- a/.github/workflows/analyse.yml +++ b/.github/workflows/analyse.yml @@ -40,11 +40,7 @@ jobs: - name: Run slither run: > - poetry run slither . \ - --no-fail-pedantic \ - --compile-force-framework hardhat \ - --sarif results.sarif \ - --exclude pess-strange-setter,pess-arbitrary-call-calldata-tainted,pess-multiple-storage-read,pess-dubious-typecast + poetry run slither . --no-fail-pedantic --sarif results.sarif - name: Check results.sarif presence id: results diff --git a/slither.config.json b/slither.config.json index e5347201f..a5cbbf4e0 100644 --- a/slither.config.json +++ b/slither.config.json @@ -3,5 +3,7 @@ "exclude_low": true, "exclude_medium": false, "exclude_high": false, - "filter_paths": "(.*test.*/|.*template/|.*mocks/|node_modules/|.*brownie/|.*dependencies/)" + "filter_paths": "(.*test.*/|.*template/|.*mocks/|node_modules/|.*brownie/|.*dependencies/)", + "detectors_to_exclude": "pess-strange-setter,pess-arbitrary-call-calldata-tainted,pess-multiple-storage-read,pess-dubious-typecast", + "compile_force_framework": "hardhat" } From de2cbd0429d388d0a3160060a592d0cf2a606ffb Mon Sep 17 00:00:00 2001 From: Yuri Tkachenko Date: Fri, 29 Nov 2024 15:15:47 +0000 Subject: [PATCH 4/4] chore: update test --- .../protocol-happy-path.integration.ts | 56 +++++++++---------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/test/integration/protocol-happy-path.integration.ts b/test/integration/protocol-happy-path.integration.ts index d4920dc46..161c40b6a 100644 --- a/test/integration/protocol-happy-path.integration.ts +++ b/test/integration/protocol-happy-path.integration.ts @@ -18,8 +18,6 @@ import { bailOnFailure, Snapshot } from "test/suite"; const AMOUNT = ether("100"); const MAX_DEPOSIT = 150n; -const CURATED_MODULE_ID = 1n; -const SIMPLE_DVT_MODULE_ID = 2n; const ZERO_HASH = new Uint8Array(32).fill(0); @@ -192,11 +190,11 @@ describe("Protocol Happy Path", () => { } }); - it("Should deposit 100 ETH to node operators", async () => { - const { lido, withdrawalQueue } = ctx.contracts; + it("Should deposit to staking modules", async () => { + const { lido, withdrawalQueue, stakingRouter } = ctx.contracts; const { depositSecurityModule } = ctx.contracts; - const { depositedValidators: depositedValidatorsBefore } = await lido.getBeaconStat(); + const withdrawalsUninitializedStETH = await withdrawalQueue.unfinalizedStETH(); const depositableEther = await lido.getDepositableEther(); const bufferedEtherBeforeDeposit = await lido.getBufferedEther(); @@ -212,39 +210,35 @@ describe("Protocol Happy Path", () => { }); const dsmSigner = await impersonate(depositSecurityModule.address, ether("100")); + const stakingModules = await stakingRouter.getStakingModules(); + + let depositCount = 0n; + let expectedBufferedEtherAfterDeposit = bufferedEtherBeforeDeposit; + for (const module of stakingModules) { + const depositTx = await lido.connect(dsmSigner).deposit(MAX_DEPOSIT, module.id, ZERO_HASH); + const depositReceipt = await trace(`lido.deposit (${module.name})`, depositTx); + const unbufferedEvent = ctx.getEvents(depositReceipt, "Unbuffered")[0]; + const unbufferedAmount = unbufferedEvent?.args[0] || 0n; + const deposits = unbufferedAmount / ether("32"); + + log.debug("Staking module", { + "Module": module.name, + "Deposits": deposits, + "Unbuffered amount": ethers.formatEther(unbufferedAmount), + }); + + depositCount += deposits; + expectedBufferedEtherAfterDeposit -= unbufferedAmount; + } - const depositNorTx = await lido.connect(dsmSigner).deposit(MAX_DEPOSIT, CURATED_MODULE_ID, ZERO_HASH); - const depositNorReceipt = await trace("lido.deposit (Curated Module)", depositNorTx); - - const unbufferedEventNor = ctx.getEvents(depositNorReceipt, "Unbuffered")[0]; - const unbufferedAmountNor = unbufferedEventNor?.args[0] || 0n; // 0 if no deposit was made to NOR & SDVT - - const depositCountsNor = unbufferedAmountNor / ether("32"); - let expectedBufferedEtherAfterDeposit = bufferedEtherBeforeDeposit - unbufferedAmountNor; - - const depositSdvtTx = await lido.connect(dsmSigner).deposit(MAX_DEPOSIT, SIMPLE_DVT_MODULE_ID, ZERO_HASH); - const depositSdvtReceipt = await trace("lido.deposit (Simple DVT)", depositSdvtTx); - - const unbufferedEventSdvt = ctx.getEvents(depositSdvtReceipt, "Unbuffered")[0]; - const depositedValidatorsChangedEventSdvt = ctx.getEvents(depositSdvtReceipt, "DepositedValidatorsChanged")[0]; - - const unbufferedAmountSdvt = unbufferedEventSdvt.args[0]; - const newValidatorsCountSdvt = depositedValidatorsChangedEventSdvt.args[0]; - - const depositCountsTotal = depositCountsNor + unbufferedAmountSdvt / ether("32"); - expectedBufferedEtherAfterDeposit -= unbufferedAmountSdvt; - - expect(newValidatorsCountSdvt).to.equal( - depositedValidatorsBefore + depositCountsTotal, - "New validators count after deposit", - ); + expect(depositCount).to.be.gt(0n, "Deposits"); const bufferedEtherAfterDeposit = await lido.getBufferedEther(); expect(bufferedEtherAfterDeposit).to.equal(expectedBufferedEtherAfterDeposit, "Buffered ether after deposit"); log.debug("After deposit", { + "Deposits": depositCount, "Buffered ether": ethers.formatEther(bufferedEtherAfterDeposit), - "Unbuffered amount (NOR)": ethers.formatEther(unbufferedAmountNor), }); });