Skip to content
Snippets Groups Projects
Unverified Commit 94f21e79 authored by Silas Davis's avatar Silas Davis
Browse files

use last 20 bytes of sha3 hash for address

parent 4ecc033f
No related branches found
No related tags found
No related merge requests found
......@@ -247,11 +247,12 @@ func (contract *SNativeContractDescription) Dispatch(appState AppState,
return function.F(appState, caller, remainingArgs, gas)
}
// We define the address of an SNative contact as the first 20 bytes of the sha3
// We define the address of an SNative contact as the last 20 bytes of the sha3
// hash of its name
func (contract *SNativeContractDescription) Address() abi.Address {
var address abi.Address
copy(address[:], sha3.Sha3([]byte(contract.Name))[:abi.AddressLength])
hash := sha3.Sha3([]byte(contract.Name))
copy(address[:], hash[len(hash)-abi.AddressLength:])
return address
}
......
......@@ -97,7 +97,7 @@ func TestSNativeContractDescription_Dispatch(t *testing.T) {
func TestSNativeContractDescription_Address(t *testing.T) {
contract := NewSNativeContract("A comment",
"CoolButVeryLongNamedContractOfDoom")
assert.Equal(t, sha3.Sha3(([]byte)(contract.Name))[:20], contract.AddressBytes())
assert.Equal(t, sha3.Sha3(([]byte)(contract.Name))[12:], contract.AddressBytes())
}
//
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment