From 94f21e7999ac83b9c12a6fc77c1a05c537c755e8 Mon Sep 17 00:00:00 2001 From: Silas Davis <silas@erisindustries.com> Date: Thu, 23 Feb 2017 16:41:49 +0000 Subject: [PATCH] use last 20 bytes of sha3 hash for address --- manager/eris-mint/evm/snative.go | 5 +++-- manager/eris-mint/evm/snative_test.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/manager/eris-mint/evm/snative.go b/manager/eris-mint/evm/snative.go index 73275c7b..92adbf30 100644 --- a/manager/eris-mint/evm/snative.go +++ b/manager/eris-mint/evm/snative.go @@ -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 } diff --git a/manager/eris-mint/evm/snative_test.go b/manager/eris-mint/evm/snative_test.go index a0722251..da0572b4 100644 --- a/manager/eris-mint/evm/snative_test.go +++ b/manager/eris-mint/evm/snative_test.go @@ -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()) } // -- GitLab