Skip to content

Commit

Permalink
Merge pull request #152 from kaleido-io/constructor-abi
Browse files Browse the repository at this point in the history
Remove ABI validation of domain constructor args
  • Loading branch information
jimthematrix authored Sep 12, 2024
2 parents f867339 + ffe0c60 commit 8d24e18
Show file tree
Hide file tree
Showing 14 changed files with 10 additions and 182 deletions.
27 changes: 2 additions & 25 deletions core/go/internal/domainmgr/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type domain struct {
config *prototk.DomainConfig
schemasBySignature map[string]statestore.Schema
schemasByID map[string]statestore.Schema
constructorABI *abi.Entry
factoryContractAddress *tktypes.EthAddress

initError atomic.Pointer[error]
Expand Down Expand Up @@ -92,14 +91,7 @@ func (d *domain) processDomainConfig(confRes *prototk.ConfigureDomainResponse) (
}
}

err := json.Unmarshal(([]byte)(d.config.ConstructorAbiJson), &d.constructorABI)
if err != nil {
return nil, i18n.WrapError(d.ctx, err, msgs.MsgDomainConstructorAbiJsonInvalid)
}
if d.constructorABI.Type != abi.Constructor {
return nil, i18n.NewError(d.ctx, msgs.MsgDomainConstructorABITypeWrong, d.constructorABI.Type)
}

var err error
d.factoryContractAddress, err = tktypes.ParseEthAddress(d.config.FactoryContractAddress)
if err != nil {
return nil, i18n.WrapError(d.ctx, err, msgs.MsgDomainFactoryAddressInvalid)
Expand Down Expand Up @@ -244,25 +236,10 @@ func (d *domain) InitDeploy(ctx context.Context, tx *components.PrivateContractD
}

// Build the init request
var abiJSON []byte
var paramsJSON []byte
constructorValues, err := d.constructorABI.Inputs.ParseJSONCtx(ctx, tx.Inputs)
if err == nil {
abiJSON, err = json.Marshal(d.constructorABI)
}
if err == nil {
// Serialize to standardized JSON before passing to domain
paramsJSON, err = tktypes.StandardABISerializer().SerializeJSONCtx(ctx, constructorValues)
}
if err != nil {
return i18n.WrapError(ctx, err, msgs.MsgDomainInvalidConstructorParams, d.constructorABI.SolString())
}

txSpec := &prototk.DeployTransactionSpecification{}
tx.TransactionSpecification = txSpec
txSpec.TransactionId = tktypes.Bytes32UUIDFirst16(tx.ID).String()
txSpec.ConstructorAbi = string(abiJSON)
txSpec.ConstructorParamsJson = string(paramsJSON)
txSpec.ConstructorParamsJson = tx.Inputs.String()

// Do the request with the domain
res, err := d.api.InitDeploy(ctx, &prototk.InitDeployRequest{
Expand Down
86 changes: 0 additions & 86 deletions core/go/internal/domainmgr/domain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,6 @@ import (
"github.com/stretchr/testify/require"
)

const fakeCoinConstructorABI = `{
"type": "constructor",
"inputs": [
{
"name": "notary",
"type": "string"
},
{
"name": "name",
"type": "string"
},
{
"name": "symbol",
"type": "string"
}
],
"outputs": null
}`

const fakeCoinStateSchema = `{
"type": "tuple",
"internalType": "struct FakeCoin",
Expand Down Expand Up @@ -206,7 +187,6 @@ func goodDomainConf() *prototk.DomainConfig {
SubmitMode: prototk.BaseLedgerSubmitConfig_ONE_TIME_USE_KEYS,
OneTimeUsePrefix: "one/time/keys/",
},
ConstructorAbiJson: fakeCoinConstructorABI,
FactoryContractAddress: tktypes.MustEthAddress(tktypes.RandHex(20)).String(),
AbiStateSchemasJson: []string{
fakeCoinStateSchema,
Expand Down Expand Up @@ -267,7 +247,6 @@ func TestDoubleRegisterReplaces(t *testing.T) {
func TestDomainInitBadSchemas(t *testing.T) {
_, _, tp, done := newTestDomain(t, false, &prototk.DomainConfig{
BaseLedgerSubmitConfig: &prototk.BaseLedgerSubmitConfig{},
ConstructorAbiJson: fakeCoinConstructorABI,
FactoryContractAddress: tktypes.MustEthAddress(tktypes.RandHex(20)).String(),
AbiStateSchemasJson: []string{
`!!! Wrong`,
Expand All @@ -278,52 +257,9 @@ func TestDomainInitBadSchemas(t *testing.T) {
assert.False(t, tp.initialized.Load())
}

func TestDomainInitBadConstructor(t *testing.T) {
_, _, tp, done := newTestDomain(t, false, &prototk.DomainConfig{
BaseLedgerSubmitConfig: &prototk.BaseLedgerSubmitConfig{},
ConstructorAbiJson: `!!!wrong`,
FactoryContractAddress: tktypes.MustEthAddress(tktypes.RandHex(20)).String(),
AbiStateSchemasJson: []string{
fakeCoinStateSchema,
},
})
defer done()
assert.Regexp(t, "PD011603", *tp.d.initError.Load())
assert.False(t, tp.initialized.Load())
}

func TestDomainInitBadConstructorType(t *testing.T) {
_, _, tp, done := newTestDomain(t, false, &prototk.DomainConfig{
BaseLedgerSubmitConfig: &prototk.BaseLedgerSubmitConfig{},
ConstructorAbiJson: `{"type":"event"}`,
FactoryContractAddress: tktypes.MustEthAddress(tktypes.RandHex(20)).String(),
AbiStateSchemasJson: []string{
fakeCoinStateSchema,
},
})
defer done()
assert.Regexp(t, "PD011604", *tp.d.initError.Load())
assert.False(t, tp.initialized.Load())
}

func TestDomainInitSchemaStoreFail(t *testing.T) {
_, _, tp, done := newTestDomain(t, false, &prototk.DomainConfig{
BaseLedgerSubmitConfig: &prototk.BaseLedgerSubmitConfig{},
ConstructorAbiJson: `{"type":"event"}`,
FactoryContractAddress: tktypes.MustEthAddress(tktypes.RandHex(20)).String(),
AbiStateSchemasJson: []string{
fakeCoinStateSchema,
},
})
defer done()
assert.Regexp(t, "PD011604", *tp.d.initError.Load())
assert.False(t, tp.initialized.Load())
}

func TestDomainInitBadAddress(t *testing.T) {
_, _, tp, done := newTestDomain(t, false, &prototk.DomainConfig{
BaseLedgerSubmitConfig: &prototk.BaseLedgerSubmitConfig{},
ConstructorAbiJson: fakeCoinConstructorABI,
FactoryContractAddress: `!wrong`,
AbiStateSchemasJson: []string{
fakeCoinStateSchema,
Expand All @@ -337,7 +273,6 @@ func TestDomainInitBadAddress(t *testing.T) {
func TestDomainInitFactorySchemaStoreFail(t *testing.T) {
_, _, tp, done := newTestDomain(t, false, &prototk.DomainConfig{
BaseLedgerSubmitConfig: &prototk.BaseLedgerSubmitConfig{},
ConstructorAbiJson: fakeCoinConstructorABI,
FactoryContractAddress: tktypes.MustEthAddress(tktypes.RandHex(20)).String(),
AbiStateSchemasJson: []string{
fakeCoinStateSchema,
Expand Down Expand Up @@ -479,7 +414,6 @@ func TestDomainInitDeployOK(t *testing.T) {
tp.Functions.InitDeploy = func(ctx context.Context, idr *prototk.InitDeployRequest) (*prototk.InitDeployResponse, error) {
defer done()
assert.Equal(t, "0x53ba5dd6b708444da2fa50578b974fb700000000000000000000000000000000", idr.Transaction.TransactionId)
assert.JSONEq(t, fakeCoinConstructorABI, idr.Transaction.ConstructorAbi)
assert.JSONEq(t, `{
"notary": "notary1",
"name": "token1",
Expand Down Expand Up @@ -525,26 +459,6 @@ func TestDomainInitDeployMissingInput(t *testing.T) {
assert.Nil(t, tx.RequiredVerifiers)
}

func TestDomainInitDeployBadConstructorParams(t *testing.T) {
ctx, _, tp, done := newTestDomain(t, false, goodDomainConf(), mockSchemas())
defer done()
assert.Nil(t, tp.d.initError.Load())

txID := uuid.MustParse("53BA5DD6-B708-444D-A2FA-50578B974FB7")
domain := tp.d
tx := &components.PrivateContractDeploy{
ID: txID,
Inputs: tktypes.RawJSON(`{
"notary": "notary1",
"name": 12345,
"symbol": "TKN1"
}`),
}
err := domain.InitDeploy(ctx, tx)
assert.Regexp(t, "PD011610", err)
assert.Nil(t, tx.RequiredVerifiers)
}

func TestDomainInitDeployError(t *testing.T) {
ctx, _, tp, done := newTestDomain(t, false, goodDomainConf(), mockSchemas())
defer done()
Expand Down
3 changes: 0 additions & 3 deletions core/go/internal/msgs/en_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,11 @@ var (
MsgDomainNotFound = ffe("PD011600", "Domain %q not found")
MsgDomainNotInitialized = ffe("PD011601", "Domain not initialized")
MsgDomainInvalidSchema = ffe("PD011602", "Domain schema %d is invalid")
MsgDomainConstructorAbiJsonInvalid = ffe("PD011603", "Constructor ABI function definition invalid")
MsgDomainConstructorABITypeWrong = ffe("PD011604", "Constructor ABI function definition has wrong type: %s")
MsgDomainFactoryAbiJsonInvalid = ffe("PD011605", "Factory contract ABI invalid")
MsgDomainFactoryAddressInvalid = ffe("PD011606", "Factory contract address invalid")
MsgDomainPrivateAbiJsonInvalid = ffe("PD011607", "Private contract ABI invalid")
MsgDomainInvalidQueryJSON = ffe("PD011608", "Invalid query JSON")
MsgDomainContractNotFoundByAddr = ffe("PD011609", "A smart contract with address %s has not yet been indexed")
MsgDomainInvalidConstructorParams = ffe("PD011610", "Invalid constructor parameters for %s")
MsgDomainInvalidPrepareDeployResult = ffe("PD011611", "Prepare deploy did not result in exactly one of a invoke transaction or a deploy transaction")
MsgDomainInvalidFunctionParams = ffe("PD011612", "Invalid function parameters for %s")
MsgDomainUnknownSchema = ffe("PD011613", "Unknown schema %s")
Expand Down
4 changes: 2 additions & 2 deletions core/go/internal/plugins/domains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func TestDomainRequestsOK(t *testing.T) {
assert.Equal(t, int64(12345), cdr.ChainId)
return &prototk.ConfigureDomainResponse{
DomainConfig: &prototk.DomainConfig{
ConstructorAbiJson: "ABI1",
FactoryContractAddress: "address1",
},
}, nil
},
Expand Down Expand Up @@ -196,7 +196,7 @@ func TestDomainRequestsOK(t *testing.T) {
ChainId: int64(12345),
})
require.NoError(t, err)
assert.Equal(t, "ABI1", cdr.DomainConfig.ConstructorAbiJson)
assert.Equal(t, "address1", cdr.DomainConfig.FactoryContractAddress)

_, err = domainAPI.InitDomain(ctx, &prototk.InitDomainRequest{
DomainUuid: domainID,
Expand Down
21 changes: 0 additions & 21 deletions core/go/pkg/testbed/ut_simdomain_notarized_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,6 @@ func TestDemoNotarizedCoinSelection(t *testing.T) {

var blockIndexer atomic.Pointer[blockindexer.BlockIndexer]
var ec ethclient.EthClient
fakeCoinConstructorABI := `{
"type": "constructor",
"inputs": [
{
"name": "notary",
"type": "string"
},
{
"name": "name",
"type": "string"
},
{
"name": "symbol",
"type": "string"
}
],
"outputs": null
}`

fakeCoinStateSchema := `{
"type": "tuple",
Expand Down Expand Up @@ -336,7 +318,6 @@ func TestDemoNotarizedCoinSelection(t *testing.T) {
BaseLedgerSubmitConfig: &prototk.BaseLedgerSubmitConfig{
SubmitMode: prototk.BaseLedgerSubmitConfig_ENDORSER_SUBMISSION,
},
ConstructorAbiJson: fakeCoinConstructorABI,
FactoryContractAddress: deployTx.ContractAddress.String(),
AbiStateSchemasJson: []string{fakeCoinStateSchema},
},
Expand All @@ -351,7 +332,6 @@ func TestDemoNotarizedCoinSelection(t *testing.T) {
},

InitDeploy: func(ctx context.Context, req *prototk.InitDeployRequest) (*prototk.InitDeployResponse, error) {
assert.JSONEq(t, fakeCoinConstructorABI, req.Transaction.ConstructorAbi)
assert.JSONEq(t, fakeDeployPayload, req.Transaction.ConstructorParamsJson)
return &prototk.InitDeployResponse{
RequiredVerifiers: []*prototk.ResolveVerifierRequest{
Expand All @@ -364,7 +344,6 @@ func TestDemoNotarizedCoinSelection(t *testing.T) {
},

PrepareDeploy: func(ctx context.Context, req *prototk.PrepareDeployRequest) (*prototk.PrepareDeployResponse, error) {
assert.JSONEq(t, fakeCoinConstructorABI, req.Transaction.ConstructorAbi)
assert.JSONEq(t, `{
"notary": "domain1/contract1/notary",
"name": "FakeToken1",
Expand Down
3 changes: 0 additions & 3 deletions core/java/src/test/java/io/kaleido/paladin/TestDomain.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ public class TestDomain extends DomainInstance {
@Override
protected CompletableFuture<ToDomain.ConfigureDomainResponse> configureDomain(ToDomain.ConfigureDomainRequest request) {
ToDomain.DomainConfig domainConfig = ToDomain.DomainConfig.newBuilder()
.setConstructorAbiJson("""
{"type":"constructor","inputs":[]}
""")
.setFactoryContractAddress("0x1000000000000000000000000000000000000001")
.setBaseLedgerSubmitConfig(ToDomain.BaseLedgerSubmitConfig.newBuilder()
.setSubmitMode(ToDomain.BaseLedgerSubmitConfig.Mode.ONE_TIME_USE_KEYS)
Expand Down
5 changes: 0 additions & 5 deletions domains/noto/internal/noto/noto.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ func (n *Noto) ConfigureDomain(ctx context.Context, req *pb.ConfigureDomainReque
return nil, fmt.Errorf("unrecognized variant: %s", config.Variant)
}

constructorJSON, err := json.Marshal(types.NotoABI.Constructor())
if err != nil {
return nil, err
}
schemaJSON, err := json.Marshal(types.NotoCoinABI)
if err != nil {
return nil, err
Expand All @@ -105,7 +101,6 @@ func (n *Noto) ConfigureDomain(ctx context.Context, req *pb.ConfigureDomainReque
return &pb.ConfigureDomainResponse{
DomainConfig: &pb.DomainConfig{
FactoryContractAddress: config.FactoryAddress,
ConstructorAbiJson: string(constructorJSON),
AbiStateSchemasJson: []string{string(schemaJSON)},
BaseLedgerSubmitConfig: &pb.BaseLedgerSubmitConfig{
SubmitMode: pb.BaseLedgerSubmitConfig_ENDORSER_SUBMISSION,
Expand Down
6 changes: 0 additions & 6 deletions domains/noto/pkg/types/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ import (
)

var NotoABI = abi.ABI{
{
Type: abi.Constructor,
Inputs: abi.ParameterArray{
{Name: "notary", Type: "string"},
},
},
{
Name: "mint",
Type: abi.Function,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ private static JsonABI.Parameter abiTuple_group() {
));
}

JsonABI.Entry abiEntry_privateConstructor() {
return JsonABI.newConstructor(JsonABI.newParameters(
abiTuple_group(),
JsonABI.newParameter("endorsementType", "string")
));
}

JsonABI.Entry abiEntry_privateTransactionInvoke() {
return JsonABI.newConstructor(JsonABI.newParameters(
abiTuple_group(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ protected CompletableFuture<ToDomain.ConfigureDomainResponse> configureDomain(To
config.initFromJSON(request.getConfigJson());

ToDomain.DomainConfig domainConfig = ToDomain.DomainConfig.newBuilder()
.setConstructorAbiJson(config.abiEntry_privateConstructor().toString())
.setFactoryContractAddress(config.getAddress().toString())
.addAllAbiStateSchemasJson(config.allPenteSchemas())
.setBaseLedgerSubmitConfig(ToDomain.BaseLedgerSubmitConfig.newBuilder()
Expand Down
5 changes: 0 additions & 5 deletions domains/zeto/internal/zeto/zeto.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ func (z *Zeto) ConfigureDomain(ctx context.Context, req *pb.ConfigureDomainReque
z.factoryABI = factory.ABI
z.contractABI = contract.ABI

constructorJSON, err := json.Marshal(types.ZetoABI.Constructor())
if err != nil {
return nil, err
}
schemaJSON, err := json.Marshal(types.ZetoCoinABI)
if err != nil {
return nil, err
Expand All @@ -94,7 +90,6 @@ func (z *Zeto) ConfigureDomain(ctx context.Context, req *pb.ConfigureDomainReque
return &pb.ConfigureDomainResponse{
DomainConfig: &pb.DomainConfig{
FactoryContractAddress: config.FactoryAddress,
ConstructorAbiJson: string(constructorJSON),
AbiStateSchemasJson: []string{string(schemaJSON)},
BaseLedgerSubmitConfig: &pb.BaseLedgerSubmitConfig{
SubmitMode: pb.BaseLedgerSubmitConfig_ENDORSER_SUBMISSION,
Expand Down
13 changes: 2 additions & 11 deletions domains/zeto/pkg/types/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,15 @@ import (
)

var ZetoABI = abi.ABI{
&abi.Entry{
Type: abi.Constructor,
Inputs: abi.ParameterArray{
{Name: "from", Type: "string"},
{Name: "depositVerifier", Type: "address"},
{Name: "withdrawVerifier", Type: "address"},
{Name: "verifier", Type: "address"},
},
},
&abi.Entry{
{
Name: "mint",
Type: abi.Function,
Inputs: abi.ParameterArray{
{Name: "to", Type: "string"},
{Name: "amount", Type: "uint256"},
},
},
&abi.Entry{
{
Name: "transfer",
Type: abi.Function,
Inputs: abi.ParameterArray{
Expand Down
1 change: 0 additions & 1 deletion toolkit/go/domainstarter/starter/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func (s *starter) configureDomain(ctx context.Context, cdr *prototk.ConfigureDom
return &prototk.ConfigureDomainResponse{
// This is a useless, but valid, example
DomainConfig: &prototk.DomainConfig{
ConstructorAbiJson: `{"type":"constructor","inputs":[]}`,
FactoryContractAddress: `0x1000000000000000000000000000000000000001`,
AbiStateSchemasJson: []string{},
BaseLedgerSubmitConfig: &prototk.BaseLedgerSubmitConfig{
Expand Down
Loading

0 comments on commit 8d24e18

Please sign in to comment.