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

v2: Delete langspec and templates #445

Merged
merged 6 commits into from
Dec 15, 2022
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## What's Changed
### Breaking Changes
* Remove `MakeLogicSigAccount` and replace with `MakeLogicSigAccountEscrow`. Mark `MakeLogicSig` as a private function as well, only intended for internal use.
* Rename `SignLogicsigTransaction` to `SignLogicSigTransaction`.
* Remove logicsig templates, `logic/langspec.json`, and all methods depending on it.
* Remove `DryrunTxnResult.Cost` in favor of 2 fields: `BudgetAdded` and `BudgetConsumed`. `cost` can be derived by `BudgetConsumed - BudgetAdded`.

# 1.24.0
Expand Down
23 changes: 5 additions & 18 deletions crypto/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,23 +187,10 @@ type LogicSigAccount struct {
SigningKey ed25519.PublicKey `codec:"sigkey"`
}

// MakeLogicSigAccountEscrow creates a new escrow LogicSigAccount. The address
// of this account will be a hash of its program.
// Deprecated: This method is deprecated for not applying basic sanity check over program bytes,
// use `MakeLogicSigAccountEscrowChecked` instead.
func MakeLogicSigAccountEscrow(program []byte, args [][]byte) LogicSigAccount {
return LogicSigAccount{
Lsig: types.LogicSig{
Logic: program,
Args: args,
},
}
}

// MakeLogicSigAccountEscrowChecked creates a new escrow LogicSigAccount.
// MakeLogicSigAccountEscrow creates a new escrow LogicSigAccount.
// The address of this account will be a hash of its program.
func MakeLogicSigAccountEscrowChecked(program []byte, args [][]byte) (LogicSigAccount, error) {
lsig, err := MakeLogicSig(program, args, nil, MultisigAccount{})
func MakeLogicSigAccountEscrow(program []byte, args [][]byte) (LogicSigAccount, error) {
lsig, err := makeLogicSig(program, args, nil, MultisigAccount{})
if err != nil {
return LogicSigAccount{}, err
}
Expand All @@ -218,7 +205,7 @@ func MakeLogicSigAccountEscrowChecked(program []byte, args [][]byte) (LogicSigAc
// The parameter signer is the private key of the delegating account.
func MakeLogicSigAccountDelegated(program []byte, args [][]byte, signer ed25519.PrivateKey) (lsa LogicSigAccount, err error) {
var ma MultisigAccount
lsig, err := MakeLogicSig(program, args, signer, ma)
lsig, err := makeLogicSig(program, args, signer, ma)
if err != nil {
return
}
Expand Down Expand Up @@ -248,7 +235,7 @@ func MakeLogicSigAccountDelegated(program []byte, args [][]byte, signer ed25519.
// delegating multisig account. Use the method AppendMultisigSignature on the
// returned LogicSigAccount to add additional signatures from other members.
func MakeLogicSigAccountDelegatedMsig(program []byte, args [][]byte, msigAccount MultisigAccount, signer ed25519.PrivateKey) (lsa LogicSigAccount, err error) {
lsig, err := MakeLogicSig(program, args, signer, msigAccount)
lsig, err := makeLogicSig(program, args, signer, msigAccount)
if err != nil {
return
}
Expand Down
18 changes: 10 additions & 8 deletions crypto/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func TestLogicSigAddress(t *testing.T) {
var sk ed25519.PrivateKey
var ma MultisigAccount

lsig, err := MakeLogicSig(program, args, sk, ma)
lsig, err := makeLogicSig(program, args, sk, ma)
require.NoError(t, err)

actualAddr := LogicSigAddress(lsig)
Expand All @@ -139,7 +139,7 @@ func TestLogicSigAddress(t *testing.T) {

var ma MultisigAccount

lsig, err := MakeLogicSig(program, args, account.PrivateKey, ma)
lsig, err := makeLogicSig(program, args, account.PrivateKey, ma)
require.NoError(t, err)

// for backwards compatibility, we still expect the hashed program bytes address
Expand All @@ -150,7 +150,7 @@ func TestLogicSigAddress(t *testing.T) {
t.Run("multi sig", func(t *testing.T) {
ma, sk1, _, _ := makeTestMultisigAccount(t)

lsig, err := MakeLogicSig(program, args, sk1, ma)
lsig, err := makeLogicSig(program, args, sk1, ma)
require.NoError(t, err)

// for backwards compatibility, we still expect the hashed program bytes address
Expand All @@ -167,7 +167,8 @@ func TestMakeLogicSigAccount(t *testing.T) {
}

t.Run("Escrow", func(t *testing.T) {
lsigAccount := MakeLogicSigAccountEscrow(program, args)
lsigAccount, err := MakeLogicSigAccountEscrow(program, args)
require.NoError(t, err)

require.Equal(t, program, lsigAccount.Lsig.Logic)
require.Equal(t, args, lsigAccount.Lsig.Args)
Expand Down Expand Up @@ -261,7 +262,7 @@ func TestLogicSigAccountFromLogicSig(t *testing.T) {
var sk ed25519.PrivateKey
var ma MultisigAccount

lsig, err := MakeLogicSig(program, args, sk, ma)
lsig, err := makeLogicSig(program, args, sk, ma)
require.NoError(t, err)

t.Run("with public key", func(t *testing.T) {
Expand All @@ -286,7 +287,7 @@ func TestLogicSigAccountFromLogicSig(t *testing.T) {

var ma MultisigAccount

lsig, err := MakeLogicSig(program, args, account.PrivateKey, ma)
lsig, err := makeLogicSig(program, args, account.PrivateKey, ma)
require.NoError(t, err)

t.Run("with correct public key", func(t *testing.T) {
Expand Down Expand Up @@ -316,7 +317,7 @@ func TestLogicSigAccountFromLogicSig(t *testing.T) {
t.Run("multi sig", func(t *testing.T) {
ma, sk1, _, _ := makeTestMultisigAccount(t)

lsig, err := MakeLogicSig(program, args, sk1, ma)
lsig, err := makeLogicSig(program, args, sk1, ma)
require.NoError(t, err)

t.Run("with public key", func(t *testing.T) {
Expand Down Expand Up @@ -350,7 +351,8 @@ func TestLogicSigAccount_Address(t *testing.T) {
}

t.Run("no sig", func(t *testing.T) {
lsigAccount := MakeLogicSigAccountEscrow(program, args)
lsigAccount, err := MakeLogicSigAccountEscrow(program, args)
require.NoError(t, err)

expectedAddr, err := types.DecodeAddress("6Z3C3LDVWGMX23BMSYMANACQOSINPFIRF77H7N3AWJZYV6OH6GWTJKVMXY")
require.NoError(t, err)
Expand Down
13 changes: 4 additions & 9 deletions crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ func SignLogicSigAccountTransaction(logicSigAccount LogicSigAccount, tx types.Tr
return
}

// SignLogicsigTransaction takes LogicSig object and a transaction and returns the
// SignLogicSigTransaction takes LogicSig object and a transaction and returns the
// bytes of a signed transaction ready to be broadcasted to the network
// Note, LogicSig actually can be attached to any transaction and it is a
// program's responsibility to approve/decline the transaction
Expand All @@ -586,7 +586,7 @@ func SignLogicSigAccountTransaction(logicSigAccount LogicSigAccount, tx types.Tr
// the LogicSig's address, EXCEPT IF the LogicSig is delegated to a non-multisig
// account. In order to properly handle that case, create a LogicSigAccount and
// use SignLogicSigAccountTransaction instead.
func SignLogicsigTransaction(lsig types.LogicSig, tx types.Transaction) (txid string, stxBytes []byte, err error) {
func SignLogicSigTransaction(lsig types.LogicSig, tx types.Transaction) (txid string, stxBytes []byte, err error) {
hasSig := lsig.Sig != (types.Signature{})
hasMsig := !lsig.Msig.Blank()

Expand Down Expand Up @@ -640,18 +640,13 @@ func AddressFromProgram(program []byte) types.Address {
return types.Address(hash)
}

// MakeLogicSig produces a new LogicSig signature.
//
// Deprecated: THIS FUNCTION IS DEPRECATED.
// It will be removed in v2 of this library.
// Use one of MakeLogicSigAccountEscrow, MakeLogicSigAccountDelegated, or
// MakeLogicSigAccountDelegatedMsig instead.
// makeLogicSig produces a new LogicSig signature.
//
// The function can work in three modes:
// 1. If no sk and ma provided then it returns contract-only LogicSig
// 2. If no ma provides, it returns Sig delegated LogicSig
// 3. If both sk and ma specified the function returns Multisig delegated LogicSig
func MakeLogicSig(program []byte, args [][]byte, sk ed25519.PrivateKey, ma MultisigAccount) (lsig types.LogicSig, err error) {
func makeLogicSig(program []byte, args [][]byte, sk ed25519.PrivateKey, ma MultisigAccount) (lsig types.LogicSig, err error) {
if err = sanityCheckProgram(program); err != nil {
return
}
Expand Down
29 changes: 15 additions & 14 deletions crypto/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func TestMakeLogicSigBasic(t *testing.T) {
var pk MultisigAccount

// check empty LogicSig
lsig, err := MakeLogicSig(program, args, sk, pk)
lsig, err := makeLogicSig(program, args, sk, pk)
require.Error(t, err)
require.Equal(t, types.LogicSig{}, lsig)
require.True(t, lsig.Blank())
Expand All @@ -298,7 +298,7 @@ func TestMakeLogicSigBasic(t *testing.T) {
contractSender, err := types.DecodeAddress(programHash)
require.NoError(t, err)

lsig, err = MakeLogicSig(program, args, sk, pk)
lsig, err = makeLogicSig(program, args, sk, pk)
require.NoError(t, err)
require.Equal(t, program, lsig.Logic)
require.Equal(t, args, lsig.Args)
Expand All @@ -312,7 +312,7 @@ func TestMakeLogicSigBasic(t *testing.T) {
args = make([][]byte, 2)
args[0] = []byte{1, 2, 3}
args[1] = []byte{4, 5, 6}
lsig, err = MakeLogicSig(program, args, sk, pk)
lsig, err = makeLogicSig(program, args, sk, pk)
require.NoError(t, err)
require.Equal(t, program, lsig.Logic)
require.Equal(t, args, lsig.Args)
Expand All @@ -339,7 +339,7 @@ func TestMakeLogicSigSingle(t *testing.T) {
require.NoError(t, err)
program = []byte{1, 32, 1, 1, 34}
sk = acc.PrivateKey
lsig, err := MakeLogicSig(program, args, sk, pk)
lsig, err := makeLogicSig(program, args, sk, pk)
require.NoError(t, err)
expectedSig := types.Signature{0x3e, 0x5, 0x3d, 0x39, 0x4d, 0xfb, 0x12, 0xbc, 0x65, 0x79, 0x9f, 0xea, 0x31, 0x8a, 0x7b, 0x8e, 0xa2, 0x51, 0x8b, 0x55, 0x2c, 0x8a, 0xbe, 0x6c, 0xd7, 0xa7, 0x65, 0x2d, 0xd8, 0xb0, 0x18, 0x7e, 0x21, 0x5, 0x2d, 0xb9, 0x24, 0x62, 0x89, 0x16, 0xe5, 0x61, 0x74, 0xcd, 0xf, 0x19, 0xac, 0xb9, 0x6c, 0x45, 0xa4, 0x29, 0x91, 0x99, 0x11, 0x1d, 0xe4, 0x7c, 0xe4, 0xfc, 0x12, 0xec, 0xce, 0x2}
require.Equal(t, expectedSig, lsig.Sig)
Expand All @@ -351,7 +351,7 @@ func TestMakeLogicSigSingle(t *testing.T) {
// check that a modified program fails verification
modProgram := make([]byte, len(program))
copy(modProgram, program)
lsigModified, err := MakeLogicSig(modProgram, args, sk, pk)
lsigModified, err := makeLogicSig(modProgram, args, sk, pk)
require.NoError(t, err)
modProgram[3] = 2
verified = VerifyLogicSig(lsigModified, acc.Address)
Expand All @@ -378,7 +378,7 @@ func TestMakeLogicSigMulti(t *testing.T) {
acc := GenerateAccount()
sk = acc.PrivateKey

lsig, err := MakeLogicSig(program, args, sk1, ma)
lsig, err := makeLogicSig(program, args, sk1, ma)
require.NoError(t, err)
require.Equal(t, program, lsig.Logic)
require.Equal(t, args, lsig.Args)
Expand All @@ -400,14 +400,14 @@ func TestMakeLogicSigMulti(t *testing.T) {
// check that a modified program fails verification
modProgram := make([]byte, len(program))
copy(modProgram, program)
lsigModified, err := MakeLogicSig(modProgram, args, sk1, ma)
lsigModified, err := makeLogicSig(modProgram, args, sk1, ma)
require.NoError(t, err)
modProgram[3] = 2
verified = VerifyLogicSig(lsigModified, sender)
require.False(t, verified)

// combine sig and multisig, ensure it fails
lsigf, err := MakeLogicSig(program, args, sk, pk)
lsigf, err := makeLogicSig(program, args, sk, pk)
require.NoError(t, err)
lsig.Sig = lsigf.Sig

Expand Down Expand Up @@ -455,7 +455,7 @@ func TestSignLogicsigTransaction(t *testing.T) {
},
}

txid, stxnBytes, err := SignLogicsigTransaction(lsig, txn)
txid, stxnBytes, err := SignLogicSigTransaction(lsig, txn)
require.NoError(t, err)
require.EqualValues(t, expectedBytes, stxnBytes)
require.Equal(t, expectedTxid, txid)
Expand All @@ -477,7 +477,7 @@ func TestSignLogicsigTransaction(t *testing.T) {
t.Run("no sig", func(t *testing.T) {
var sk ed25519.PrivateKey
var ma MultisigAccount
lsig, err := MakeLogicSig(program, args, sk, ma)
lsig, err := makeLogicSig(program, args, sk, ma)
require.NoError(t, err)

programHash := "6Z3C3LDVWGMX23BMSYMANACQOSINPFIRF77H7N3AWJZYV6OH6GWTJKVMXY"
Expand Down Expand Up @@ -505,7 +505,7 @@ func TestSignLogicsigTransaction(t *testing.T) {
var ma MultisigAccount
acc, err := AccountFromPrivateKey(ed25519.PrivateKey{0xd2, 0xdc, 0x4c, 0xcc, 0xe9, 0x98, 0x62, 0xff, 0xcf, 0x8c, 0xeb, 0x93, 0x6, 0xc4, 0x8d, 0xa6, 0x80, 0x50, 0x82, 0xa, 0xbb, 0x29, 0x95, 0x7a, 0xac, 0x82, 0x68, 0x9a, 0x8c, 0x49, 0x5a, 0x38, 0x5e, 0x67, 0x4f, 0x1c, 0xa, 0xee, 0xec, 0x37, 0x71, 0x89, 0x8f, 0x61, 0xc7, 0x6f, 0xf5, 0xd2, 0x4a, 0x19, 0x79, 0x3e, 0x2c, 0x91, 0xfa, 0x8, 0x51, 0x62, 0x63, 0xe3, 0x85, 0x73, 0xea, 0x42})
require.NoError(t, err)
lsig, err := MakeLogicSig(program, args, acc.PrivateKey, ma)
lsig, err := makeLogicSig(program, args, acc.PrivateKey, ma)
require.NoError(t, err)

t.Run("sender is contract addr", func(t *testing.T) {
Expand Down Expand Up @@ -533,7 +533,7 @@ func TestSignLogicsigTransaction(t *testing.T) {
},
}

_, _, err := SignLogicsigTransaction(lsig, txn)
_, _, err := SignLogicSigTransaction(lsig, txn)
require.Error(t, err, errLsigInvalidSignature)
})
})
Expand All @@ -543,7 +543,7 @@ func TestSignLogicsigTransaction(t *testing.T) {
maAddr, err := ma.Address()
require.NoError(t, err)

lsig, err := MakeLogicSig(program, args, sk1, ma)
lsig, err := makeLogicSig(program, args, sk1, ma)
require.NoError(t, err)

err = AppendMultisigToLogicSig(&lsig, sk2)
Expand Down Expand Up @@ -618,7 +618,8 @@ func TestSignLogicSigAccountTransaction(t *testing.T) {
}

t.Run("no sig", func(t *testing.T) {
lsigAccount := MakeLogicSigAccountEscrow(program, args)
lsigAccount, err := MakeLogicSigAccountEscrow(program, args)
require.NoError(t, err)

programAddr, err := types.DecodeAddress("6Z3C3LDVWGMX23BMSYMANACQOSINPFIRF77H7N3AWJZYV6OH6GWTJKVMXY")
require.NoError(t, err)
Expand Down
12 changes: 2 additions & 10 deletions future/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,6 @@ func TestLogicSig(t *testing.T) {
// validate LogicSig signed transaction against goal
const fromAddress = "47YPQTIGQEO7T4Y4RWDYWEKV6RTR2UNBQXBABEEGM72ESWDQNCQ52OPASU"
const toAddress = "PNWOET7LLOWMBMLE4KOCELCX6X3D3Q4H2Q4QJASYIEOF7YIPPQBG3YQ5YI"
const referenceTxID = "5FJDJD5LMZC3EHUYYJNH5I23U4X6H2KXABNDGPIL557ZMJ33GZHQ"
const mn = "advice pudding treat near rule blouse same whisper inner electric quit surface sunny dismiss leader blood seat clown cost exist hospital century reform able sponsor"
const fee = 1000
const amount = 2000
Expand Down Expand Up @@ -887,21 +886,14 @@ func TestLogicSig(t *testing.T) {
args[0] = []byte("123")
args[1] = []byte("456")
key, err := mnemonic.ToPrivateKey(mn)
var pk crypto.MultisigAccount
require.NoError(t, err)
lsig, err := crypto.MakeLogicSig(program, args, key, pk)
lsig, err := crypto.MakeLogicSigAccountDelegated(program, args, key)
require.NoError(t, err)

_, stxBytes, err := crypto.SignLogicsigTransaction(lsig, tx)
_, stxBytes, err := crypto.SignLogicSigAccountTransaction(lsig, tx)
require.NoError(t, err)

require.Equal(t, byteFromBase64(golden), stxBytes)

sender, err := types.DecodeAddress(fromAddress)
require.NoError(t, err)

verified := crypto.VerifyLogicSig(lsig, sender)
require.True(t, verified)
}

func TestFee(t *testing.T) {
Expand Down
17 changes: 0 additions & 17 deletions logic/bundle_langspec_json.sh

This file was deleted.

Loading