Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add host functions that calculate contract IDs from inputs #538

Closed
leighmcculloch opened this issue Oct 13, 2022 · 7 comments · Fixed by #853
Closed

Add host functions that calculate contract IDs from inputs #538

leighmcculloch opened this issue Oct 13, 2022 · 7 comments · Fixed by #853
Assignees
Labels
hostfunction Work on specific host functions

Comments

@leighmcculloch
Copy link
Member

leighmcculloch commented Oct 13, 2022

We need a set of host functions that will return contract ID (as Bytes) given a set of inputs.

We have the following functions that can create contracts:

{"3", fn create_contract_from_ed25519(v: Object, salt: Object, key: Object, sig: Object) -> Object}
{"4", fn create_contract_from_contract(v: Object, salt: Object) -> Object}
{"5", fn create_token_from_ed25519(salt: Object, key: Object, sig: Object) -> Object}
{"6", fn create_token_from_contract(salt: Object) -> Object}
{"7", fn create_token_from_asset(asset: Object) -> Object}
/// Create a contract using the source account and salt as input
/// to the contract ID that gets created. Pass as arguments a
/// Bytes for the wasm code and a Bytes for the salt. Returned
/// will be a Bytes of length 32 bytes.
{"8", fn create_contract_from_source_account(v: Object, salt: Object) -> Object}
/// Create a token contract using the source account and salt
/// as input to the contract ID that gets created. Pass as
/// arguments a Bytes for the salt. Returned
/// will be a Bytes of length 32 bytes.
{"9", fn create_token_from_source_account(salt: Object) -> Object}

In total we need to add 12 new host functions:

  • 7 new host functions that are counter-parts to the host functions above, that will return the contract ID that will be used if the deployment was to occur by calling the respective function.

    • get_contract_id_contract_from_ed25519(salt: Object, key: Object) -> Object
    • get_contract_id_contract_from_contract(salt: Object) -> Object
    • get_contract_id_contract_from_source_account(salt: Object) -> Object
    • get_contract_id_token_from_ed25519(salt: Object, key: Object) -> Object
    • get_contract_id_token_from_contract(salt: Object) -> Object
    • get_contract_id_token_from_source_account(salt: Object) -> Object
    • get_contract_id_token_from_asset(asset: Object) -> Object
  • 2 new host functions for getting the contract ID for a deployment from contract that isn't the currently executing contract.

    • get_contract_id_contract_from_other_contract(contract_id: RawVal, salt: Object) -> Object
    • get_contract_id_token_from_other_contract(contract_id: RawVal, salt: Object) -> Object

We can omit any of these host functions that would always return the same value given the same inputs. For example, I expect we can omit all the token functions except the one that accepts an asset,

Dependent on #537
Blocking stellar/rs-soroban-sdk#730

@jayz22
Copy link
Contributor

jayz22 commented Feb 13, 2023

@leighmcculloch Is this issue still relevant? Most of the mentioned host functions have been removed and the mentioned issue has been closed.

@leighmcculloch
Copy link
Member Author

Yeah it should be possible for us to write an SDK function that helps a developer predetermine a contract ID that would be the contract ID of a contract when deployed.

@leighmcculloch
Copy link
Member Author

leighmcculloch commented Feb 13, 2023

The infrastructure around deployments has changed a lot, so the examples in the original issue are out of date, but the problem remains.

@jayz22 jayz22 added the hostfunction Work on specific host functions label Feb 13, 2023
@jayz22 jayz22 self-assigned this Feb 13, 2023
@jayz22
Copy link
Contributor

jayz22 commented Jun 14, 2023

We currently have two host functions for creating a contract:

                    "name": "create_contract",
                    "args": [
                        {
                            "name": "deployer",
                            "type": "AddressObject"
                        },
                        {
                            "name": "wasm_hash",
                            "type": "BytesObject"
                        },
                        {
                            "name": "salt",
                            "type": "BytesObject"
                        }
                    ],
                    "name": "create_asset_contract",
                    "args": [
                        {
                            "name": "serialized_asset",
                            "type": "BytesObject"
                        }                        
                    ],

So we just need two additional host functions given the same arguments and returns the contract_id without creating?

2 new host functions for getting the contract ID for a deployment from contract that isn't the currently executing contract.

@leighmcculloch Can you confirm if this statement is outdated?

@leighmcculloch
Copy link
Member Author

I think we could probably defer this. I suspect someone will need it, but it can be added at any point.

@jayz22
Copy link
Contributor

jayz22 commented Jun 14, 2023

@leighmcculloch I've created the PR above which adds two new host functions corresponding to contract and asset contract. I think this should cover all the scenarios originally requested to unblock the sdk? Let me know if that's not the case.

@leighmcculloch
Copy link
Member Author

@jayz22 It looks great 👏🏻. That was fast!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hostfunction Work on specific host functions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants