Skip to content

Commit

Permalink
[Bugfix] AST & IR (Function Call), Bytecode (Helpers) and Constructor…
Browse files Browse the repository at this point in the history
… (Tests) + Proto bump to 0.3.5 + New Detector Tests (#204)

* Mix fixes

* Cleanup

* Bump protos

* Constructor tests improvements

* Fixing function call referencing, type descriptions - it was bugged as ****
  • Loading branch information
0x19 authored Apr 20, 2024
1 parent d3db40f commit 4108c77
Show file tree
Hide file tree
Showing 31 changed files with 584 additions and 299 deletions.
8 changes: 6 additions & 2 deletions ast/and_operation.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package ast

import (
"github.com/goccy/go-json"

v3 "github.com/cncf/xds/go/xds/type/v3"
"github.com/goccy/go-json"
ast_pb "github.com/unpackdev/protos/dist/go/ast"
"github.com/unpackdev/solgo/parser"
)
Expand Down Expand Up @@ -32,6 +31,11 @@ func NewAndOperationExpression(b *ASTBuilder) *AndOperation {
// SetReferenceDescriptor sets the reference descriptions of the AndOperation node.
// This function always returns false for now.
func (b *AndOperation) SetReferenceDescriptor(refId int64, refDesc *TypeDescription) bool {
typeDescriptions := make([]*TypeDescription, 0)
for _, expr := range b.Expressions {
typeDescriptions = append(typeDescriptions, expr.GetTypeDescription())
}
b.TypeDescriptions = typeDescriptions
return false
}

Expand Down
20 changes: 15 additions & 5 deletions ast/function_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ func NewFunctionCall(b *ASTBuilder) *FunctionCall {
// SetReferenceDescriptor sets the reference descriptions of the FunctionCall node.
func (f *FunctionCall) SetReferenceDescriptor(refId int64, refDesc *TypeDescription) bool {
f.ReferencedDeclaration = refId
f.TypeDescription = refDesc

argTypes := make([]*TypeDescription, 0)

for _, arg := range f.Arguments {
argTypes = append(argTypes, arg.GetTypeDescription())
}
f.ArgumentTypes = argTypes
f.TypeDescription = f.buildTypeDescription()

return false
}

Expand Down Expand Up @@ -294,10 +302,12 @@ func (f *FunctionCall) Parse(
expr,
)

f.ArgumentTypes = append(
f.ArgumentTypes,
expr.GetTypeDescription(),
)
if expr.GetTypeDescription() != nil {
f.ArgumentTypes = append(
f.ArgumentTypes,
expr.GetTypeDescription(),
)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion ast/reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (r *Resolver) Resolve() []error {
// Reference update can come in any direction really. For example B that uses A can come first
// and because of it, it B will never discover A. In order to ensure that is not the case here,
// we are going to iterate few times through unprocessed references...
for i := 0; i <= 2; i++ {
for i := 0; i <= 3; i++ {
for nodeId, node := range r.UnprocessedNodes {
if rNodeId, rNodeType := r.resolveByNode(node.Name, node.Node); rNodeType != nil {
if updated := r.tree.UpdateNodeReferenceById(nodeId, rNodeId, rNodeType); updated {
Expand Down
18 changes: 18 additions & 0 deletions bytecode/constructor_test.go

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions bytecode/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,27 @@ func (m *Metadata) GetUrls() []string {
return urls
}

// IsPartial checks whenever decoded bytecode data is partial (some fields are missing, not known)
func (m *Metadata) IsPartial() bool {
if m.cborLength == 0 {
return true
}

if len(m.auxbytes) == 0 {
return true
}

if len(m.Solc) == 0 {
return true
}

if len(m.Ipfs) == 0 && len(m.Bzzr0) == 0 && len(m.Bzzr1) == 0 {
return true
}

return false
}

// DecodeContractMetadata decodes the metadata from Ethereum contract creation bytecode.
// It returns a Metadata object and an error, if any occurred during decoding.
func DecodeContractMetadata(bytecode []byte) (*Metadata, error) {
Expand Down
1 change: 0 additions & 1 deletion contracts/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func (c *Contract) DiscoverMetadata(ctx context.Context) (*bytecode.Metadata, er
return nil, fmt.Errorf("failed to decode contract %s metadata: %s", c.GetAddress(), err)
}
c.descriptor.Metadata = bMetadata

return bMetadata, nil
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"address": "0x45214a964e9009f223905146af9ecd44f7876b00",
"type": "keystore",
"private_key": "",
"public_key": "",
"account": {
"address": "0x45214a964e9009f223905146af9ecd44f7876b00",
"url": "keystore:///home/nevio/dev/unpack/solgo-orig/data/faucets/ethereum/UTC--2024-04-20T08-06-59.509734278Z--45214a964e9009f223905146af9ecd44f7876b00"
},
"password": "c2ltdWxhdG9y",
"network": "ethereum",
"tags": [
"test"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"address": "0x5f060ba7658176299a53739f0d3a9a5befe3b514",
"type": "keystore",
"private_key": "",
"public_key": "",
"account": {
"address": "0x5f060ba7658176299a53739f0d3a9a5befe3b514",
"url": "keystore:///home/nevio/dev/unpack/solgo-orig/data/faucets/ethereum/UTC--2024-04-20T07-24-54.551601436Z--5f060ba7658176299a53739f0d3a9a5befe3b514"
},
"password": "c2ltdWxhdG9y",
"network": "ethereum",
"tags": [
"test"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"address": "0x972dc1aa584d6f235c58523dd1d8f3a880597c7e",
"type": "keystore",
"private_key": "",
"public_key": "",
"account": {
"address": "0x972dc1aa584d6f235c58523dd1d8f3a880597c7e",
"url": "keystore:///home/nevio/dev/unpack/solgo-orig/data/faucets/ethereum/UTC--2024-04-20T09-53-21.594019166Z--972dc1aa584d6f235c58523dd1d8f3a880597c7e"
},
"password": "c2ltdWxhdG9y",
"network": "ethereum",
"tags": [
"test"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"address": "0xdef19352bc69ce8553196fb75df199729079a635",
"type": "keystore",
"private_key": "",
"public_key": "",
"account": {
"address": "0xdef19352bc69ce8553196fb75df199729079a635",
"url": "keystore:///home/nevio/dev/unpack/solgo-orig/data/faucets/ethereum/UTC--2024-04-15T07-30-49.417826720Z--def19352bc69ce8553196fb75df199729079a635"
},
"password": "c2ltdWxhdG9y",
"network": "ethereum",
"tags": [
"test"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"address":"def19352bc69ce8553196fb75df199729079a635","crypto":{"cipher":"aes-128-ctr","ciphertext":"583343f8386762b44313f9580199b5400e3708a7cd7667fd1a863f757192e93d","cipherparams":{"iv":"d02104a664245a7b9789ff0ac7a6ee2b"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"c059f05b6db8bfec7919d2fae01371effbf033fe0142b1379c1ef73882a259e6"},"mac":"68acfe2d44e5048083ee5d819ed5c4a3c0e826a27d12ab3a52d180d4e31ef837"},"id":"93a87a7b-b892-4147-9eb9-cc0caed77c8e","version":3}
2 changes: 1 addition & 1 deletion data/solc/releases/releases.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/tests/audits/ERC20.slither.raw.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion data/tests/audits/Lottery.slither.raw.json

Large diffs are not rendered by default.

Loading

0 comments on commit 4108c77

Please sign in to comment.