Skip to content

Commit

Permalink
Merge pull request ethereum#292 from OffchainLabs/postfix-signatures
Browse files Browse the repository at this point in the history
Postfix duplicate solidity function bindings with 4 byte signature
  • Loading branch information
joshuacolvin0 authored Mar 25, 2024
2 parents 58a1245 + 6f0a9e7 commit 22399a7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
22 changes: 21 additions & 1 deletion accounts/abi/bind/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ func isKeyWord(arg string) bool {
return true
}

func duplicates(methods map[string]abi.Method) map[string]bool {
var (
identifiers = make(map[string]bool)
dups = make(map[string]bool)
)
for _, method := range methods {
identifiers, dups := identifiers, dups
if identifiers[method.RawName] {
dups[method.RawName] = true
}
identifiers[method.RawName] = true
}
return dups
}

// Bind generates a Go wrapper around a contract ABI. This wrapper isn't meant
// to be used as is in client code, but rather as an intermediate struct which
// enforces compile time type safety and naming convention opposed to having to
Expand Down Expand Up @@ -121,6 +136,7 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
callIdentifiers = make(map[string]bool)
transactIdentifiers = make(map[string]bool)
eventIdentifiers = make(map[string]bool)
dups = duplicates(evmABI.Methods)
)

for _, input := range evmABI.Constructor.Inputs {
Expand All @@ -132,12 +148,16 @@ func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]
for _, original := range evmABI.Methods {
// Normalize the method for capital cases and non-anonymous inputs/outputs
normalized := original
normalizedName := methodNormalizer[lang](alias(aliases, original.Name))
// Ensure there is no duplicated identifier
var identifiers = callIdentifiers
if !original.IsConstant() {
identifiers = transactIdentifiers
}
name := original.RawName
if dups[original.RawName] {
name = fmt.Sprintf("%s%x", original.RawName, original.ID)
}
normalizedName := methodNormalizer[lang](alias(aliases, name))
// Name shouldn't start with a digit. It will make the generated code invalid.
if len(normalizedName) > 0 && unicode.IsDigit(rune(normalizedName[0])) {
normalizedName = fmt.Sprintf("M%s", normalizedName)
Expand Down
4 changes: 2 additions & 2 deletions accounts/abi/bind/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1486,7 +1486,7 @@ var bindTests = []struct {
}
}
}()
contract.Foo(auth, big.NewInt(1), big.NewInt(2))
contract.Foo04bc52f8(auth, big.NewInt(1), big.NewInt(2))
sim.Commit()
select {
case n := <-resCh:
Expand All @@ -1497,7 +1497,7 @@ var bindTests = []struct {
t.Fatalf("Wait bar0 event timeout")
}
contract.Foo0(auth, big.NewInt(1))
contract.Foo2fbebd38(auth, big.NewInt(1))
sim.Commit()
select {
case n := <-resCh:
Expand Down

0 comments on commit 22399a7

Please sign in to comment.