Skip to content

Commit 436fc8d

Browse files
committed
all: Rename crypto.Sha3{,Hash}() to crypto.Keccak256{,Hash}()
As we aren't really using the standarized SHA-3
1 parent c20d6e5 commit 436fc8d

48 files changed

Lines changed: 92 additions & 92 deletions

Some content is hidden

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

‎accounts/abi/abi_test.go‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func TestMethodSignature(t *testing.T) {
244244
t.Error("signature mismatch", exp, "!=", m.Sig())
245245
}
246246

247-
idexp := crypto.Sha3([]byte(exp))[:4]
247+
idexp := crypto.Keccak256([]byte(exp))[:4]
248248
if !bytes.Equal(m.Id(), idexp) {
249249
t.Errorf("expected ids to match %x != %x", m.Id(), idexp)
250250
}
@@ -264,7 +264,7 @@ func TestPack(t *testing.T) {
264264
t.FailNow()
265265
}
266266

267-
sig := crypto.Sha3([]byte("foo(uint32)"))[:4]
267+
sig := crypto.Keccak256([]byte("foo(uint32)"))[:4]
268268
sig = append(sig, make([]byte, 32)...)
269269
sig[35] = 10
270270

@@ -286,7 +286,7 @@ func TestMultiPack(t *testing.T) {
286286
t.FailNow()
287287
}
288288

289-
sig := crypto.Sha3([]byte("bar(uint32,uint16)"))[:4]
289+
sig := crypto.Keccak256([]byte("bar(uint32,uint16)"))[:4]
290290
sig = append(sig, make([]byte, 64)...)
291291
sig[35] = 10
292292
sig[67] = 11
@@ -309,7 +309,7 @@ func TestPackSlice(t *testing.T) {
309309
t.FailNow()
310310
}
311311

312-
sig := crypto.Sha3([]byte("slice(uint32[2])"))[:4]
312+
sig := crypto.Keccak256([]byte("slice(uint32[2])"))[:4]
313313
sig = append(sig, make([]byte, 64)...)
314314
sig[35] = 1
315315
sig[67] = 2
@@ -332,7 +332,7 @@ func TestPackSliceBig(t *testing.T) {
332332
t.FailNow()
333333
}
334334

335-
sig := crypto.Sha3([]byte("slice256(uint256[2])"))[:4]
335+
sig := crypto.Keccak256([]byte("slice256(uint256[2])"))[:4]
336336
sig = append(sig, make([]byte, 64)...)
337337
sig[35] = 1
338338
sig[67] = 2

‎accounts/abi/event.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ func (e Event) Id() common.Hash {
4040
types[i] = input.Type.String()
4141
i++
4242
}
43-
return common.BytesToHash(crypto.Sha3([]byte(fmt.Sprintf("%v(%v)", e.Name, strings.Join(types, ",")))))
43+
return common.BytesToHash(crypto.Keccak256([]byte(fmt.Sprintf("%v(%v)", e.Name, strings.Join(types, ",")))))
4444
}

‎accounts/abi/event_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ func TestEventId(t *testing.T) {
1919
{ "type" : "event", "name" : "check", "inputs": [{ "name" : "t", "type": "address" }, { "name": "b", "type": "uint256" }] }
2020
]`,
2121
expectations: map[string]common.Hash{
22-
"balance": crypto.Sha3Hash([]byte("balance(uint256)")),
23-
"check": crypto.Sha3Hash([]byte("check(address,uint256)")),
22+
"balance": crypto.Keccak256Hash([]byte("balance(uint256)")),
23+
"check": crypto.Keccak256Hash([]byte("check(address,uint256)")),
2424
},
2525
},
2626
}

‎accounts/abi/method.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@ func (m Method) String() string {
7272
}
7373

7474
func (m Method) Id() []byte {
75-
return crypto.Sha3([]byte(m.Sig()))[:4]
75+
return crypto.Keccak256([]byte(m.Sig()))[:4]
7676
}

‎cmd/geth/js_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ multiply7 = Multiply7.at(contractaddress);
396396
if sol != nil && solcVersion != sol.Version() {
397397
modContractInfo := versionRE.ReplaceAll(contractInfo, []byte(`"compilerVersion":"`+sol.Version()+`"`))
398398
fmt.Printf("modified contractinfo:\n%s\n", modContractInfo)
399-
contentHash = `"` + common.ToHex(crypto.Sha3([]byte(modContractInfo))) + `"`
399+
contentHash = `"` + common.ToHex(crypto.Keccak256([]byte(modContractInfo))) + `"`
400400
}
401401
if checkEvalJSON(t, repl, `filename = "/tmp/info.json"`, `"/tmp/info.json"`) != nil {
402402
return

‎common/compiler/solidity.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func SaveInfo(info *ContractInfo, filename string) (contenthash common.Hash, err
220220
if err != nil {
221221
return
222222
}
223-
contenthash = common.BytesToHash(crypto.Sha3(infojson))
223+
contenthash = common.BytesToHash(crypto.Keccak256(infojson))
224224
err = ioutil.WriteFile(filename, infojson, 0600)
225225
return
226226
}

‎common/httpclient/httpclient.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (self *HTTPClient) GetAuthContent(uri string, hash common.Hash) ([]byte, er
7474
}
7575

7676
// check hash to authenticate content
77-
chash := crypto.Sha3Hash(content)
77+
chash := crypto.Keccak256Hash(content)
7878
if chash != hash {
7979
return nil, fmt.Errorf("content hash mismatch %x != %x (exp)", hash[:], chash[:])
8080
}

‎common/httpclient/httpclient_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestGetAuthContent(t *testing.T) {
3636
client := New(dir)
3737

3838
text := "test"
39-
hash := crypto.Sha3Hash([]byte(text))
39+
hash := crypto.Keccak256Hash([]byte(text))
4040
if err := ioutil.WriteFile(path.Join(dir, "test.content"), []byte(text), os.ModePerm); err != nil {
4141
t.Fatal("could not write test file", err)
4242
}

‎common/natspec/natspec.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func FetchDocsForContract(contractAddress string, xeth *xeth.XEth, client *httpc
115115
err = fmt.Errorf("contract (%v) not found", contractAddress)
116116
return
117117
}
118-
codehash := common.BytesToHash(crypto.Sha3(codeb))
118+
codehash := common.BytesToHash(crypto.Keccak256(codeb))
119119
// set up nameresolver with natspecreg + urlhint contract addresses
120120
reg := registrar.New(xeth)
121121

@@ -197,7 +197,7 @@ type userDoc struct {
197197
func (self *NatSpec) makeAbi2method(abiKey [8]byte) (meth *method) {
198198
for signature, m := range self.userDoc.Methods {
199199
name := strings.Split(signature, "(")[0]
200-
hash := []byte(common.Bytes2Hex(crypto.Sha3([]byte(signature))))
200+
hash := []byte(common.Bytes2Hex(crypto.Keccak256([]byte(signature))))
201201
var key [8]byte
202202
copy(key[:], hash[:8])
203203
if bytes.Equal(key[:], abiKey[:]) {

‎common/natspec/natspec_e2e_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,11 @@ func TestNatspecE2E(t *testing.T) {
238238
// create a contractInfo file (mock cloud-deployed contract metadocs)
239239
// incidentally this is the info for the HashReg contract itself
240240
ioutil.WriteFile("/tmp/"+testFileName, []byte(testContractInfo), os.ModePerm)
241-
dochash := crypto.Sha3Hash([]byte(testContractInfo))
241+
dochash := crypto.Keccak256Hash([]byte(testContractInfo))
242242

243243
// take the codehash for the contract we wanna test
244244
codeb := tf.xeth.CodeAtBytes(registrar.HashRegAddr)
245-
codehash := crypto.Sha3Hash(codeb)
245+
codehash := crypto.Keccak256Hash(codeb)
246246

247247
reg := registrar.New(tf.xeth)
248248
_, err := reg.SetHashToHash(addr, codehash, dochash)

0 commit comments

Comments
 (0)