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

ZK-382: Implement deposit for token shortlist #97

Closed
wants to merge 7 commits into from

Conversation

kroist
Copy link
Collaborator

@kroist kroist commented Jan 22, 2025

Implement Deposit function for token shortlist feature:

  • New contract ShielderV_0_1_0
  • New abstract contract TokenList
  • return tokenIndex in DepositEvent
    uint256 tokenIndex
  • new function depositERC20
    function depositERC20(
    bytes3 expectedContractVersion,
    uint256 idHiding,
    uint256 oldNullifierHash,
    uint256 newNote,
    uint256 merkleRoot,
    uint256 amount,
    uint256 tokenIndex,
    bytes calldata proof
    )
  • functions in main contract for appending token to list and removing the last in case of errors
    function addTokenToList(address _token) external onlyOwner {
    _addTokenToList(_token);
    }
    /*
    * Remove the last token from the list
    */
    function removeLastToken() external onlyOwner {
    _removeLastToken();
    }
  • Modified verifier generator
  • Some tests for upgrades

Copy link

github-actions bot commented Jan 22, 2025

Transaction NameMainCurrentDifference (%)
NewAccountNative20003112000263-0.00240%
DepositNative18279901827882-0.00591%
WithdrawNative18981621898174+0.00063%

@kroist kroist requested review from fbielejec, DamianStraszak and guspiel and removed request for DamianStraszak January 22, 2025 09:20
@kroist kroist changed the title ZK-382: Implement deposit for shortlist of tokens ZK-382: Implement deposit for token shortlist Jan 22, 2025
Copy link

github-actions bot commented Jan 22, 2025

📊 Coverage Report

📈 Total Coverage Summary

Type Covered Total Coverage
📝 Lines 2008 2235 🟡 89.84%
📄 Statements 2008 2235 🟡 89.84%
⚡ Functions 69 76 🟡 90.78%
🔀 Branches 197 199 🟡 98.99%

Coverage Legend

  • ✅ 100% Coverage
  • 🟡 80-99% Coverage
  • 🟠 50-79% Coverage
  • ❌ 0-49% Coverage

📁 File Coverage

📋 Detailed Coverage Report
File Lines Statements Functions Branches
zkOS-monorepo/ts/shielder-sdk/src/_generated/abi.ts 100% 100% 100% 100%
zkOS-monorepo/ts/shielder-sdk/src/actions/deposit.ts 100% 100% 100% 100%
zkOS-monorepo/ts/shielder-sdk/src/actions/index.ts 100% 100% 100% 100%
zkOS-monorepo/ts/shielder-sdk/src/actions/newAccount.ts 100% 100% 100% 100%
zkOS-monorepo/ts/shielder-sdk/src/actions/utils.ts 100% 100% 100% 100%
zkOS-monorepo/ts/shielder-sdk/src/actions/withdraw.ts 100% 100% 100% 100%
zkOS-monorepo/ts/shielder-sdk/src/chain/contract.ts 9.09% 9.09% 25% 100%
zkOS-monorepo/ts/shielder-sdk/src/chain/relayer.ts 20.75% 20.75% 33.33% 50%
zkOS-monorepo/ts/shielder-sdk/src/client.ts 100% 100% 93.75% 100%
zkOS-monorepo/ts/shielder-sdk/src/constants.ts 100% 100% 100% 100%
zkOS-monorepo/ts/shielder-sdk/src/index.ts 0% 0% 0% 0%
zkOS-monorepo/ts/shielder-sdk/src/state/events.ts 100% 100% 100% 100%
zkOS-monorepo/ts/shielder-sdk/src/state/index.ts 100% 100% 100% 100%
zkOS-monorepo/ts/shielder-sdk/src/state/manager.ts 100% 100% 100% 100%
zkOS-monorepo/ts/shielder-sdk/src/state/storageSchema.ts 100% 100% 100% 100%
zkOS-monorepo/ts/shielder-sdk/src/state/sync.ts 100% 100% 100% 100%
zkOS-monorepo/ts/shielder-sdk/src/state/types.ts 100% 100% 100% 100%
zkOS-monorepo/ts/shielder-sdk/src/utils.ts 100% 100% 100% 100%

Copy link
Contributor

@guspiel guspiel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leaving some initial comments

contracts/ShielderV0_1_0.sol Show resolved Hide resolved
* @custom:oz-upgrades-unsafe-allow external-library-linking
*/
// solhint-disable-next-line contract-name-camelcase
contract ShielderV0_1_0 is
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach in this PR is to keep existing code (shielder-circuits package, integration-tests) pointing at the current mainnet release implementation, and to start adding new code next to it.

An alternative approach would be to modify Shielder.sol etc. in place and add the mainnet release version next to it (in ShielderV_0_0_1.sol and other files if necessary).

The latter seems better to me. V_0_0_1 is already tested, we don't need to run any tests for it. But it seems cleaner to work on the V_0_1_0 implementation in the existing ecosystem of crates/integration_tests, shielder-rust-sdk and shielder-relayer, under the existing PR checks.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed to Shielder but kept in ShielderV0_1_0.sol file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point here is to change existing code while making sure that existing tests pass. Currently you're adding code outside the existing testing framework, is there any good reason for it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rewriting tests for new circuits is out of scope of this PR. let's not make it giant.

/*
* Make an ERC-20 token deposit into the Shielder
*/
function depositERC20(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New contract code should be accompanied by test coverage. Our current way to do that is to use crates/integration-tests.

The skipping of integration tests was discussed in the context of Shielder SDK, not contract code coverage.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note sure it's currently meaningful to write integration tests without withdraw. let's leave it for another PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new deposit is compatible with the old withdraw and new account, as long as you only use token index 0. The tests I have in mind do not use withdraw.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rewriting tests for new circuits is out of scope of this PR. let's not make it giant.

Makefile Show resolved Hide resolved
Cargo.toml Show resolved Hide resolved
contracts/TokenList.sol Outdated Show resolved Hide resolved
Copy link
Collaborator

@fbielejec fbielejec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the implementation looks very good, bu the versioning is attacking from all angles 😄 As much as I can understand naming the contracts with the semversion included, imo it's not needed all over the place, - it shoud be enough to do semversioning in the tags and in the Cargo.toml, which has the version field for this exact purpose

Copy link
Contributor

@guspiel guspiel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left comments noting that code is being added outside the existing testing framework; it seems preferable to iterate while keeping the tests.

@kroist kroist closed this Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants