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

Commit reveal #77 #184

Merged
merged 45 commits into from
Oct 24, 2024
Merged

Commit reveal #77 #184

merged 45 commits into from
Oct 24, 2024

Conversation

LamsyA
Copy link
Contributor

@LamsyA LamsyA commented May 20, 2024

Issue(s): Close #77

Description

This is an implementation of the commitment scheme in cairo.

The contract uses a commitment scheme where bidders first commit to their bids and later reveal them. This ensures bid privacy until the reveal phase.

Interface: ICommitmentRevealTrait
The ICommitmentRevealTrait interface defines two essential methods:

commit(name: felt252, amount: felt252) -> felt252: Commits a bid with a name and amount, returning a hash.
reveal(name: felt252, amount: felt252) -> bool: Reveals a previously committed bid, returning true if the commitment is valid.

Checklist

  • CI Verifier: Run ./scripts/cairo_programs_verifier.sh successfully
  • Contract Tests: Added tests to cover the changes

@LamsyA LamsyA mentioned this pull request May 20, 2024
Copy link
Contributor

@julio4 julio4 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 does not fully conform to the commit-reveal scheme. The hash of the "secret", let's say x, should be computed off-chain, and the resulting hash should be used on-chain as an "attestation" that the user has committed to this value x, noted as commitment = hash(x). At the time of the commitment, the value x is kept secret while the commitment is made public.

Later, the user can reveal y, and the contract can verify that the revealed value y matches the committed value x by checking that hash(y) == commitment. This ensures that x == y.

A simple example could be the submission of a secret message, that can be optionally revealed at a later time with the guarantee that it was written at the time of commitment.

@LamsyA
Copy link
Contributor Author

LamsyA commented May 23, 2024

Okay, am on it.

@LamsyA LamsyA requested a review from julio4 May 29, 2024 07:05
@julio4
Copy link
Contributor

julio4 commented Jun 4, 2024

@LamsyA Hello, did you have the time to review and apply the changes in the last comments? Let me know if you need help.

@LamsyA
Copy link
Contributor Author

LamsyA commented Jun 5, 2024

@LamsyA Hello, did you have the time to review and apply the changes in the last comments? Let me know if you need help.

Yeah, I did

I will need your help to clarify something.

@julio4
Copy link
Contributor

julio4 commented Jun 8, 2024

@LamsyA Hello, did you have the time to review and apply the changes in the last comments? Let me know if you need help.

Yeah, I did

I will need your help to clarify something.

Yes, what points you would like me to clarify?

@LamsyA
Copy link
Contributor Author

LamsyA commented Jul 19, 2024

I have corrected the code;

  • Commitment Phase:

    • Off-chain: Compute the hash of the secret value.

    • On-chain: Store the hash (commitment).

  • Reveal Phase:

    • On-chain: Submit the original secret value.

    • On-chain: Verify that the hash of the submitted secret matches the stored commitment.

you can now review it.

@LamsyA
Copy link
Contributor Author

LamsyA commented Aug 12, 2024

Hi @julio4, kindly review this PR.

the-first-elder and others added 15 commits October 24, 2024 15:55
* final push

* updated the Summary.md

* fix: fmt and minor edit

---------

Co-authored-by: julio4 <[email protected]>
* sierra->Sierra + plural/singular form fixes

* ch00 > Missing attr. elems, wrong attr. names

* missing dot in messages + update how legacymap modulo format

* ch00 > errors > add indent to comment in complex section

* ch00 > events > wording, missing code quotes

* ch00 > syscalls > wording

* ch00 > bytearray > wording

* ch00 > stor.custom types > wording

* ch00 > cust.types in entrypoints > wording

* ch00 > documentation > wording

* Revert comment format changes

* Simplify panic_with_felt252 related comment in errors.md

* Fixes for ch00

* Wording in cheatsheet

* Comment update in type_casting

---------

Co-authored-by: Nenad <[email protected]>
* test: component dependencies

* undo changes

* test: countable_component

* test: countable_internal_dep_switch

* fix: apply requested changes

* fix: small fmt fix

---------

Co-authored-by: julio4 <[email protected]>
* feat(staking): first draft with contract and tests

Missing events and some tests

* feat(staking): Add events and events-related tests

* feat(staking): Add a more complex test for rewards set up

* feat(staking): Add md file

* feat(staking): Apply changes according to PR review
* feat(enums): Enums in contract

* fix: small fmt

---------

Co-authored-by: julio4 <[email protected]>
…r.is_non_zero` (NethermindEth#213)

* upgradeable > use is_non_zero

* simple_vault > grammar

* not is_zero -> is_non_zero

* update sbe links

* staking > wording

* amm > fix brackets + grammar

---------

Co-authored-by: Nenad <[email protected]>
* add time locked transactions example

* install snforge in gh-action

* fix: refactor timelock example
* added erc20 unit test

* added test against custom errors

* formated

* made requested changes and moved test to contract module

* fixed zero address

* chore: Remove unused test files

* test for upgradeable contracts

* fixed build issue

* fix: pr#203

---------

Co-authored-by: julio4 <[email protected]>
…#210)

* how-to fixes

* Clean up dependencies

* collisions > fixes

* ownable minor fixes

* remove error.log

* fix typo

* add comma after 'first'

* add 'the' before cairo book

---------

Co-authored-by: Nenad <[email protected]>
0xNeshi and others added 24 commits October 24, 2024 15:55
…#215)

* formatting for write to slot

* stor. arrs. > wording, grammar

* hashing > wording, grammar

* packing > wording, grammar, format

* list > amount->amounts, wording, typos

* plugins > grammar

* sign. verif. > grammar

* remove 'a' in how_to

* update library calls -> dispatcher

* Revert "update library calls -> dispatcher"

This reverts commit e7d3b0c.

* align library calls header

* fix tests

---------

Co-authored-by: Nenad <[email protected]>
* feat: nft auction

* test: add tests to nft_auction app

* chore: improve code and add more tests

* chore: improvements and more tests

* test: add more test cases for nft_auction

* chore: update mdbook

* chore: update nft_auction package
- Add error module
- Update snforge version to 0.24.0

* chore: rename package and related files from `nft_auction` to `nft_dutch_auction`

* chore: reused existing package

* fix: cli#204

---------

Co-authored-by: julio4 <[email protected]>
* fix: chapter-related folder names

* updated all references
* feat: simple storage with starknet-js

* feat: add how_to_deploy & fix tutorial content for simple_storage

* fix: update links & add section in summary

* feat: revisions NethermindEth#222

---------

Co-authored-by: julio4 <[email protected]>
* add initial factory

* add ownable component

* add caller to CounterCreated event

* turn counter into campaign

* fix Campaign interfaced funcs + implement donate

* add _assert_is_ended + update error messages

* _assert_active->_assert_campaign_active

* _assert_is_ended->_assert_campaign_ended

* implement withdraw

* add missing assert success in donate

* add title & description

* update comment

* implement upgrade

* clean up internal funcs and imports

* move hardcoded errors in Errors mod

* donate -> contribute + event rename

* withdraw -> claim

* add store impl for contract addr. array

* remove store impl

* add dynamic array impl

* remove dyn. array

* remove descr + convert title to felt + convert target to u128

* implement updating class hashes

* Make title ByteArray again + target into u256 + update ctor arg serialization

* refactor serialization + add back description

* remove unused contracts

* add 1 test

* add get_description

* add correct deps

* add alexandria to toml

* format factory.cairo

* add missing snforge workspace

* add missing getters + tests

* add factory deploy tests

* add class hash update test + event assertions

* assert old class hash prior to update

* remove commented out test

* use common alex. storage workspace in using_lists

* add missing newline in toml

* move factory tests to separate file

* add scaffold docs for contracts

* add end_time asserts

* refactor private asserts

* check if target reached before claiming

* add ability to withdraw funds

* make contributions into a component (now iterable)

* refactor 'withhold' - contrs map to amt_idx

* add get_contributors func

* get_contributors -> get_contributions

* total_contributors->contributor_count

* add tests for campaign upgrade and deploy + update all relevant code in factory

* add status to campaign

* add close fn

* pass desired donation token in ctor

* merge all getters into get_details

* return total_contributions in details

* remove rev version from alexandria dep

* verbose names

* reorg. folder structure

* add tag to alexandria dep

* campaign_upgrade.cairo->mock_upgrade.cairo

* add explicit alexandria rev + make crowdfunding contracts standalone chapters

* add status pending

* field rename: factory->creator

* refund users when upgrading campaign

* Make owner the calling address, and creator is the campaign manager

* add get_contributor (amount) func

* Add successful campaign test

* update comment for upgrade

* _refund_all->_withdraw_all

* update checks for withdraw

* rework contribute

* rework all funcs

* unsuccessful -> failed

* calc end_time in start fn

* calc end_time in upgrade fn

* makes upgrades callable only by creators in factory

* fix factory tests

* fix crowdfunding tests

* reduce total contri. when withdraw from act. camp

* add refund fn

* refactor withdraw_all to use _refund

* pending->draft

* fix mock and tests

* add test for close

* add test for withdraw

* upgrade > update end_time only if duration provided

* close->cancel

* rename to more align with Solidity by example

* target->goal

* remove comment

* err CLOSED->CANCELED + check active in unpledge

* contributor->pledger

* add campaign doc content

* remove draft status

* add start_time

* remove Status

* update doc for campaign

* move total_pledges to pledgeable

* reorder alphabetically

* remove Launched event + upgrade mock

* TARGET->GOAL

* reorder params in Details

* add inline to _refund

* add new pledgeable tests

* add getX tests + add get_pledge_count

* refactor pledger_to_amount_index->pledger_to_amount

* Add tests with 1000 pledgers

* add test for add + update existing pledger

* reenable lib

* Add link to adv. factory in crowdfunding point 9

* write the adv. factory chapter

* upgrade_campaign_implementation-> upgrade_campaign + comment updates

* rename get_pledgers_as_arr->array

* Use ERC20Upgradeable instead of ERC20 preset

* Add missing token recipient ctor argument in crowdfunding tests

---------

Co-authored-by: Nenad <[email protected]>
* test: implement test for countable component

* test: implement test for switchable component

* test: implement test for ownable component

* chore: implement test for emitted events and add anchor tags

* feat: apply requested changes

* feat: apply requested changes

* feat: revisions

---------

Co-authored-by: julio4 <[email protected]>
* test: SNIP-6 implementation

* docs: errors recheck

* test: SNIP-6 implementation

* docs: errors recheck

* feat: add simple account example

* feat/fix: revisions on NethermindEth#200

* feat:implement SRC5

* feat: implementation with oz

* fix: oz impl src5 for account

---------

Co-authored-by: Oluwaseun Jeremiah <jeremiah@Jemiah>
Co-authored-by: julio4 <[email protected]>
Some updates and corrections.
* simple_vault test implementation

* Added dict cheatsheet

* Added dict cheatsheet

* a little clean up

* a little clean up
- Add link to NFT Dutch Auction chapter
* remove List

No longer needed with Vec

* chore: dependencies update >=2.8

* chore: 2024_07 edition getting-started

* chore: Map getting-started

* chore: update applications

* chore: update dependencies

* fix: storage variables PointerReadAccess

* doc: update contributor guide

* chore: update advanced-concepts

* fix: 2024_07 edition

* chore: versions update

* feat: storage custom types individual members access

* remove storing arrays chapter

* ci/cd: remove custom test resolver script

* chore: switch dependencies to scarb registry

* Revert "ci/cd: remove custom test resolver script"

This reverts commit 0c3549f.

* chore: split snforge/cairo-test scarb config
* feat: dice game vrf application

* feat: add summary nav

* fix: ran scarb fmt

* fix: ran scarb fmt

* Fix new lines

* Add more info on randomness sources

* Rename dice_game_vrf.md->random_number_generator.md and update titles

* minor rewording of 1 entropy source

* remove anchors

* Minor changes to fn names

* Implement dice game scaffold

* Implement Pragma randomness

* minor refactor in randomness request

* Implement powerball scaffold

* Turn Dice Game into CoinFlip

* Implement coin_flip test

* Add more tests

* Update titles

* Remove redundant blank line

* Add premium fee calculation into tests

* Assert leftover balance

* Remove comment about fees

* Increase the expected callback fee, update mock to expose fee calc fn

* Unfinished: refunded

* Store and use is_refunded flag

* Implement logic necessary to successfully perform & test refund

* Update callback fee limit based on manual testing + update term to deposit

* Format

* Use a FlipData struct instead of tuple

* Fix refund

* Simplify CoinFlip to pay the flips itself

* CALLBACK_FEE_DEPOSIT->MAX_CALLBACK_FEE_DEPOSIT

* Update tests to test the new CoinFlip contract

* Fix compile errors

* Increase publish_delay to 1 & remove unused imports

* Remove starkli-wallet dir

* Generate 3 random words for the 1st test

* refactor tests

* Add missng newline to scarb.toml

* fix typo in md

* reword 'manipulation' def

* Chainlink->Pragma

* link to Commit-reveal chapter issue

* list 'shut down' as possible centr. issue with ext. oracles

* Turn point 5 into a note

* Remove Sideways enum

* add contract description

* Remove ResultTrait from crowdfunding tests.cairo

---------

Co-authored-by: Tony Stark <[email protected]>
Co-authored-by: Nenad <[email protected]>
Co-authored-by: Nenad <[email protected]>
* feat(merkle-tree): Contract with tests

* feat(merkle-tree): Corrections according to PR reviews

* feat(merkle-tree): Contract with tests

* fix: 2024_07 edition

* fix: Replace Map simulating Array with Vec - streamline md file explanations

* fix: scarb fmt

---------

Co-authored-by: julio4 <[email protected]>
* fix: typos

* ci/cd: typos check in ci

* fix: cases

* fix: randomness requestor typos
* Expand Constant Product AMM's description

* Refactor

---------

Co-authored-by: Julio <[email protected]>
* Set one common edition version in workspace Scarb.toml

* move snforge_std to dev-deps

* Remove [lib] from coin_flip and simple_storage_starknetjs

* rebuild projects

* remove casm attr from scarb.toml

* Update foundry to 0.31.0 in tool-versions

* Set workspace cairo_test in mappings

* Add missing cairo_test.workspace attrbs to Scarb.tomls

* Revert snforge_std to 0.30.0

* Revert "Add missing cairo_test.workspace attrbs to Scarb.tomls"

This reverts commit 7a9131d.
Copy link
Contributor

@julio4 julio4 left a comment

Choose a reason for hiding this comment

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

Changed to a simpler example and wrote the .md file

@julio4 julio4 merged commit bdd9204 into NethermindEth:main Oct 24, 2024
2 checks passed
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.

feat: Commit-Reveal scheme