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

dex/networks/eth: ETH fidelity bonds contract #2717

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

martonp
Copy link
Contributor

@martonp martonp commented Mar 22, 2024

This diff introduces the solidity contract that supports posting fidelity bonds on ETH.

ETHBond is a contract that allows users to post fidelity bonds. In order to
save on gas costs, the actual bonds are not stored in the contract, but rather
a commitment to the bond is stored, which is a hash of the user's address and
the current bonds they have posted. The actual values of the bonds should be
stored off chain, but they can be retrieved by checking the event logs of the
contract. The first bond for an account must be posted by calling createBond.
Any further updates to the bonds for an account, including adding, extending,
and refunding bonds should be done by calling updateBonds.
    === Gas usage ===

    Create 1: 72076 (first creation is higher due to creating the commitment array)
    Create 2: 54976
    Create 3: 54976
   
    Update:

     # Old
# New      0      1     2      3      4      5      6 
      1  41143, 42793, 50628, 55233, 59839, 64444, 69050
      2  45002, 57281, 52524, 60360, 64965, 69571, 74177
      3  48850, 61829, 67001, 62245, 70080, 74686, 79292
      4  52697, 66376, 71549, 76722, 71965, 79802, 84408
      5  56545, 70924, 76097, 81270, 86443, 81687, 89524
      6  60392, 75472, 80645, 85818, 90992, 96165, 91410

This diff introduces the solidity contract that supports posting fidelity
bonds on ETH.
Copy link
Member

@JoeGruffins JoeGruffins left a comment

Choose a reason for hiding this comment

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

These tests are really cool. We need them for the current contracts.

// bonds, the difference will be refunded to the sender, but only if the
// locktimes of the bonds to be refunded has passed.
function updateBonds(bytes32 acctID, Bond[] calldata oldBonds, Bond[] calldata newBonds, uint index) external payable senderIsOrigin() {
emit BondUpdated(acctID, index, oldBonds, newBonds);
Copy link
Member

Choose a reason for hiding this comment

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

I'm still reading up on how emit works, but is it ok at the beginning? Does it never happen if the tx fails?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, no log if the tx fails.

// a mapping(bytes32 => bytes32) with only one commitment, but this
// would allow a troublemaker to post a bond blocking the actual
// account owner from doing so.
mapping(bytes32 => bytes32[]) public bondCommits;
Copy link
Member

Choose a reason for hiding this comment

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

Can we get all of the values and locktimes upon restoration from seed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you just check the latest log for the account ID. Actually the log should be updated to include the msg.sender.

Copy link
Member

Choose a reason for hiding this comment

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

Awesome! We can't do that with the utxo bonds yet.

@JoeGruffins JoeGruffins mentioned this pull request Mar 28, 2024
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.

None yet

2 participants