Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
50 changes: 42 additions & 8 deletions cmd/goal/multisig.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/spf13/cobra"

"github.com/algorand/go-algorand/cmd/util/datadir"
"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/transactions"
Expand All @@ -33,9 +34,10 @@ import (
)

var (
addr string
msigAddr string
noSig bool
addr string
msigAddr string
noSig bool
useLegacyMsig bool
)

func init() {
Expand All @@ -55,6 +57,7 @@ func init() {
signProgramCmd.Flags().StringVarP(&addr, "address", "a", "", "Address of the key to sign with")
signProgramCmd.Flags().StringVarP(&msigAddr, "msig-address", "A", "", "Multi-Sig Address that signing address is part of")
signProgramCmd.Flags().StringVarP(&outFilename, "lsig-out", "o", "", "File to write partial Lsig to")
signProgramCmd.Flags().BoolVar(&useLegacyMsig, "legacy-msig", false, "Use legacy multisig (if not specified, auto-detect consensus params from algod)")
signProgramCmd.MarkFlagRequired("address")

mergeSigCmd.Flags().StringVarP(&outFilename, "out", "o", "", "Output file for merged transactions")
Expand Down Expand Up @@ -202,25 +205,56 @@ var signProgramCmd = &cobra.Command{
}
lsig.Logic = program
}
if !gotPartial {

if !cmd.Flags().Changed("legacy-msig") { // if not specified, auto-detect from consensus params
params, err := client.SuggestedParams()
if err == nil {
if cparams, ok := config.Consensus[protocol.ConsensusVersion(params.ConsensusVersion)]; ok {
useLegacyMsig = !cparams.LogicSigLMsig
}
}
}

// Get or create partial multisig from appropriate field
var partial crypto.MultisigSig
if gotPartial {
if useLegacyMsig {
if !lsig.LMsig.Blank() {
reportErrorf("LogicSig file contains LMsig field, but --legacy-msig=true is set, which uses Msig. Specify --legacy-msig=false to use LMsig, or provide a LogicSig file with Msig field")
}
partial = lsig.Msig
} else {
if !lsig.Msig.Blank() {
reportErrorf("LogicSig file contains Msig field, but --legacy-msig=false is set, which uses LMsig. Specify --legacy-msig=true to use Msig, or provide a LogicSig file with LMsig field")
}
partial = lsig.LMsig
}
} else {
if msigAddr == "" {
reportErrorf("--msig-address/-A required when partial LogicSig not available")
}
multisigInfo, err := client.LookupMultisigAccount(wh, msigAddr)
if err != nil {
reportErrorf(msigLookupError, err)
}
msig, err := msigInfoToMsig(multisigInfo)
partial, err = msigInfoToMsig(multisigInfo)
if err != nil {
reportErrorf(msigParseError, err)
}
lsig.Msig = msig
}
msig, err := client.MultisigSignProgramWithWallet(wh, pw, program, addr, lsig.Msig)

msig, err := client.MultisigSignProgramWithWallet(wh, pw, program, addr, partial, useLegacyMsig)
if err != nil {
reportErrorf(errorSigningTX, err)
}
lsig.Msig = msig

if useLegacyMsig {
lsig.Msig = msig
lsig.LMsig = crypto.MultisigSig{}
} else {
lsig.Msig = crypto.MultisigSig{}
lsig.LMsig = msig
}
lsigblob := protocol.Encode(&lsig)
err = writeFile(outname, lsigblob, 0600)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions config/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ type ConsensusParams struct {
// sum of estimated op cost must be less than this
LogicSigMaxCost uint64

LogicSigMsig bool
LogicSigLMsig bool

// max decimal precision for assets
MaxAssetDecimals uint32

Expand Down Expand Up @@ -985,6 +988,7 @@ func initConsensusProtocols() {
v18.LogicSigVersion = 1
v18.LogicSigMaxSize = 1000
v18.LogicSigMaxCost = 20000
v18.LogicSigMsig = true
v18.MaxAssetsPerAccount = 1000
v18.SupportTxGroups = true
v18.MaxTxGroupSize = 16
Expand Down Expand Up @@ -1447,6 +1451,8 @@ func initConsensusProtocols() {
vFuture.MaxAppAccess = 16 // Twice as many, though cross products are explicit
vFuture.BytesPerBoxReference = 2048 // Count is more important that bytes, loosen up
vFuture.EnableInnerClawbackWithoutSenderHolding = true
vFuture.LogicSigMsig = false
vFuture.LogicSigLMsig = true

Consensus[protocol.ConsensusFuture] = vFuture

Expand Down
4 changes: 4 additions & 0 deletions daemon/kmd/api/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -1422,6 +1422,10 @@
"public_key": {
"$ref": "#/definitions/PublicKey"
},
"use_legacy_msig": {
"type": "boolean",
"x-go-name": "UseLegacyMsig"
},
"wallet_handle_token": {
"type": "string",
"x-go-name": "WalletHandleToken"
Expand Down
4 changes: 2 additions & 2 deletions daemon/kmd/api/v1/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1185,8 +1185,8 @@ func postMultisigProgramSignHandler(ctx reqContext, w http.ResponseWriter, r *ht
return
}

// Sign the transaction
msig, err := wallet.MultisigSignProgram(req.Program, crypto.Digest(reqAddr), req.PublicKey, req.PartialMsig, []byte(req.WalletPassword))
// Sign the program
msig, err := wallet.MultisigSignProgram(req.Program, crypto.Digest(reqAddr), req.PublicKey, req.PartialMsig, []byte(req.WalletPassword), req.UseLegacyMsig)
if err != nil {
errorResponse(w, http.StatusBadRequest, err)
return
Expand Down
3 changes: 2 additions & 1 deletion daemon/kmd/client/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,15 @@ func (kcl KMDClient) MultisigSignTransaction(walletHandle, pw []byte, tx []byte,
}

// MultisigSignProgram wraps kmdapi.APIV1POSTMultisigProgramSignRequest
func (kcl KMDClient) MultisigSignProgram(walletHandle, pw []byte, addr string, data []byte, pk crypto.PublicKey, partial crypto.MultisigSig) (resp kmdapi.APIV1POSTMultisigProgramSignResponse, err error) {
func (kcl KMDClient) MultisigSignProgram(walletHandle, pw []byte, addr string, data []byte, pk crypto.PublicKey, partial crypto.MultisigSig, useLegacyMsig bool) (resp kmdapi.APIV1POSTMultisigProgramSignResponse, err error) {
req := kmdapi.APIV1POSTMultisigProgramSignRequest{
WalletHandleToken: string(walletHandle),
WalletPassword: string(pw),
Program: data,
Address: addr,
PublicKey: pk,
PartialMsig: partial,
UseLegacyMsig: useLegacyMsig,
}
err = kcl.DoV1Request(req, &resp)
return
Expand Down
Loading
Loading