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
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
version: "2"
linters:
enable:
- exhaustive
settings:
cyclop:
max-complexity: 30
package-average: 10
errcheck:
check-type-assertions: false
exhaustive:
check:
- switch
exhaustruct:
exclude:
- ^net/http.Client$
Expand Down
2 changes: 2 additions & 0 deletions pkg/client/transactions_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ func guessTransactionInfoType(t *proto.TransactionTypeVersion) (TransactionInfo,
out = &EthereumTransactionInfo{}
case proto.CommitToGenerationTransaction: // 19
out = &CommitToGenerationTransactionInfo{}
case proto.InvokeExpressionTransaction: // 20 Not used yet.
out = nil // Do nothing.
}
if out == nil {
return nil, errors.Errorf("unknown transaction type %d version %d", t.Type, t.Version)
Expand Down
6 changes: 6 additions & 0 deletions pkg/crypto/groth16.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package crypto
import (
"bytes"
"encoding/binary"
"fmt"

"github.com/consensys/gnark-crypto/ecc"
"github.com/consensys/gnark-crypto/ecc/bn254/fr"
Expand Down Expand Up @@ -53,6 +54,11 @@ func Groth16Verify(vkBytes []byte, proofBytes []byte, inputsBytes []byte, curve
return false, err
}
proof = bn256proof
case ecc.UNKNOWN:
return false, errors.Errorf("unknown elliptic curve")
case ecc.BLS12_377, ecc.BLS24_315, ecc.BLS24_317, ecc.BW6_761, ecc.BW6_633, ecc.STARK_CURVE,
ecc.SECP256K1, ecc.GRUMPKIN:
return false, fmt.Errorf("unsupported curve %s", curve)
default:
return false, errors.Errorf("unknown elliptic curve")
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/proto/eth_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,8 @@ func (fs FrontierSigner) Hash(tx *EthereumTransaction) EthereumHash {
case EthereumAccessListTxType, EthereumDynamicFeeTxType:
rlpData = append(rlpData, byte(tx.EthereumTxType()))
rlpData = hashValues.MarshalTo(rlpData)
case UndefinedTxType:
return EthereumHash{} // The same as default.
default:
// This _should_ not happen, but in case someone sends in a bad
// json struct via RPC, it's probably more prudent to return an
Expand Down
6 changes: 6 additions & 0 deletions pkg/proto/eth_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ func (e EthereumTxType) String() string {
return "EthereumAccessListTxType"
case EthereumDynamicFeeTxType:
return "EthereumDynamicFeeTxType"
case UndefinedTxType:
return "UndefinedTxType"
default:
return ""
}
Expand Down Expand Up @@ -684,6 +686,10 @@ func (tx *EthereumTransaction) decodeTypedCanonical(canonicalData []byte) (Ether
)
}
return &inner, nil
case EthereumLegacyTxType:
return nil, ErrTxTypeNotSupported
case UndefinedTxType:
return nil, ErrTxTypeNotSupported
default:
return nil, ErrTxTypeNotSupported
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/proto/snapshot_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,8 @@ func (s TransactionStatusSnapshot) AppendToProtobuf(txSnapshots *g.TransactionSt
txSnapshots.TransactionStatus = g.TransactionStatus_ELIDED
case TransactionFailed:
txSnapshots.TransactionStatus = g.TransactionStatus_FAILED
case unknownTransactionStatus:
return errors.New("unknown transaction status")
default:
return errors.Errorf("undefined tx status %d", s.Status)
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/proto/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,11 @@ func (a TransactionTypeInfo) String() string {
switch a.Type {
case TransferTransaction:
sb.WriteString("TransferTransaction")
default:
case GenesisTransaction, PaymentTransaction, IssueTransaction, ReissueTransaction, BurnTransaction,
ExchangeTransaction, LeaseTransaction, LeaseCancelTransaction, CreateAliasTransaction,
MassTransferTransaction, DataTransaction, SetScriptTransaction, SponsorshipTransaction,
SetAssetScriptTransaction, InvokeScriptTransaction, UpdateAssetInfoTransaction, EthereumMetamaskTransaction,
CommitToGenerationTransaction, InvokeExpressionTransaction:
sb.WriteString(strconv.Itoa(int(a.Type)))
}
sb.WriteString(" ")
Expand Down Expand Up @@ -407,6 +411,8 @@ func GuessTransactionType(t *TransactionTypeVersion) (Transaction, error) {
out = &EthereumTransaction{}
case CommitToGenerationTransaction: // 19
out = &CommitToGenerationWithProofs{}
case InvokeExpressionTransaction: // 20, Not used yet.
out = nil
}
if out == nil {
return nil, errors.Errorf("unknown transaction type %d version %d", t.Type, t.Version)
Expand Down
8 changes: 8 additions & 0 deletions pkg/proto/transactions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5371,6 +5371,8 @@ func TestDataWithProofsProtobufRoundTrip(t *testing.T) {
e = &BinaryDataEntry{k, v}
case DataString:
e = &StringDataEntry{k, tc.values[i]}
case DataDelete:
// Do nothing for Delete entry.
}
err := tx.AppendEntry(e)
assert.NoError(t, err)
Expand Down Expand Up @@ -5429,6 +5431,8 @@ func TestDataWithProofsBinarySize(t *testing.T) {
e = &BinaryDataEntry{k, v}
case DataString:
e = &StringDataEntry{k, tc.values[i]}
case DataDelete:
// Do nothing for Delete entry.
}
err := tx.AppendEntry(e)
assert.NoError(t, err)
Expand Down Expand Up @@ -5471,6 +5475,8 @@ func TestDataWithProofsBinaryRoundTrip(t *testing.T) {
e = &BinaryDataEntry{k, v}
case DataString:
e = &StringDataEntry{k, tc.values[i]}
case DataDelete:
// Do nothing.
}
err := tx.AppendEntry(e)
assert.NoError(t, err)
Expand Down Expand Up @@ -5570,6 +5576,8 @@ func TestDataWithProofsToJSON(t *testing.T) {
sb.WriteRune('"')
sb.WriteString(tc.values[i])
sb.WriteRune('"')
case DataDelete:
// Do nothing.
}
sb.WriteRune('}')
err := tx.AppendEntry(e)
Expand Down
24 changes: 12 additions & 12 deletions pkg/proto/transactions_with_proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -1611,28 +1611,28 @@ func (tx *ExchangeWithProofs) BodyMarshalBinary(Scheme) ([]byte, error) {
var o2b []byte
var err error
switch tx.Order1.GetVersion() {
case 1:
case OrderVersionV1:
o1b, err = tx.marshalAsOrderV1(tx.Order1)
case 2:
case OrderVersionV2:
o1b, err = tx.marshalAsOrderV2(tx.Order1)
case 3:
case OrderVersionV3:
o1b, err = tx.marshalAsOrderV3(tx.Order1)
default:
err = errors.Errorf("invalid Order1 version %d", tx.Order1.GetVersion())
case OrderVersionV4:
err = fmt.Errorf("first order of version 4 is not supported")
}
if err != nil {
return nil, errors.Wrap(err, "failed to marshal buy order to bytes")
}
o1l := uint32(len(o1b))
switch tx.Order2.GetVersion() {
case 1:
case OrderVersionV1:
o2b, err = tx.marshalAsOrderV1(tx.Order2)
case 2:
case OrderVersionV2:
o2b, err = tx.marshalAsOrderV2(tx.Order2)
case 3:
case OrderVersionV3:
o2b, err = tx.marshalAsOrderV3(tx.Order2)
default:
err = errors.Errorf("invalid Order2 version %d", tx.Order2.GetVersion())
case OrderVersionV4:
err = fmt.Errorf("second order of version 4 is not supported")
}
if err != nil {
return nil, errors.Wrap(err, "failed to marshal sell order to bytes")
Expand Down Expand Up @@ -3384,8 +3384,8 @@ func (tx *DataWithProofs) bodyUnmarshalBinary(data []byte) error {
var se StringDataEntry
err = se.UnmarshalBinary(data)
e = &se
default:
return errors.Errorf("unsupported ValueType %d", t)
case DataDelete:
return errors.New("value of type DataDelete is not supported")
}
if err != nil {
return errors.Wrap(err, "failed to unmarshal DataWithProofs transaction body from bytes")
Expand Down
31 changes: 18 additions & 13 deletions pkg/proto/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,14 +608,13 @@ func (m *OrderPriceMode) UnmarshalJSON(val []byte) error {
}

func (m OrderPriceMode) MarshalJSON() ([]byte, error) {
if !m.isValidOrderPriceValue() {
return nil, errors.Errorf("invalid OrderPriceMode=%d", byte(m))
}
switch m {
case OrderPriceModeDefault:
return []byte(jsonNull), nil
default:
case OrderPriceModeFixedDecimals, OrderPriceModeAssetDecimals:
return fmt.Appendf(nil, "\"%s\"", m.String()), nil
default:
return nil, errors.Errorf("invalid OrderPriceMode=%d", byte(m))
}
}

Expand Down Expand Up @@ -683,13 +682,13 @@ func (m OrderPriceMode) isValidOrderPriceValue() bool {

func (m OrderPriceMode) Valid(orderVersion OrderVersion) (bool, error) {
switch orderVersion {
case 1, 2, 3:
case OrderVersionV1, OrderVersionV2, OrderVersionV3:
if m != OrderPriceModeDefault {
return false, errors.Errorf("OrderV%d.PriceMode must be %q",
orderVersion, OrderPriceModeDefault.String(),
)
}
default:
case OrderVersionV4:
if !m.isValidOrderPriceValue() {
return false, errors.Errorf("invalid OrderPriceMode = %d", byte(m))
}
Expand Down Expand Up @@ -733,25 +732,25 @@ type Order interface {

func MarshalOrderBody(scheme Scheme, o Order) (data []byte, err error) {
switch version := o.GetVersion(); version {
case 1:
case OrderVersionV1:
o, ok := o.(*OrderV1)
if !ok {
return nil, errors.New("failed to cast an order version 1 to *OrderV1")
}
return o.BodyMarshalBinary()
case 2:
case OrderVersionV2:
o, ok := o.(*OrderV2)
if !ok {
return nil, errors.New("failed to cast an order version 2 to *OrderV2")
}
return o.BodyMarshalBinary()
case 3:
case OrderVersionV3:
o, ok := o.(*OrderV3)
if !ok {
return nil, errors.New("failed to cast an order version 3 to *OrderV3")
}
return o.BodyMarshalBinary()
case 4:
case OrderVersionV4:
switch o := o.(type) {
case *OrderV4:
data, err = o.BodyMarshalBinary(scheme)
Expand Down Expand Up @@ -3346,7 +3345,7 @@ func (s *Script) UnmarshalJSON(value []byte) error {
// ArgumentValueType is an alias for byte that encodes the value type.
type ArgumentValueType byte

// String translates ValueType value to human readable name.
// String translates ValueType value to human-readable name.
func (vt ArgumentValueType) String() string {
switch vt {
case ArgumentInteger:
Expand All @@ -3359,6 +3358,10 @@ func (vt ArgumentValueType) String() string {
return "string"
case ArgumentList:
return "list"
case ArgumentValueFalse:
return "false"
case ArgumentValueTrue:
return "true"
default:
return ""
}
Expand Down Expand Up @@ -3500,8 +3503,10 @@ func (a *Arguments) UnmarshalBinary(data []byte) error {
var aa ListArgument
err = aa.UnmarshalBinary(data)
arg = &aa
default:
return errors.Errorf("unsupported argument type %d", data[0])
case ArgumentBoolean:
var ba BooleanArgument
err = ba.UnmarshalBinary(data)
arg = &ba
}
if err != nil {
return errors.Wrap(err, "failed unmarshal Arguments from bytes")
Expand Down
3 changes: 2 additions & 1 deletion pkg/ride/ast/attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ const (
LibV7
LibV8
LibV9
maxVersion // Keep this constant last, used to determine maximum Ride version.
)

// CurrentMaxLibraryVersion reports the max lib version. Update it when a new version was added.
func CurrentMaxLibraryVersion() LibraryVersion {
return LibV9
return maxVersion - 1
}

func NewLibraryVersion(b byte) (LibraryVersion, error) {
Expand Down
5 changes: 3 additions & 2 deletions pkg/ride/compiler/ast_parser.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:exhaustive // Complicated usage of generated pegRules.
package compiler

import (
Expand Down Expand Up @@ -1710,7 +1711,7 @@ func (p *astParser) loadMeta(name string, argsTypes []s.Type) error {
switch p.tree.LibVersion {
case ast.LibV1, ast.LibV2, ast.LibV3, ast.LibV4, ast.LibV5:
return p.loadMetaBeforeV6(name, argsTypes)
case ast.LibV6, ast.LibV7, ast.LibV8:
case ast.LibV6, ast.LibV7, ast.LibV8, ast.LibV9:
return p.loadMetaV6(name, argsTypes)
}
return nil
Expand Down Expand Up @@ -1842,7 +1843,7 @@ func (p *astParser) ruleAnnotatedFunc(node *node32) {
if !s.CallableRetV4.EqualWithEntry(retType) && !s.ThrowType.Equal(retType) {
p.addError(curNode.token32, "CallableFunc must return %s,but return %s", s.CallableRetV4.String(), retType.String())
}
case ast.LibV5, ast.LibV6, ast.LibV7, ast.LibV8:
case ast.LibV5, ast.LibV6, ast.LibV7, ast.LibV8, ast.LibV9:
if !s.CallableRetV5.EqualWithEntry(retType) && !s.ThrowType.Equal(retType) {
p.addError(curNode.token32, "CallableFunc must return %s, but return %s", s.CallableRetV5.String(), retType.String())
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/ride/compiler/ast_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (

"github.com/wavesplatform/gowaves/pkg/client"
"github.com/wavesplatform/gowaves/pkg/ride/ast"
"github.com/wavesplatform/gowaves/pkg/ride/compiler/stdlib"
"github.com/wavesplatform/gowaves/pkg/ride/serialization"
)

Expand Down Expand Up @@ -1138,3 +1139,11 @@ let a = Order("".toBytes(), "".toBytes(), AssetPair("".toBytes(), "".toBytes()),
})
}
}

func TestVarsAndFuncsWithLastRideVersion(t *testing.T) {
vars := stdlib.Vars()
funcs := stdlib.FuncsByVersion()
expectedLen := int(ast.CurrentMaxLibraryVersion())
assert.Len(t, vars.Vars, expectedLen)
assert.Len(t, funcs, expectedLen)
}
2 changes: 2 additions & 0 deletions pkg/ride/compiler/stdlib/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ func handleTypes(node *node32, s string, dropRuntimeTypes bool) Type {
default:
t = SimpleType{stringType}
}
case ruleUnknown, ruleMainRule, ruleTypes, ruleEOF, rule_:
// Do nothing.
}
curNode = curNode.next
if curNode == nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/ride/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/wavesplatform/gowaves/pkg/ride/serialization"
)

Expand Down
4 changes: 3 additions & 1 deletion pkg/ride/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ const (
func MaxChainInvokeComplexityByVersion(version ast.LibraryVersion) (uint32, error) {
// libV1 and libV2 don't have callables
switch version {
case ast.LibV1, ast.LibV2:
return 0, errors.New("invokes are not available before version 3")
case ast.LibV3, ast.LibV4:
return maxChainInvokeComplexityV3V4, nil
case ast.LibV5:
return maxChainInvokeComplexityV5, nil
case ast.LibV6, ast.LibV7, ast.LibV8:
case ast.LibV6, ast.LibV7, ast.LibV8, ast.LibV9:
return maxChainInvokeComplexityV6, nil
default:
return 0, errors.Errorf("unsupported library version %d", version)
Expand Down
Loading
Loading