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

Dlc oracle fraud detection #468

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1fb87a3
fix fee on edges
infografx Jun 16, 2019
584cb8b
Merge branch 'arbitrary_message_size' into master-mit-lit-arb_mess_size
infografx Jul 19, 2019
4b2b9da
Fix
infografx Jul 19, 2019
c518693
fix
infografx Jul 19, 2019
0343533
fix
infografx Jul 19, 2019
4c4760c
Merge branch 'fix_fee_on_edges' into master-mit-lit_fee_edges
infografx Jul 19, 2019
9683cf8
Fees calculations.
infografx Jul 20, 2019
e9aefd2
Contract settlement from counterparty works.
infografx Jul 20, 2019
411b2a9
Merge branch 'master-mit-lit_fee_edges' into master-mit-lit_milestone…
infografx Jul 20, 2019
f74115f
Merge branch 'master-mit-lit_fee-fix' into master-mit-lit_milestone2-…
infografx Jul 20, 2019
9f4e7b7
Merge branch 'master-mit-lit_couterparty' into master-mit-lit_milesto…
infografx Jul 20, 2019
39f5f4c
Merge branch 'milestone2-test' into master-mit-lit_milestone2-test
infografx Jul 22, 2019
86a9164
Fix
infografx Jul 22, 2019
b8ede08
Fix.
infografx Jul 22, 2019
bbff319
Fix.
infografx Jul 25, 2019
238c50f
Remove import btcrpc
infografx Jul 25, 2019
502803e
The test for milestone2 is completed.
infografx Jul 25, 2019
d2020b6
Fix.
infografx Jul 26, 2019
73295c7
Add FeePerByte to the lit-af utility.
infografx Jul 26, 2019
bc28dc9
Merge branch 'master-mit-lit_milestone2-test_wos' into master-mit-lit…
infografx Sep 17, 2019
f1910e0
Some cleanup.
infografx Sep 17, 2019
42c8091
A little fix.
infografx Sep 20, 2019
89a32d0
Multiple oracles support added.
infografx Sep 30, 2019
3fa0e47
Oracle Fraud Detection.
infografx Nov 6, 2019
566c4c6
Fix.
infografx Nov 11, 2019
a8e43c2
Fix.
infografx Nov 12, 2019
8c9c5d5
Cleanup.
infografx Nov 12, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Lit stuff
lit
dlcoracle
lit-af
!cmd/lit-af
cmd/lit-af/lit-af
Expand Down
185 changes: 183 additions & 2 deletions cmd/lit-af/dlccmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strconv"
"strings"
"time"
"errors"

"github.com/fatih/color"
"github.com/mit-dci/lit/litrpc"
Expand Down Expand Up @@ -102,6 +103,9 @@ var contractCommand = &Command{
fmt.Sprintf("%-20s %s",
lnutil.White("settime"),
"Sets the settlement time of a contract"),
fmt.Sprintf("%-20s %s",
lnutil.White("setrefundtime"),
"Sets the refund time of a contract"),
fmt.Sprintf("%-20s %s",
lnutil.White("setdatafeed"),
"Sets the data feed to use, will fetch the R point"),
Expand All @@ -117,6 +121,11 @@ var contractCommand = &Command{
fmt.Sprintf("%-20s %s",
lnutil.White("setcointype"),
"Sets the cointype of a contract"),
fmt.Sprintf("%-20s %s",
lnutil.White("setfeeperbyte"),
fmt.Sprintf("%-20s %s",
lnutil.White("setoraclesnumber"),
"Sets the oracles number for a contract"),
fmt.Sprintf("%-20s %s",
lnutil.White("offer"),
"Offer a draft contract to one of your peers"),
Expand Down Expand Up @@ -238,6 +247,23 @@ var setContractSettlementTimeCommand = &Command{
),
ShortDescription: "Sets the settlement time for the contract\n",
}


var setContractRefundTimeCommand = &Command{
Format: fmt.Sprintf("%s%s\n", lnutil.White("dlc contract settime"),
lnutil.ReqColor("cid", "time")),
Description: fmt.Sprintf("%s\n%s\n%s\n",
"Sets the refund time for the contract",
fmt.Sprintf("%-10s %s",
lnutil.White("cid"),
"The ID of the contract"),
fmt.Sprintf("%-10s %s",
lnutil.White("time"),
"The refund time (unix timestamp)"),
),
ShortDescription: "Sets the settlement time for the contract\n",
}

var setContractFundingCommand = &Command{
Format: fmt.Sprintf("%s%s\n", lnutil.White("dlc contract setfunding"),
lnutil.ReqColor("cid", "ourAmount", "theirAmount")),
Expand Down Expand Up @@ -289,6 +315,36 @@ var setContractCoinTypeCommand = &Command{
),
ShortDescription: "Sets the coin type to use for the contract\n",
}
var setContractFeePerByteCommand = &Command{
Format: fmt.Sprintf("%s%s\n", lnutil.White("dlc contract setfeeperbyte"),
lnutil.ReqColor("cid", "feeperbyte")),
Description: fmt.Sprintf("%s\n%s\n%s\n",
"Sets the fee per byte to use for the contract",
fmt.Sprintf("%-10s %s",
lnutil.White("cid"),
"The ID of the contract"),
fmt.Sprintf("%-10s %s",
lnutil.White("feeperbyte"),
"The fee per byte in satoshi to use for the contract"),
),
ShortDescription: "Sets the fee per byte in satoshi to use for the contract\n",
}

var setContractOraclesNumberCommand = &Command{
Format: fmt.Sprintf("%s%s\n", lnutil.White("dlc contract setoraclesnumber"),
lnutil.ReqColor("cid", "oraclesnumber")),
Description: fmt.Sprintf("%s\n%s\n%s\n",
"Sets the oracles number to use for the contract",
fmt.Sprintf("%-10s %s",
lnutil.White("cid"),
"The ID of the contract"),
fmt.Sprintf("%-10s %s",
lnutil.White("oraclesnumber"),
"The oracles number to use for the contract"),
),
ShortDescription: "Sets a number of oracles required for the contract\n",
}

var declineContractCommand = &Command{
Format: fmt.Sprintf("%s%s\n", lnutil.White("dlc contract decline"),
lnutil.ReqColor("cid")),
Expand Down Expand Up @@ -492,6 +548,10 @@ func (lc *litAfClient) DlcContract(textArgs []string) error {
return lc.DlcSetContractSettlementTime(textArgs)
}

if cmd == "setrefundtime" {
return lc.DlcSetContractRefundTime(textArgs)
}

if cmd == "setfunding" {
return lc.DlcSetContractFunding(textArgs)
}
Expand All @@ -504,6 +564,14 @@ func (lc *litAfClient) DlcContract(textArgs []string) error {
return lc.DlcSetContractCoinType(textArgs)
}

if cmd == "setfeeperbyte" {
return lc.DlcSetContractFeePerByte(textArgs)
}

if cmd == "setoraclesnumber" {
return lc.DlcSetContractOraclesNumber(textArgs)
}

if cmd == "offer" {
return lc.DlcOfferContract(textArgs)
}
Expand Down Expand Up @@ -737,6 +805,38 @@ func (lc *litAfClient) DlcSetContractSettlementTime(textArgs []string) error {
return nil
}

func (lc *litAfClient) DlcSetContractRefundTime(textArgs []string) error {
stopEx, err := CheckHelpCommand(setContractRefundTimeCommand, textArgs, 2)
if err != nil || stopEx {
return err
}

args := new(litrpc.SetContractSettlementTimeArgs)
reply := new(litrpc.SetContractSettlementTimeReply)

cIdx, err := strconv.ParseUint(textArgs[0], 10, 64)
if err != nil {
return err
}
time, err := strconv.ParseUint(textArgs[1], 10, 64)
if err != nil {
return err
}
args.CIdx = cIdx
args.Time = time

err = lc.Call("LitRPC.SetContractRefundTime", args, reply)
if err != nil {
return err
}

fmt.Fprint(color.Output, "Refund time set successfully\n")

return nil
}



func (lc *litAfClient) DlcSetContractFunding(textArgs []string) error {
stopEx, err := CheckHelpCommand(setContractFundingCommand, textArgs, 3)
if err != nil || stopEx {
Expand Down Expand Up @@ -803,6 +903,79 @@ func (lc *litAfClient) DlcSetContractCoinType(textArgs []string) error {
return nil
}


func (lc *litAfClient) DlcSetContractFeePerByte(textArgs []string) error {
stopEx, err := CheckHelpCommand(setContractFeePerByteCommand, textArgs, 2)
if err != nil || stopEx {
return err
}

args := new(litrpc.SetContractFeePerByteArgs)
reply := new(litrpc.SetContractFeePerByteReply)

cIdx, err := strconv.ParseUint(textArgs[0], 10, 64)
if err != nil {
return err
}
feeperbyte, err := strconv.ParseUint(textArgs[1], 10, 64)
if err != nil {
return err
}

args.CIdx = cIdx
args.FeePerByte = uint32(feeperbyte)

err = lc.Call("LitRPC.SetContractFeePerByte", args, reply)
if err != nil {
return err
}

fmt.Fprint(color.Output, "Fee per byte set successfully\n")

return nil
}




func (lc *litAfClient) DlcSetContractOraclesNumber(textArgs []string) error {
stopEx, err := CheckHelpCommand(setContractOraclesNumberCommand, textArgs, 2)
if err != nil || stopEx {
return err
}

args := new(litrpc.SetContractOraclesNumberArgs)
reply := new(litrpc.SetContractOraclesNumberReply)

cIdx, err := strconv.ParseUint(textArgs[0], 10, 64)
if err != nil {
return err
}
OraclesNumber, err := strconv.ParseUint(textArgs[1], 10, 64)
if err != nil {
return err
}

if OraclesNumber > 1 {
return errors.New("Multiple oracles supported only from RPC cals.")
}

args.CIdx = cIdx
args.OraclesNumber = uint32(OraclesNumber)

err = lc.Call("LitRPC.SetContractOraclesNumber", args, reply)
if err != nil {
return err
}

fmt.Fprint(color.Output, "SetContractOraclesNumber set successfully\n")

return nil
}




func (lc *litAfClient) DlcSetContractDivision(textArgs []string) error {
stopEx, err := CheckHelpCommand(setContractDivisionCommand, textArgs, 3)
if err != nil || stopEx {
Expand Down Expand Up @@ -956,19 +1129,27 @@ func PrintContract(c *lnutil.DlcContract) {
fmt.Fprintf(color.Output, "%-30s : %d\n", lnutil.White("Index"), c.Idx)
fmt.Fprintf(color.Output, "%-30s : [%x...%x...%x]\n",
lnutil.White("Oracle public key"),
c.OracleA[:2], c.OracleA[15:16], c.OracleA[31:])
c.OracleA[0][:2], c.OracleA[0][15:16], c.OracleA[0][31:])
fmt.Fprintf(color.Output, "%-30s : [%x...%x...%x]\n",
lnutil.White("Oracle R-point"), c.OracleR[:2],
c.OracleR[15:16], c.OracleR[31:])
c.OracleR[0][15:16], c.OracleR[0][31:])
fmt.Fprintf(color.Output, "%-30s : %s\n",
lnutil.White("Settlement time"),
time.Unix(int64(c.OracleTimestamp), 0).UTC().Format(time.UnixDate))
fmt.Fprintf(color.Output, "%-30s : %s\n",
lnutil.White("Refund time"),
time.Unix(int64(c.RefundTimestamp), 0).UTC().Format(time.UnixDate))
fmt.Fprintf(color.Output, "%-30s : %d\n",
lnutil.White("Funded by us"), c.OurFundingAmount)
fmt.Fprintf(color.Output, "%-30s : %d\n",
lnutil.White("Funded by peer"), c.TheirFundingAmount)
fmt.Fprintf(color.Output, "%-30s : %d\n",
lnutil.White("Coin type"), c.CoinType)
fmt.Fprintf(color.Output, "%-30s : %d\n",
lnutil.White("Fee per byte"), c.FeePerByte)
fmt.Fprintf(color.Output, "%-30s : %d\n",
lnutil.White("Oracles number"), c.OraclesNumber)


peer := "None"
if c.PeerIdx > 0 {
Expand Down
1 change: 1 addition & 0 deletions consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ const (
QcStateFee = 10 // fixqcstatefee
DefaultLockTime = 500 //default lock time
DlcSettlementTxFee = 1000
MaxOraclesNumber = 8
)
Loading