Skip to content

Commit e1a62cd

Browse files
committed
Fixed the check mayCrossChannel and added test cases
1 parent 22cf8f8 commit e1a62cd

File tree

15 files changed

+439
-77
lines changed

15 files changed

+439
-77
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/hyperledger/fabric-chaincode-go/shim"
7+
"github.com/hyperledger/fabric-protos-go/peer"
8+
)
9+
10+
type SimpleContract struct {
11+
}
12+
13+
func (t *SimpleContract) Invoke(stub shim.ChaincodeStubInterface) peer.Response {
14+
15+
f, args := stub.GetFunctionAndParameters()
16+
resp := stub.InvokeChaincode("contract", []byte("10"), args[0]) // KO: different channels can be choosen at runtime
17+
18+
return shim.Success([]byte("Hello!"))
19+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"warnings" : [ {
3+
"message" : "['go-testcases/hf/cchi/cchi1/cchi1.go':16:63] on 'untyped SimpleContract::Invoke(*SimpleContract t, shim.ChaincodeStubInterface stub)': [EXPRESSION] Detected possible cross-channel invocation. It may lead to a lack of transparency because no new transactions are created during the invocation."
4+
}, {
5+
"message" : "['go-testcases/hf/cchi/cchi1/cchi1.go':16:63] on 'untyped SimpleContract::Invoke(*SimpleContract t, shim.ChaincodeStubInterface stub)': [EXPRESSION] Detected possible cross-channel invocation. It may lead to uncommited write operations during the execution of callee chaincode."
6+
} ],
7+
"files" : [ "report.json" ],
8+
"info" : {
9+
"cfgs" : "1",
10+
"duration" : "68ms",
11+
"end" : "2025-02-21T10:30:08.036+01:00",
12+
"expressions" : "16",
13+
"files" : "0",
14+
"globals" : "6",
15+
"members" : "43",
16+
"programs" : "1",
17+
"start" : "2025-02-21T10:30:07.968+01:00",
18+
"statements" : "3",
19+
"units" : "10",
20+
"version" : "0.1",
21+
"warnings" : "2"
22+
},
23+
"configuration" : {
24+
"analysisGraphs" : "NONE",
25+
"descendingPhaseType" : "NONE",
26+
"dumpForcesUnwinding" : "false",
27+
"fixpointWorkingSet" : "DuplicateFreeFIFOWorkingSet",
28+
"glbThreshold" : "5",
29+
"hotspots" : "unset",
30+
"jsonOutput" : "true",
31+
"openCallPolicy" : "RelaxedOpenCallPolicy",
32+
"optimize" : "false",
33+
"recursionWideningThreshold" : "5",
34+
"semanticChecks" : "CrossChannelInvocationsIssuesChecker",
35+
"serializeInputs" : "false",
36+
"serializeResults" : "false",
37+
"syntacticChecks" : "",
38+
"useWideningPoints" : "true",
39+
"wideningThreshold" : "5",
40+
"workdir" : "go-outputs/hf/cchi/cchi1"
41+
}
42+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/hyperledger/fabric-chaincode-go/shim"
7+
"github.com/hyperledger/fabric-protos-go/peer"
8+
)
9+
10+
type SimpleContract struct {
11+
}
12+
13+
func (t *SimpleContract) Invoke(stub shim.ChaincodeStubInterface) peer.Response {
14+
15+
f, args := stub.GetFunctionAndParameters()
16+
resp := stub.InvokeChaincode("contract", []byte("10"), "ch" + string(args[0])) // KO: different channels can be choosen at runtime
17+
18+
return shim.Success([]byte("Hello!"))
19+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"warnings" : [ {
3+
"message" : "['go-testcases/hf/cchi/cchi2/cchi2.go':16:78] on 'untyped SimpleContract::Invoke(*SimpleContract t, shim.ChaincodeStubInterface stub)': [EXPRESSION] Detected possible cross-channel invocation. It may lead to a lack of transparency because no new transactions are created during the invocation."
4+
}, {
5+
"message" : "['go-testcases/hf/cchi/cchi2/cchi2.go':16:78] on 'untyped SimpleContract::Invoke(*SimpleContract t, shim.ChaincodeStubInterface stub)': [EXPRESSION] Detected possible cross-channel invocation. It may lead to uncommited write operations during the execution of callee chaincode."
6+
} ],
7+
"files" : [ "report.json" ],
8+
"info" : {
9+
"cfgs" : "1",
10+
"duration" : "15ms",
11+
"end" : "2025-02-21T10:30:08.227+01:00",
12+
"expressions" : "19",
13+
"files" : "0",
14+
"globals" : "6",
15+
"members" : "43",
16+
"programs" : "1",
17+
"start" : "2025-02-21T10:30:08.212+01:00",
18+
"statements" : "3",
19+
"units" : "10",
20+
"version" : "0.1",
21+
"warnings" : "2"
22+
},
23+
"configuration" : {
24+
"analysisGraphs" : "NONE",
25+
"descendingPhaseType" : "NONE",
26+
"dumpForcesUnwinding" : "false",
27+
"fixpointWorkingSet" : "DuplicateFreeFIFOWorkingSet",
28+
"glbThreshold" : "5",
29+
"hotspots" : "unset",
30+
"jsonOutput" : "true",
31+
"openCallPolicy" : "RelaxedOpenCallPolicy",
32+
"optimize" : "false",
33+
"recursionWideningThreshold" : "5",
34+
"semanticChecks" : "CrossChannelInvocationsIssuesChecker",
35+
"serializeInputs" : "false",
36+
"serializeResults" : "false",
37+
"syntacticChecks" : "",
38+
"useWideningPoints" : "true",
39+
"wideningThreshold" : "5",
40+
"workdir" : "go-outputs/hf/cchi/cchi2"
41+
}
42+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/hyperledger/fabric-chaincode-go/shim"
7+
"github.com/hyperledger/fabric-protos-go/peer"
8+
)
9+
10+
type SimpleContract struct {
11+
}
12+
13+
func (t *SimpleContract) Invoke(stub shim.ChaincodeStubInterface) peer.Response {
14+
15+
f, args := stub.GetFunctionAndParameters()
16+
17+
channel := "channelA"
18+
if string(args[0]) == "planB" {
19+
channel = "channelB" // control flow dependency
20+
}
21+
22+
resp := stub.InvokeChaincode("contract", []byte("10"), channel) // KO: different channels can be choosen at runtime
23+
24+
return shim.Success([]byte("Hello!"))
25+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"warnings" : [ {
3+
"message" : "['go-testcases/hf/cchi/cchi3/cchi3.go':22:63] on 'untyped SimpleContract::Invoke(*SimpleContract t, shim.ChaincodeStubInterface stub)': [EXPRESSION] Detected possible cross-channel invocation. It may lead to a lack of transparency because no new transactions are created during the invocation."
4+
}, {
5+
"message" : "['go-testcases/hf/cchi/cchi3/cchi3.go':22:63] on 'untyped SimpleContract::Invoke(*SimpleContract t, shim.ChaincodeStubInterface stub)': [EXPRESSION] Detected possible cross-channel invocation. It may lead to uncommited write operations during the execution of callee chaincode."
6+
} ],
7+
"files" : [ "report.json" ],
8+
"info" : {
9+
"cfgs" : "1",
10+
"duration" : "30ms",
11+
"end" : "2025-02-21T10:30:08.315+01:00",
12+
"expressions" : "23",
13+
"files" : "0",
14+
"globals" : "6",
15+
"members" : "43",
16+
"programs" : "1",
17+
"start" : "2025-02-21T10:30:08.285+01:00",
18+
"statements" : "8",
19+
"units" : "10",
20+
"version" : "0.1",
21+
"warnings" : "2"
22+
},
23+
"configuration" : {
24+
"analysisGraphs" : "NONE",
25+
"descendingPhaseType" : "NONE",
26+
"dumpForcesUnwinding" : "false",
27+
"fixpointWorkingSet" : "DuplicateFreeFIFOWorkingSet",
28+
"glbThreshold" : "5",
29+
"hotspots" : "unset",
30+
"jsonOutput" : "true",
31+
"openCallPolicy" : "RelaxedOpenCallPolicy",
32+
"optimize" : "false",
33+
"recursionWideningThreshold" : "5",
34+
"semanticChecks" : "CrossChannelInvocationsIssuesChecker",
35+
"serializeInputs" : "false",
36+
"serializeResults" : "false",
37+
"syntacticChecks" : "",
38+
"useWideningPoints" : "true",
39+
"wideningThreshold" : "5",
40+
"workdir" : "go-outputs/hf/cchi/cchi3"
41+
}
42+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/hyperledger/fabric-chaincode-go/shim"
7+
"github.com/hyperledger/fabric-protos-go/peer"
8+
)
9+
10+
type SimpleContract struct {
11+
}
12+
13+
func (t *SimpleContract) Invoke(stub shim.ChaincodeStubInterface) peer.Response {
14+
15+
f, args := stub.GetFunctionAndParameters()
16+
17+
channel := "channel"
18+
sum := 0
19+
for i := 1; i < int(args[0]); i++ {
20+
channel += "1" // control flow dependency
21+
}
22+
channel += "A"
23+
24+
resp := stub.InvokeChaincode("contract", []byte("10"), channel) // KO: different channels can be choosen at runtime
25+
26+
return shim.Success([]byte("Hello!"))
27+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"warnings" : [ {
3+
"message" : "['go-testcases/hf/cchi/cchi4/cchi4.go':24:63] on 'untyped SimpleContract::Invoke(*SimpleContract t, shim.ChaincodeStubInterface stub)': [EXPRESSION] Detected possible cross-channel invocation. It may lead to a lack of transparency because no new transactions are created during the invocation."
4+
}, {
5+
"message" : "['go-testcases/hf/cchi/cchi4/cchi4.go':24:63] on 'untyped SimpleContract::Invoke(*SimpleContract t, shim.ChaincodeStubInterface stub)': [EXPRESSION] Detected possible cross-channel invocation. It may lead to uncommited write operations during the execution of callee chaincode."
6+
} ],
7+
"files" : [ "report.json" ],
8+
"info" : {
9+
"cfgs" : "1",
10+
"duration" : "149ms",
11+
"end" : "2025-02-21T10:30:08.506+01:00",
12+
"expressions" : "37",
13+
"files" : "0",
14+
"globals" : "6",
15+
"members" : "43",
16+
"programs" : "1",
17+
"start" : "2025-02-21T10:30:08.357+01:00",
18+
"statements" : "12",
19+
"units" : "10",
20+
"version" : "0.1",
21+
"warnings" : "2"
22+
},
23+
"configuration" : {
24+
"analysisGraphs" : "NONE",
25+
"descendingPhaseType" : "NONE",
26+
"dumpForcesUnwinding" : "false",
27+
"fixpointWorkingSet" : "DuplicateFreeFIFOWorkingSet",
28+
"glbThreshold" : "5",
29+
"hotspots" : "unset",
30+
"jsonOutput" : "true",
31+
"openCallPolicy" : "RelaxedOpenCallPolicy",
32+
"optimize" : "false",
33+
"recursionWideningThreshold" : "5",
34+
"semanticChecks" : "CrossChannelInvocationsIssuesChecker",
35+
"serializeInputs" : "false",
36+
"serializeResults" : "false",
37+
"syntacticChecks" : "",
38+
"useWideningPoints" : "true",
39+
"wideningThreshold" : "5",
40+
"workdir" : "go-outputs/hf/cchi/cchi4"
41+
}
42+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/hyperledger/fabric-chaincode-go/shim"
7+
"github.com/hyperledger/fabric-protos-go/peer"
8+
)
9+
10+
type SimpleContract struct {
11+
}
12+
13+
func (t *SimpleContract) Invoke(stub shim.ChaincodeStubInterface) peer.Response {
14+
15+
resp := stub.InvokeChaincode("contract", []byte("10"), "channel1") // KO: there are two InvokeChaincode with different channels
16+
17+
resp := stub.InvokeChaincode("contract", []byte("10"), "channel2")
18+
19+
return shim.Success([]byte("Hello!"))
20+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"warnings" : [ {
3+
"message" : "['go-testcases/hf/cchi/cchi5/cchi5.go':17:66] on 'untyped SimpleContract::Invoke(*SimpleContract t, shim.ChaincodeStubInterface stub)': [EXPRESSION] Detected cross-channel invocations on different channels. The other invocation: 'go-testcases/hf/cchi/cchi5/cchi5.go':15:66. They may lead to a lack of transparency because no new transactions are created during the invocation."
4+
}, {
5+
"message" : "['go-testcases/hf/cchi/cchi5/cchi5.go':17:66] on 'untyped SimpleContract::Invoke(*SimpleContract t, shim.ChaincodeStubInterface stub)': [EXPRESSION] Detected cross-channel invocations on different channels. The other invocation: 'go-testcases/hf/cchi/cchi5/cchi5.go':15:66. They may lead to uncommited write operations during the execution of callee chaincode."
6+
} ],
7+
"files" : [ "report.json" ],
8+
"info" : {
9+
"cfgs" : "1",
10+
"duration" : "7ms",
11+
"end" : "2025-02-21T10:30:08.538+01:00",
12+
"expressions" : "17",
13+
"files" : "0",
14+
"globals" : "6",
15+
"members" : "43",
16+
"programs" : "1",
17+
"start" : "2025-02-21T10:30:08.531+01:00",
18+
"statements" : "3",
19+
"units" : "10",
20+
"version" : "0.1",
21+
"warnings" : "2"
22+
},
23+
"configuration" : {
24+
"analysisGraphs" : "NONE",
25+
"descendingPhaseType" : "NONE",
26+
"dumpForcesUnwinding" : "false",
27+
"fixpointWorkingSet" : "DuplicateFreeFIFOWorkingSet",
28+
"glbThreshold" : "5",
29+
"hotspots" : "unset",
30+
"jsonOutput" : "true",
31+
"openCallPolicy" : "RelaxedOpenCallPolicy",
32+
"optimize" : "false",
33+
"recursionWideningThreshold" : "5",
34+
"semanticChecks" : "CrossChannelInvocationsIssuesChecker",
35+
"serializeInputs" : "false",
36+
"serializeResults" : "false",
37+
"syntacticChecks" : "",
38+
"useWideningPoints" : "true",
39+
"wideningThreshold" : "5",
40+
"workdir" : "go-outputs/hf/cchi/cchi5"
41+
}
42+
}

0 commit comments

Comments
 (0)