Skip to content

Commit 31fc552

Browse files
committed
fix: exposed vars security issue
1 parent 561610f commit 31fc552

File tree

7 files changed

+131
-127
lines changed

7 files changed

+131
-127
lines changed

packages/r/intermarch3/goo/court.gno

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,57 +13,57 @@ import (
1313
)
1414

1515
var (
16-
Disputes = avl.NewTree()
17-
DisputeDuration = 2 * int64(time.Minute.Seconds())
18-
RevealDuration = 2 * int64(time.Minute.Seconds())
19-
VoteTokenPrice = 1 * int64(1_000_000) // in GNOT
16+
disputes = avl.NewTree()
17+
disputeDuration = 2 * int64(time.Minute.Seconds())
18+
revealDuration = 2 * int64(time.Minute.Seconds())
19+
voteTokenPrice = 1 * int64(1_000_000) // in GNOT
2020
VoteToken = newOOToken("Gno Optimistic Oracle Token", "goot", 6)
2121
)
2222

2323
func initiateDispute(id string) {
24-
if _, exists := Disputes.Get(id); exists {
24+
if _, exists := disputes.Get(id); exists {
2525
panic("error: Dispute for this request already exists.")
2626
}
2727
dispute := Dispute{
2828
RequestId: id,
2929
Votes: []Vote{},
3030
Voters: avl.NewTree(),
3131
IsResolved: false,
32-
EndTime: time.Now().Add(time.Duration(DisputeDuration) * time.Second),
33-
EndRevealTime: time.Now().Add(time.Duration(DisputeDuration+RevealDuration) * time.Second),
32+
EndTime: time.Now().Add(time.Duration(disputeDuration) * time.Second),
33+
EndRevealTime: time.Now().Add(time.Duration(disputeDuration+revealDuration) * time.Second),
3434
}
35-
Disputes.Set(id, dispute)
35+
disputes.Set(id, dispute)
3636
chain.Emit("DisputeInitiated", "id", id)
3737
}
3838

3939
// -- PUBLIC FUNCTIONS --
4040

41-
// BuyInitialVoteToken allows a user to buy their first vote token by sending VoteTokenPrice amount of ugnot.
41+
// BuyInitialVoteToken allows a user to buy their first vote token by sending voteTokenPrice amount of ugnot.
4242
func BuyInitialVoteToken(_ realm) {
4343
caller := runtime.OriginCaller()
4444
coins := banker.OriginSend()
45-
if len(coins) != 1 || coins.AmountOf("ugnot") != VoteTokenPrice {
46-
panic("error: Must send exactly " + strconv.Itoa(int(VoteTokenPrice/1_000_000)) + " gnot to get a vote token.")
45+
if len(coins) != 1 || coins.AmountOf("ugnot") != voteTokenPrice {
46+
panic("error: Must send exactly " + strconv.Itoa(int(voteTokenPrice/1_000_000)) + " gnot to get a vote token.")
4747
}
4848

4949
balance := VoteToken.BalanceOf(caller)
5050
if balance > 0 {
5151
panic("error: You already have a vote token.")
5252
}
5353

54-
VoteToken.Mint(caller, 1)
54+
VoteToken.mint(caller, 1)
5555
chain.Emit("VoteTokenPurchased", "voter", caller.String())
5656
}
5757

5858
// BalanceOfVoteToken returns the number of vote tokens held by the caller.
5959
func BalanceOfVoteToken(_ realm) int64 {
60-
return VoteToken.balanceOf(runtime.PreviousRealm().Address())
60+
return VoteToken.BalanceOf(runtime.PreviousRealm().Address())
6161
}
6262

6363
// VoteOnDispute allows a user to commit a vote during a dispute.
6464
func VoteOnDispute(_ realm, id string, hash string) {
6565
dispute := getDispute(id)
66-
res, _ := Requests.Get(id)
66+
res, _ := requests.Get(id)
6767
request := res.(DataRequest)
6868
if request.Proposer == runtime.PreviousRealm().Address() || request.Disputer == runtime.PreviousRealm().Address() {
6969
panic("error: Proposer and Disputer cannot vote in this dispute.")
@@ -92,7 +92,7 @@ func VoteOnDispute(_ realm, id string, hash string) {
9292
}
9393
dispute.Votes = append(dispute.Votes, vote)
9494
dispute.Voters.Set(string(vote.Voter), Voter{HasVoted: true, VoteIndex: int64(len(dispute.Votes) - 1)})
95-
Disputes.Set(id, dispute)
95+
disputes.Set(id, dispute)
9696
chain.Emit("VoteSubmitted", "id", id, "voter", vote.Voter.String())
9797
}
9898

@@ -127,7 +127,7 @@ func RevealVote(_ realm, id string, value int64, salt string) {
127127
vote.Revealed = true
128128
dispute.NbResolvedVotes += 1
129129
dispute.Votes[voter.(Voter).VoteIndex] = vote
130-
Disputes.Set(id, dispute)
130+
disputes.Set(id, dispute)
131131
chain.Emit("VoteRevealed", "id", id, "voter", vote.Voter.String(), "value", strconv.Itoa(int(value)))
132132
}
133133

@@ -143,13 +143,13 @@ func ResolveDispute(_ realm, id string) {
143143
val := resolve(id)
144144
dispute.WinningValue = val
145145
dispute.IsResolved = true
146-
Disputes.Set(id, dispute)
146+
disputes.Set(id, dispute)
147147
// Update the original request with the winning value
148148
request := getRequest(id)
149149

150150
request.ProposedValue = val
151151
request.State = "Resolved"
152-
Requests.Set(id, request)
152+
requests.Set(id, request)
153153
chain.Emit("DisputeResolved", "id", id, "winningValue", strconv.Itoa(int(val)))
154154
chain.Emit("RequestResolved", "id", id, "winningValue", strconv.Itoa(int(val)))
155155

@@ -161,15 +161,15 @@ func ResolveDispute(_ realm, id string) {
161161
// Refund + reward the proposer if the dispute did not change the value
162162
winner = request.Proposer
163163
}
164-
Bank.SendCoins(runtime.CurrentRealm().Address(), winner, chain.Coins{chain.Coin{Denom: "ugnot", Amount: Bond + RequesterReward}})
164+
bank.SendCoins(runtime.CurrentRealm().Address(), winner, chain.Coins{chain.Coin{Denom: "ugnot", Amount: bond + requesterReward}})
165165
}
166166

167167
// -- admin functions --
168168

169169
// SetDisputeDuration sets the duration (in seconds) for the voting period.
170170
func SetDisputeDuration(_ realm, duration int64) {
171171
if runtime.OriginCaller() == admin {
172-
DisputeDuration = duration * int64(time.Second)
172+
disputeDuration = duration * int64(time.Second)
173173
} else {
174174
panic("error: Only admin can set dispute duration.")
175175
}
@@ -178,7 +178,7 @@ func SetDisputeDuration(_ realm, duration int64) {
178178
// SetRevealDuration sets the duration (in seconds) for the reveal period.
179179
func SetRevealDuration(_ realm, duration int64) {
180180
if runtime.OriginCaller() == admin {
181-
RevealDuration = duration * int64(time.Second)
181+
revealDuration = duration * int64(time.Second)
182182
} else {
183183
panic("error: Only admin can set reveal duration.")
184184
}
@@ -187,7 +187,7 @@ func SetRevealDuration(_ realm, duration int64) {
187187
// SetVoteTokenPrice sets the price (in ugnot) to cast a vote.
188188
func SetVoteTokenPrice(_ realm, price int64) {
189189
if runtime.OriginCaller() == admin {
190-
VoteTokenPrice = price
190+
voteTokenPrice = price
191191
} else {
192192
panic("error: Only admin can set vote price.")
193193
}
@@ -202,12 +202,12 @@ func GetDispute(_ realm, id string) Dispute {
202202

203203
// GetDisputeDuration returns the current dispute duration.
204204
func GetDisputeDuration(_ realm) int64 {
205-
return DisputeDuration
205+
return disputeDuration
206206
}
207207

208208
// GetVoteTokenPrice returns the current vote price.
209209
func GetVoteTokenPrice(_ realm) int64 {
210-
return VoteTokenPrice
210+
return voteTokenPrice
211211
}
212212

213213
// GetDisputeEndTime returns the end time of the voting period for a specific dispute.
@@ -230,13 +230,13 @@ func GetRevealEndTime(_ realm, id string) time.Time {
230230

231231
// GetRevealDuration returns the current reveal duration.
232232
func GetRevealDuration(_ realm) int64 {
233-
return RevealDuration
233+
return revealDuration
234234
}
235235

236236
// Utils functions
237237

238238
func getDispute(id string) Dispute {
239-
dispute, exists := Disputes.Get(id)
239+
dispute, exists := disputes.Get(id)
240240
if !exists {
241241
panic("error: Dispute with this ID does not exist.")
242242
}

packages/r/intermarch3/goo/court_test.gno

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ var user4 = testutils.TestAddress("user4")
1414

1515
func TestBuyInitialVoteToken(t *testing.T) {
1616
testing.SetRealm(testing.NewUserRealm(user1))
17-
urequire.AbortsWithMessage(t, "error: Must send exactly "+strconv.Itoa(int(VoteTokenPrice/1_000_000))+" gnot to get a vote token.", func() {
17+
urequire.AbortsWithMessage(t, "error: Must send exactly "+strconv.Itoa(int(voteTokenPrice/1_000_000))+" gnot to get a vote token.", func() {
1818
BuyInitialVoteToken(cross)
1919
}, "user should not be able to buy a vote token without sending the correct amount")
2020

2121
testing.SetRealm(testing.NewUserRealm(user1))
22-
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: VoteTokenPrice}})
22+
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: voteTokenPrice}})
2323
urequire.NotPanics(t, func() {
2424
BuyInitialVoteToken(cross)
2525
}, "user should be able to buy a vote token by sending the correct amount")
2626
amount := BalanceOfVoteToken(cross)
2727
urequire.Equal(t, int64(1), amount, "user should have received a vote token")
2828

2929
testing.SetRealm(testing.NewUserRealm(user1))
30-
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: VoteTokenPrice}})
30+
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: voteTokenPrice}})
3131
urequire.AbortsWithMessage(t, "error: You already have a vote token.", func() {
3232
BuyInitialVoteToken(cross)
3333
}, "user should not be able to buy a second vote token")
@@ -36,20 +36,20 @@ func TestBuyInitialVoteToken(t *testing.T) {
3636
func TestVoteOnDispute(t *testing.T) {
3737
// setup: create request and dispute
3838
testing.SetRealm(testing.NewUserRealm(user1))
39-
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: RequesterReward}})
39+
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: requesterReward}})
4040
id := RequestData(cross, "test", true, time.Now().Add(24*time.Hour).Unix())
4141

4242
testing.SetRealm(testing.NewUserRealm(user1))
43-
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: Bond}})
43+
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: bond}})
4444
ProposeValue(cross, id, 0)
4545

4646
testing.SetRealm(testing.NewUserRealm(user2))
47-
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: Bond}})
47+
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: bond}})
4848
DisputeData(cross, id)
4949

5050
// buy vote token
5151
testing.SetRealm(testing.NewUserRealm(user3))
52-
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: VoteTokenPrice}})
52+
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: voteTokenPrice}})
5353
BuyInitialVoteToken(cross)
5454

5555
// vote on dispute
@@ -74,7 +74,7 @@ func TestVoteOnDispute(t *testing.T) {
7474
}, "user should not be able to vote on dispute if they have already voted")
7575

7676
testing.SetRealm(testing.NewUserRealm(user4))
77-
setTime(time.Now().Add(time.Duration(DisputeDuration)*time.Second + time.Second))
77+
setTime(time.Now().Add(time.Duration(disputeDuration)*time.Second + time.Second))
7878
urequire.AbortsWithMessage(t, "error: Vote period has ended.", func() {
7979
VoteOnDispute(cross, id, "hash")
8080
}, "user should not be able to vote on dispute after the voting period has ended")
@@ -83,23 +83,23 @@ func TestVoteOnDispute(t *testing.T) {
8383
func TestRevealVote(t *testing.T) {
8484
// setup: create request and dispute
8585
testing.SetRealm(testing.NewUserRealm(user1))
86-
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: RequesterReward}})
86+
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: requesterReward}})
8787
id := RequestData(cross, "test", true, time.Now().Add(24*time.Hour).Unix())
8888

8989
testing.SetRealm(testing.NewUserRealm(user1))
90-
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: Bond}})
90+
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: bond}})
9191
ProposeValue(cross, id, 0)
9292

9393
testing.SetRealm(testing.NewUserRealm(user2))
94-
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: Bond}})
94+
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: bond}})
9595
DisputeData(cross, id)
9696

9797
// vote on dispute
9898
testing.SetRealm(testing.NewUserRealm(user3))
9999
VoteOnDispute(cross, id, "a96e0beb59a16b085a7d2b3b5ffd6e5971870aa2903c6df86f26fa908ded2e21")
100100

101101
testing.SetRealm(testing.NewUserRealm(user3))
102-
setTime(time.Now().Add(time.Duration(DisputeDuration)*time.Second + time.Second))
102+
setTime(time.Now().Add(time.Duration(disputeDuration)*time.Second + time.Second))
103103
urequire.AbortsWithMessage(t, "error: Hash does not match the revealed value and salt.", func() {
104104
RevealVote(cross, id, 1, "mysalt")
105105
}, "vote reveal with incorrect value and salt should fail")
@@ -119,25 +119,25 @@ func TestRevealVote(t *testing.T) {
119119
func TestResolveDispute(t *testing.T) {
120120
// setup: create request and dispute
121121
testing.SetRealm(testing.NewUserRealm(user1))
122-
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: RequesterReward}})
122+
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: requesterReward}})
123123
id := RequestData(cross, "test", true, time.Now().Add(24*time.Hour).Unix())
124124

125125
testing.SetRealm(testing.NewUserRealm(user1))
126-
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: Bond}})
126+
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: bond}})
127127
ProposeValue(cross, id, 0)
128128

129129
testing.SetRealm(testing.NewUserRealm(user2))
130-
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: Bond}})
130+
testing.SetOriginSend([]chain.Coin{{Denom: "ugnot", Amount: bond}})
131131
DisputeData(cross, id)
132132

133133
// vote on dispute
134134
testing.SetRealm(testing.NewUserRealm(user3))
135135
VoteOnDispute(cross, id, "a96e0beb59a16b085a7d2b3b5ffd6e5971870aa2903c6df86f26fa908ded2e21")
136-
setTime(time.Now().Add(time.Duration(DisputeDuration)*time.Second + time.Second))
136+
setTime(time.Now().Add(time.Duration(disputeDuration)*time.Second + time.Second))
137137
RevealVote(cross, id, 0, "test")
138138

139-
setTime(time.Now().Add(time.Duration(RevealDuration)*time.Second + time.Second))
140-
CreateGnotCoins(cross, (Bond*2)+RequesterReward)
139+
setTime(time.Now().Add(time.Duration(revealDuration)*time.Second + time.Second))
140+
CreateGnotCoins(cross, (bond*2)+requesterReward)
141141
urequire.NotPanics(t, func() {
142142
ResolveDispute(cross, id)
143143
}, "user should be able to resolve dispute after the reveal period has ended")

0 commit comments

Comments
 (0)