Skip to content

Commit 6de773a

Browse files
committed
upload code
1 parent 3662590 commit 6de773a

File tree

131 files changed

+19977
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+19977
-0
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "secp256k1"]
2+
path = secp256k1
3+
url = git@github.com:Troublor/secp256k1.git

.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/erebus-redgiant.iml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

analysis/__test__/basic_storage.sol

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
pragma solidity ^0.8.0;
2+
3+
contract BasicStorage {
4+
uint a;
5+
uint[] b;
6+
mapping(uint => uint) c;
7+
8+
function invoke(uint a_, uint b_, uint ck_, uint cv_) public {
9+
a = a_;
10+
b.push(b_);
11+
c[ck_] = cv_;
12+
}
13+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
let a := sload(0)
3+
let b := sload(1)
4+
5+
if eq(a, 0) {
6+
sstore(2, 0)
7+
}
8+
9+
if eq(b, 1) {
10+
sstore(3, 1)
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
let a := 1
3+
let b := sload(a)
4+
let b2 := add(b, 2)
5+
let c := sload(b2)
6+
mstore(b, c)
7+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
let seed := 9
3+
mstore(0, caller())
4+
mstore(0x20, seed)
5+
let addr := keccak256(0, 0x40)
6+
let sdata := sload(addr)
7+
sstore(1, sdata)
8+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*/
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
3+
pragma solidity ^0.8.0;
4+
5+
contract Contract {
6+
mapping(address => uint) public balances;
7+
8+
event Transfer(address indexed from, address indexed to, uint value);
9+
10+
constructor(uint256 initialSupply) {
11+
balances[msg.sender] = initialSupply;
12+
}
13+
14+
function balanceOf(address account) public view returns (uint balance) {
15+
return balances[account];
16+
}
17+
18+
function transfer(address to, uint amount) public returns (bool success) {
19+
return this.transferFrom(msg.sender, to, amount);
20+
}
21+
22+
function transferFrom(
23+
address from,
24+
address to,
25+
uint amount
26+
) public returns (bool success) {
27+
require(balances[from] >= amount);
28+
balances[from] -= amount;
29+
balances[to] += amount;
30+
emit Transfer(from, to, amount);
31+
return true;
32+
}
33+
34+
function guessWhat(bool guess) public pure {
35+
assert(guess);
36+
}
37+
}

analysis/data_flow/analyzer.go

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package data_flow
2+
3+
type Analyzer interface {
4+
NewFlowNode(operation *Operation) FlowNode
5+
CheckOperation(operation *Operation) (isSource, isSink bool)
6+
SinkTainted(collection *TrackerCollection, flowedValue FlowNode)
7+
FlowPolicy() FlowPolicy
8+
}

analysis/data_flow/call.go

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
package data_flow
2+
3+
import (
4+
"github.com/Troublor/erebus-redgiant/dyengine/tracers"
5+
)
6+
7+
type call struct {
8+
position tracers.CallPosition
9+
10+
value FlowNode
11+
data map[uint64]FlowNode
12+
13+
returnData map[uint64]FlowNode
14+
success FlowNode
15+
16+
source FlowNode
17+
}
18+
19+
func newCall(pos tracers.CallPosition) *call {
20+
return &call{
21+
position: pos,
22+
data: make(map[uint64]FlowNode),
23+
returnData: make(map[uint64]FlowNode),
24+
}
25+
}
26+
27+
func (c *call) setFlowSource(source FlowNode) {
28+
c.source = source
29+
}
30+
31+
func (c *call) matchMsgCall(msgCall *tracers.MsgCall[*Data]) bool {
32+
return c.position.Cmp(msgCall.Position) == 0
33+
}
34+
35+
func (c *call) StoreData(memory *memory, offset, length uint64) {
36+
if length == 0 {
37+
return
38+
}
39+
start := memoryGranularity.Regulate(offset)
40+
for i := uint64(0); start+i < offset+length; i += memoryGranularity.Uint64() {
41+
c.data[i] = memory.mem[start+i]
42+
}
43+
}
44+
45+
func (c *call) StoreReturnData(memory *memory, offset, length uint64) {
46+
if length == 0 {
47+
return
48+
}
49+
start := memoryGranularity.Regulate(offset)
50+
for i := uint64(0); start+i < offset+length; i += memoryGranularity.Uint64() {
51+
c.returnData[i] = memory.mem[start+i]
52+
}
53+
}
54+
55+
func (c *call) GetData(start, length uint64) FlowNodeList {
56+
if length == 0 {
57+
return nil
58+
}
59+
var values FlowNodeList
60+
for i := memoryGranularity.Regulate(start); i < start+length; i += memoryGranularity.Uint64() {
61+
v := c.data[i]
62+
if v != UntaintedValue {
63+
values = append(values, v)
64+
}
65+
}
66+
if len(values) == 0 && c.source != nil {
67+
values = append(values, c.source)
68+
}
69+
return values
70+
}
71+
72+
func (c *call) GetValue() FlowNode {
73+
return c.value
74+
}
75+
76+
func (c *call) GetSuccess() FlowNode {
77+
if c.success != UntaintedValue {
78+
return c.success
79+
} else if c.source != nil {
80+
return c.source
81+
} else {
82+
return c.success
83+
}
84+
}
85+
86+
func (c *call) GetReturnData(start, length uint64) FlowNodeList {
87+
if length == 0 {
88+
return nil
89+
}
90+
var values FlowNodeList
91+
for i := memoryGranularity.Regulate(start); i < start+length; i += memoryGranularity.Uint64() {
92+
v := c.returnData[i]
93+
if v != UntaintedValue {
94+
values = append(values, v)
95+
}
96+
}
97+
if len(values) == 0 && c.source != nil {
98+
values = append(values, c.source)
99+
}
100+
return values
101+
}
102+
103+
func (c *call) GetAllReturnData() FlowNodeList {
104+
var values FlowNodeList
105+
for _, v := range c.returnData {
106+
if v != UntaintedValue {
107+
values = append(values, v)
108+
}
109+
}
110+
if len(values) == 0 && c.source != nil {
111+
values = append(values, c.source)
112+
}
113+
return values
114+
}
115+
116+
func (c *call) ReturnDataIsTainted(analyzer Analyzer) bool {
117+
for _, node := range c.returnData {
118+
if node != UntaintedValue && node.From().IsTainted() {
119+
return true
120+
}
121+
}
122+
return false
123+
}

analysis/data_flow/chain.go

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package data_flow
2+
3+
import (
4+
"github.com/ethereum/go-ethereum/common"
5+
)
6+
7+
type chain struct {
8+
balances map[common.Address]FlowNode
9+
codes map[common.Address]FlowNode
10+
}
11+
12+
func newChain() *chain {
13+
return &chain{
14+
balances: make(map[common.Address]FlowNode),
15+
codes: make(map[common.Address]FlowNode),
16+
}
17+
}
18+
19+
func (c *chain) GetBalance(addr common.Address) FlowNode {
20+
return c.balances[addr]
21+
}
22+
23+
func (c *chain) SetBalance(addr common.Address, node FlowNode) {
24+
c.balances[addr] = node
25+
}
26+
27+
func (c *chain) GetCode(addr common.Address) FlowNode {
28+
return c.codes[addr]
29+
}
30+
31+
func (c *chain) SetCode(addr common.Address, node FlowNode) {
32+
c.codes[addr] = node
33+
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package data_flow_test
2+
3+
import (
4+
"testing"
5+
6+
. "github.com/onsi/ginkgo/v2"
7+
. "github.com/onsi/gomega"
8+
)
9+
10+
func TestDataFlow(t *testing.T) {
11+
RegisterFailHandler(Fail)
12+
RunSpecs(t, "DataFlow Suite")
13+
}

0 commit comments

Comments
 (0)