diff --git a/Makefile b/Makefile index 29bbd1a874f96fb7813e15138112d522399992d6..53fd84ee4616b39e8191b8ed818f02e83f8981d2 100644 --- a/Makefile +++ b/Makefile @@ -73,6 +73,11 @@ hell: go build -o ${REPO}/target/hell ./util/hell/cmd/hell/main.go ./target/hell $(filter-out $@,$(MAKECMDGOALS)) +# Dumps Solidity interface contracts for SNatives +.PHONY: snatives +snatives: + @go run ./util/snatives/main.go + ### Building github.com/eris-ltd/eris-db # build all targets in github.com/eris-ltd/eris-db diff --git a/manager/eris-mint/evm/native.go b/manager/eris-mint/evm/native.go index ab9e0c9720ee40c14f30f788cdd86bd03f5609dc..7470ee32ca5832e9ae2b87d386bc5b50cd83add0 100644 --- a/manager/eris-mint/evm/native.go +++ b/manager/eris-mint/evm/native.go @@ -40,7 +40,8 @@ func registerNativeContracts() { type NativeContract func(appState AppState, caller *Account, input []byte, gas *int64) (output []byte, err error) -type FuncID [4]byte +const FuncIDLength = 4 +type FuncID [FuncIDLength]byte /* Removed due to C dependency func ecrecoverFunc(appState AppState, caller *Account, input []byte, gas *int64) (output []byte, err error) { diff --git a/manager/eris-mint/evm/snative.go b/manager/eris-mint/evm/snative.go index c107804c2a12d14f0e5ef26ee4f04c94416c5ef0..a9829919a1391687f9e4bf4c2045dc8e94e91359 100644 --- a/manager/eris-mint/evm/snative.go +++ b/manager/eris-mint/evm/snative.go @@ -201,7 +201,7 @@ func NewSNativeContract(comment, name string, functions ...SNativeFuncDescriptio func (contract *SNativeContractDescription) Dispatch(appState AppState, caller *Account, args []byte, gas *int64) (output []byte, err error) { - if len(args) < 4 { + if len(args) < FuncIDLength { return Zero256.Bytes(), fmt.Errorf("SNatives dispatch requires a 4-byte function "+ "identifier but arguments are only %s bytes long", len(args)) } @@ -211,7 +211,7 @@ func (contract *SNativeContractDescription) Dispatch(appState AppState, return Zero256.Bytes(), err } - remainingArgs := args[4:] + remainingArgs := args[FuncIDLength:] // check if we have permission to call this function if !HasPermission(appState, caller, function.PermFlag) { @@ -219,7 +219,7 @@ func (contract *SNativeContractDescription) Dispatch(appState AppState, } // ensure there are enough arguments - if len(remainingArgs) != function.NArgs()*32 { + if len(remainingArgs) != function.NArgs()*Word256Length { return Zero256.Bytes(), fmt.Errorf("%s() takes %d arguments", function.Name, function.NArgs()) } diff --git a/manager/eris-mint/evm/snative_test.go b/manager/eris-mint/evm/snative_test.go index b04aefdaca3f9a97826934714f2b5a5d48acd280..65a94f7b5f130e583ac98ca439bd5f4241c0f6d8 100644 --- a/manager/eris-mint/evm/snative_test.go +++ b/manager/eris-mint/evm/snative_test.go @@ -9,15 +9,16 @@ import ( ) /* Compiling the Permissions solidity contract at +(generated by Solidity() function) https://ethereum.github.io/browser-solidity yields: 3fbf7da5 add_role(address,bytes32) -bb37737a has_base(address,int256) +744f5998 has_base(address,uint64) e8145855 has_role(address,bytes32) 28fd0194 rm_role(address,bytes32) -9ea53314 set_base(address,int256,bool) -d69186a6 set_global(int256,bool) -180d26f2 unset_base(address,int256) +3f0ebb30 set_base(address,uint64,uint64) +67dc6f70 set_global(address,uint64,uint64) +73448c99 unset_base(address,uint64) */ func TestPermissionsContract(t *testing.T) { @@ -27,23 +28,23 @@ func TestPermissionsContract(t *testing.T) { assertContractFunction(t, contract, "3fbf7da5", "add_role(address,bytes32)") - assertContractFunction(t, contract, "bb37737a", - "has_base(address,int256)") + assertContractFunction(t, contract, "744f5998", + "has_base(address,uint64)") - assertContractFunction(t, contract, "054556ac", + assertContractFunction(t, contract, "e8145855", "has_role(address,bytes32)") - assertContractFunction(t, contract, "ded3350a", + assertContractFunction(t, contract, "28fd0194", "rm_role(address,bytes32)") - assertContractFunction(t, contract, "c2174d8f", - "set_base(address,int256,bool)") + assertContractFunction(t, contract, "3f0ebb30", + "set_base(address,uint64,uint64)") - assertContractFunction(t, contract, "85f1522b", - "set_global(int256,bool)") + assertContractFunction(t, contract, "67dc6f70", + "set_global(address,uint64,uint64)") assertContractFunction(t, contract, "73448c99", - "unset_base(address,int256)") + "unset_base(address,uint64)") } func TestSNativeFuncTemplate(t *testing.T) { diff --git a/util/snatives/main.go b/util/snatives/main.go new file mode 100644 index 0000000000000000000000000000000000000000..e15d26ffca708a58e9744235e8cc02ae25b83d1c --- /dev/null +++ b/util/snatives/main.go @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" + + "github.com/eris-ltd/eris-db/manager/eris-mint/evm" +) + +// Dump SNative contracts +func main() { + for _, contract := range vm.SNativeContracts() { + solidity, err := contract.Solidity() + if err != nil { + fmt.Printf("Error generating solidity for contract %s: %s\n", + contract.Name, err) + } + fmt.Println(solidity) + } +} diff --git a/word256/word.go b/word256/word.go index 2537830ebea8f46cb71ecd56d112f94e9aa8df6a..9dfe7a673121bf544b4d3a81e03eb1f94039e548 100644 --- a/word256/word.go +++ b/word256/word.go @@ -30,7 +30,8 @@ var ( One256 = Word256{1} ) -type Word256 [32]byte +const Word256Length = 32 +type Word256 [Word256Length]byte func (w Word256) String() string { return string(w[:]) } func (w Word256) TrimmedString() string { return TrimmedString(w.Bytes()) }