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

Add support for Hash(ed) Time Lock(ed) Contracts (HTLC) #11

Merged
merged 1 commit into from Apr 12, 2023

Conversation

georgezgeorgez
Copy link
Collaborator

No description provided.

@georgezgeorgez
Copy link
Collaborator Author

@georgezgeorgez georgezgeorgez changed the title WIP: Add initial htlc embedded contract Add HTLC embedded contract Jan 21, 2023
@georgezgeorgez
Copy link
Collaborator Author

Awaiting SporkId to update and then merge

@georgezgeorgez georgezgeorgez changed the title Add HTLC embedded contract WIP: Add HTLC embedded contract Feb 7, 2023
@georgezgeorgez
Copy link
Collaborator Author

Marked as WIP to remove rpc list methods and possibly to add allowing other users to unlock and you receive funds

@georgezgeorgez georgezgeorgez changed the title WIP: Add HTLC embedded contract Add support for Hash(ed) Time Lock(ed) Contracts (HTLC) Feb 19, 2023
@georgezgeorgez
Copy link
Collaborator Author

ready
just writing a ZIP now

@Echo7seven
Copy link

Echo7seven commented Feb 20, 2023 via email

@georgezgeorgez
Copy link
Collaborator Author

"Ready" was referring to the Pull Request for the HTLC code. You received an email because you are subscribed to updates for it. If you are having trouble with Syrius, I suggest you reach out to the community in Telegram or Discord, as that is unrelated to this PR.

@georgezgeorgez
Copy link
Collaborator Author

Per CryptoFish suggestion, changed the rpc names to be consistent/shorter

@georgezgeorgez
Copy link
Collaborator Author

fixed unlocks at the exact expiration time and added some tests for that edge case

ZIP is posted:
https://github.com/deeZNNutz-com/ZIP.deeZNNutz/blob/main/0002.md

beam us up

Implement ZIP:deeZNNutz-0002 for Hash(ed) Time Lock(ed) Contracts using
NoM's default SHA3-256 and the widespread SHA2-256 hash functions

Add an embedded smart contract z1qxemdeddedxhtlcxxxxxxxxxxxxxxxxxygecvw
with 5 contract methods:
- Create
- Reclaim
- Unlock
- DenyProxyUnlock
- AllowProxyUnlock

Add a json-rpc api 'embedded.htlc' with 2 methods:
- GetById
- GetProxyUnlockStatus

Create, Reclaim, and Unlock implement the standard HTLC logic.
In addition, the contract provides a Proxy Unlock feature.

Most applications of HTLCs, e.g. Atomic Swaps, use a shared hashlock for
atomicity between transactions which can span across multiple networks.

These use cases require parties to monitor a network for publicly posted
hashlock preimages and make corresponding transactions before timelocks
expire.

The Proxy Unlock feature allows anyone with the correct preimage to
Unlock an HTLC on behalf of the hashlocked user. The original hashlocked
address receives the funds regardless of who unlocked the HTLC.

Effectively, this allows other network participants to help enforce the
atomicity of transactions such as atomic swaps. NoM's feeless properties
take this from a possibility to a plausibility.

The Proxy Unlock feature is set at the account level and can be toggled
with the DenyProxyUnlock and AllowProxyUnlock contract methods.
The feature is opinionatedly enabled by default because:
- transaction atomicity seems to be the primary/only use case of HTLCs
- it does not impose additional burdens on any user involved
- the only loss is unlock optionality, but funds can always be sent back
- removes a step for the average user to use HTLCs with increased safety
  that they may otherwise not take
@zenon-network
Copy link
Collaborator

@georgezgeorgez the test vm/embedded/implementation/htlc_test.go fails with error imports github.com/zenon-network/go-zenon/chain/genesis/mock: import cycle not allowed in test

@georgezgeorgez
Copy link
Collaborator Author

strange
it ran fine on my own branch
i'll investigate

@georgezgeorgez
Copy link
Collaborator Author

Switched to branch 'master'
Your branch is behind 'origin/master' by 46 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

george@nom:~/repos/zenon-network/go-zenon$ git pull
Updating c0f931d..82fc845
Fast-forward
[...]

george@nom:~/repos/zenon-network/go-zenon$ make znnd
go build -o /home/george/repos/zenon-network/go-zenon/build/znnd /home/george/repos/zenon-network/go-zenon/cmd/znnd/main.go
go: downloading github.com/ethereum/go-ethereum v1.10.22
go: downloading golang.org/x/sys v0.1.0
Build znnd done.
Run "/home/george/repos/zenon-network/go-zenon/build/znnd" to start znnd.

george@nom:~/repos/zenon-network/go-zenon$ go test vm/embedded/tests/htlc_test.go vm/embedded/tests/utils_test.go
ok  	command-line-arguments	1.907s

george@nom:~/repos/zenon-network/go-zenon$ go version
go version go1.18.1 linux/amd64

so during development i used go test vm/embedded/tests/htlc_test.go vm/embedded/tests/utils_test.go to do isolated testing

the github workflow file is using
for s in $(go list ./...); do if ! go test -failfast -v -p 1 $s; then exit 1; fi; done

i see the error in the pipeline
but what's strange is that when i try to run the same locally
my terminal just crashes out
looking at system resources, (i have 16 core, 32 gb ram on a very vanilla ubuntu)
it doesn't make a dent before it crashes

hmmm...

@georgezgeorgez
Copy link
Collaborator Author

oh i guess it is the exit 1 and i am running it directly from my shell

@georgezgeorgez
Copy link
Collaborator Author

oh yeah i just realized
the issue is with my htlc_test in the implementation package
which i put there along side token_test
it's using the mock
i'm just going to get rid of the dependency

@georgezgeorgez
Copy link
Collaborator Author

@zenon-network
okay sorry about that
oversight on my part
fixed
#18

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

4 participants