Skip to content

Commit 9bb5eff

Browse files
committed
Added support for the instruction GetChannelID
1 parent ad06d2b commit 9bb5eff

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package it.unive.golisa.cfg.runtime.shim.method;
2+
3+
import it.unive.golisa.analysis.taint.TaintDomain;
4+
import it.unive.golisa.cfg.runtime.shim.type.ChaincodeStub;
5+
import it.unive.golisa.cfg.type.GoStringType;
6+
import it.unive.lisa.analysis.AbstractState;
7+
import it.unive.lisa.analysis.AnalysisState;
8+
import it.unive.lisa.analysis.SemanticException;
9+
import it.unive.lisa.analysis.StatementStore;
10+
import it.unive.lisa.analysis.lattices.ExpressionSet;
11+
import it.unive.lisa.interprocedural.InterproceduralAnalysis;
12+
import it.unive.lisa.program.CompilationUnit;
13+
import it.unive.lisa.program.annotations.Annotations;
14+
import it.unive.lisa.program.cfg.CFG;
15+
import it.unive.lisa.program.cfg.CodeLocation;
16+
import it.unive.lisa.program.cfg.CodeMemberDescriptor;
17+
import it.unive.lisa.program.cfg.NativeCFG;
18+
import it.unive.lisa.program.cfg.Parameter;
19+
import it.unive.lisa.program.cfg.statement.Expression;
20+
import it.unive.lisa.program.cfg.statement.NaryExpression;
21+
import it.unive.lisa.program.cfg.statement.PluggableStatement;
22+
import it.unive.lisa.program.cfg.statement.Statement;
23+
import it.unive.lisa.symbolic.value.Constant;
24+
/**
25+
* func (s *ChaincodeStub) GetChannelID() string
26+
*
27+
* @link https://pkg.go.dev/github.com/hyperledger/fabric-chaincode-go/shim#ChaincodeStub.GetChannelID
28+
*
29+
* @author <a href="mailto:[email protected]">Luca Olivieri</a>
30+
*/
31+
public class GetChannelID extends NativeCFG {
32+
33+
private final static Annotations anns = new Annotations(TaintDomain.CLEAN_ANNOTATION);
34+
35+
/**
36+
* Builds the native cfg.
37+
*
38+
* @param location the location where this native cfg is defined
39+
* @param shimUnit the unit to which this native cfg belongs to
40+
*/
41+
public GetChannelID(CodeLocation location, CompilationUnit shimUnit) {
42+
super(new CodeMemberDescriptor(location, shimUnit, true, "GetChannelID",
43+
GoStringType.INSTANCE, anns,
44+
new Parameter(location, "s", ChaincodeStub.getChaincodeStubType(shimUnit.getProgram()))),
45+
GetChannelIDImpl.class);
46+
}
47+
48+
/**
49+
* The {@link GetChannelID} implementation.
50+
*
51+
* @author <a href="mailto:[email protected]">Luca Olivieri</a>
52+
*/
53+
public static class GetChannelIDImpl extends NaryExpression
54+
implements PluggableStatement {
55+
56+
private Statement original;
57+
58+
@Override
59+
public void setOriginatingStatement(Statement st) {
60+
original = st;
61+
}
62+
63+
@Override
64+
protected int compareSameClassAndParams(Statement o) {
65+
return 0; // nothing else to compare
66+
}
67+
68+
/**
69+
* Builds the pluggable statement.
70+
*
71+
* @param cfg the {@link CFG} where this pluggable statement lies
72+
* @param location the location where this pluggable statement is
73+
* defined
74+
* @param params the parameters
75+
*
76+
* @return the pluggable statement
77+
*/
78+
public static GetChannelIDImpl build(CFG cfg, CodeLocation location, Expression... params) {
79+
return new GetChannelIDImpl(cfg, location, params);
80+
}
81+
82+
/**
83+
* Builds the pluggable statement.
84+
*
85+
* @param cfg the {@link CFG} where this pluggable statement lies
86+
* @param location the location where this pluggable statement is
87+
* defined
88+
* @param params the parameters
89+
*/
90+
public GetChannelIDImpl(CFG cfg, CodeLocation location, Expression... params) {
91+
super(cfg, location, "GetChannelIDImpl", GoStringType.INSTANCE, params);
92+
}
93+
94+
@Override
95+
public <A extends AbstractState<A>> AnalysisState<A> forwardSemanticsAux(
96+
InterproceduralAnalysis<A> interprocedural, AnalysisState<A> state,
97+
ExpressionSet[] params, StatementStore<A> expressions)
98+
throws SemanticException {
99+
100+
// https://github.com/hyperledger/fabric-chaincode-go/blob/main/shim/interfaces.go#L73C2-L74C17
101+
// if `channel` is empty string, the caller's channel is assumed.
102+
return state.smallStepSemantics(new Constant(GoStringType.INSTANCE, "", getLocation()), original);
103+
}
104+
}
105+
}

go-lisa/src/main/java/it/unive/golisa/cfg/runtime/shim/type/ChaincodeStub.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import it.unive.golisa.cfg.runtime.shim.method.DelPrivateData;
55
import it.unive.golisa.cfg.runtime.shim.method.DelState;
66
import it.unive.golisa.cfg.runtime.shim.method.GetArgs;
7+
import it.unive.golisa.cfg.runtime.shim.method.GetChannelID;
78
import it.unive.golisa.cfg.runtime.shim.method.GetFunctionAndParameters;
89
import it.unive.golisa.cfg.runtime.shim.method.GetHistoryForKey;
910
import it.unive.golisa.cfg.runtime.shim.method.GetQueryResult;
@@ -108,6 +109,8 @@ public static void registerMethods() {
108109
new GetQueryResult(GoLangUtils.GO_RUNTIME_SOURCECODE_LOCATION, chaincodeStubUnit));
109110
chaincodeStubUnit.addInstanceCodeMember(
110111
new InvokeChaincode(GoLangUtils.GO_RUNTIME_SOURCECODE_LOCATION, chaincodeStubUnit));
112+
chaincodeStubUnit
113+
.addInstanceCodeMember(new GetChannelID(GoLangUtils.GO_RUNTIME_SOURCECODE_LOCATION, chaincodeStubUnit));
111114

112115
}
113116

0 commit comments

Comments
 (0)