-
-
Notifications
You must be signed in to change notification settings - Fork 28
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
Provide an API for deterministic contract generation #111
Comments
No, it is not possible. Each contract is unique - at least as long as it contains a timestamp (which includes milliseconds). |
I figure it out that RGB20 contract id is based on |
No, However, inside Why do you need a deterministic contract generation? |
Cause in my point of view, contract id should be the same if and only if the contract contents is the same. I mean, it's just a hash of the contract content. Actually, i tried to set Timestamp to a constant, and for the |
If you are using current master/beta v0.11 there is also a thing called Anyway, can you share your code so I can check how exactly you are doing that? |
I'm still on version 0.10.2, not using
let name = "USDT";
let decimal = Precision::CentiMicro; // Decimal: 8
let desc = "USD Tether Token";
let spec = DivisibleAssetSpec::with("RGB20", name, decimal, Some(desc)).unwrap();
let terms = RicardianContract::default();
let contract_data = ContractData { terms, media: None };
// let created = Timestamp::now();
let ts = 1700755200;
let strict_value = StrictVal::from(ts);
let created = Timestamp::from_strict_val_unchecked(&strict_value);
let txid = "0018dc9fff99382ac228a6cbcbdddb0989329d85d95c1e354b74a488da324516";
let vout_index = 1;
let beneficiary = Outpoint::new(Txid::from_hex(txid).unwrap(), vout_index);
const ISSUE: u64 = 1_000_000_000;
let contract = ContractBuilder::with(rgb20(), nia_schema(), nia_rgb20())
.expect("schema fails to implement RGB20 interface")
.set_chain(Chain::Testnet3)
.add_global_state("spec", spec)
.expect("invalid nominal")
.add_global_state("created", created)
.expect("invalid creation date")
.add_global_state("issuedSupply", Amount::from(ISSUE))
.expect("invalid issued supply")
.add_global_state("data", contract_data)
.expect("invalid contract text")
.add_fungible_state("assetOwner", beneficiary, ISSUE)
.expect("invalid asset amount")
.issue_contract()
.expect("contract doesn't fit schema requirements");
let contract_id = contract.contract_id();
println!("{contract_id}"); Also, i've replaced let sk_str = "01010101010101010001020304050607ffff0000ffff00006363636363636363";
let sk = secp256k1_zkp::SecretKey::from_str(sk_str).unwrap();
let state = RevealedValue::with(value, sk); However, got an error with "use of undeclared crate or module |
You need to use it in the code as |
@oneforalone I agree with your arguments and have added a convenient API for deterministic contract generation into the v0.11 roadmap |
Not sure I understood, what would be exactly the use case of having deterministic contract generation? |
The simplest case is that we can verify a contract if we know construction arguments of the contract. |
With v0.11 I tried to address ability to deterministically generate contract and state transitions (important for Lightning, coinjoins, atomic swap protocols etc). Let's use this issue as a tracking for the matter. To generate contract or a state transition in a deterministic way, one has to do the following:
|
@dr-orlovsky what's missing to complete this? I see this isn't listed in the rgb 0.11 board (https://github.com/orgs/RGB-WG/projects/17), do you still plan to do it in a 0.11 release? I think this is useful to have, to do some tests |
I think tests are missing: I am not 100% sure we have all required APIs in place, but hard to point at specific one which can be missed |
I can give a look at this and let you know if something's missing or if everything's in place |
I've checked this using I think we can close this as soon that PR gets merged. I've added a test (RGB-WG/rgb-schemata#41) so that with beta 6 we can be sure this still works. |
I tried to make every arguments to const value, however, each time i compiled it, the contract id changes. And after take tracing the code, found the contract id is generate from lib
commit_verify
's functioncommitment_id
. The function shows that the id is generate from a sha256 of a 32 bytes variableTAG
, while i found thatTAG
s variables are defined as const, so, why the contract id would become different with the same arguments and the same codes? Or is there an way to generate a deterministic contract id with the same codes/arguments?The text was updated successfully, but these errors were encountered: