From b1944bf4536791d6a6bfa45a1f0bce2126cb478e Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Sat, 17 Aug 2024 08:54:15 +0200 Subject: [PATCH] vm: use operation type in ordering If we have two different state transitions of different mined into the same block, which (by mistake) have the same nonce, we still can order them using type. This allows usage of type id value as a way of setting strong ordering overriding nonce values (for instance token issues can be always ordered before spendings) --- src/stl.rs | 14 +++++++------- src/vm/contract.rs | 24 ++++++++++++++++++++---- stl/RGBLogic@0.1.0.sta | 24 ++++++++++++------------ stl/RGBLogic@0.1.0.sty | 7 +++++-- 4 files changed, 44 insertions(+), 25 deletions(-) diff --git a/src/stl.rs b/src/stl.rs index 4e31e530..6e6eac25 100644 --- a/src/stl.rs +++ b/src/stl.rs @@ -51,13 +51,13 @@ fn _rgb_commit_stl() -> Result { bp_core_stl().to_dependency(), aluvm_stl().to_dependency() }) - .transpile::() - .transpile::() - .transpile::() - .transpile::() - .transpile::() - .transpile::() - .compile() + .transpile::() + .transpile::() + .transpile::() + .transpile::() + .transpile::() + .transpile::() + .compile() } fn _rgb_logic_stl() -> Result { diff --git a/src/vm/contract.rs b/src/vm/contract.rs index c72c4db0..9bf0e2f5 100644 --- a/src/vm/contract.rs +++ b/src/vm/contract.rs @@ -170,11 +170,13 @@ impl<'op> OrdOpRef<'op> { OrdOpRef::Genesis(_) => OpOrd::Genesis, OrdOpRef::Transition(op, _, witness_ord) => OpOrd::Transition { witness: *witness_ord, + ty: op.transition_type, nonce: op.nonce, opid: op.id(), }, OrdOpRef::Extension(op, _, witness_ord) => OpOrd::Extension { witness: *witness_ord, + ty: op.extension_type, nonce: op.nonce, opid: op.id(), }, @@ -415,14 +417,14 @@ pub enum OpOrd { #[strict_type(tag = 0x01)] Extension { witness: WitnessOrd, - // TODO: Consider using extension type here + ty: ExtensionType, nonce: u64, opid: OpId, }, #[strict_type(tag = 0xFF)] Transition { witness: WitnessOrd, - // TODO: Consider using transition type here + ty: TransitionType, nonce: u64, opid: OpId, }, @@ -465,20 +467,34 @@ impl GlobalOrd { idx, } } - pub fn transition(opid: OpId, idx: u16, nonce: u64, witness: WitnessOrd) -> Self { + pub fn transition( + opid: OpId, + idx: u16, + ty: TransitionType, + nonce: u64, + witness: WitnessOrd, + ) -> Self { Self { op_ord: OpOrd::Transition { witness, + ty, nonce, opid, }, idx, } } - pub fn extension(opid: OpId, idx: u16, nonce: u64, witness: WitnessOrd) -> Self { + pub fn extension( + opid: OpId, + idx: u16, + ty: ExtensionType, + nonce: u64, + witness: WitnessOrd, + ) -> Self { Self { op_ord: OpOrd::Extension { witness, + ty, nonce, opid, }, diff --git a/stl/RGBLogic@0.1.0.sta b/stl/RGBLogic@0.1.0.sta index ff50441e..88d54367 100644 --- a/stl/RGBLogic@0.1.0.sta +++ b/stl/RGBLogic@0.1.0.sta @@ -1,14 +1,14 @@ -----BEGIN STRICT TYPE LIB----- -Id: stl:LpE2Q!Jf-pKsvjM$-ntKgUld-!zeRRa!-v7l6pzJ-qW2YceY#africa-choice-biology +Id: stl:w3K7P7FD-SQ36YW9-C4zqzxS-9RCkgd$-osrL6RV-gk11t!g#satire-vital-richard Name: RGBLogic Dependencies: - RGBCommit#tuna-safari-design, - BPCore#totem-holiday-helena, + BPCore#garbo-radius-peru, + RGBCommit#nova-lobby-dialog, Bitcoin#signal-color-cipher -Check-SHA256: ec5fbe3beec7e0816d76eb90ea8fb35c931847f2b189f7befdde4e7e16d53e18 +Check-SHA256: b385c363a383d9a2cce01e0c7b4e75acd48725312341a0dcfe23317f431e744b -2vSEvOmAmtV*_Nw)d@|xKsr716mTQmaB}ROZ@Dgs2ia_2=g^?i+KdTOM?ynyZEb0ErdhI3FM~0|p{<6( -sS&)~H{Xkb4j+}v9*QG}Q6KKm20~CnZ*pbzY!hN5_Bp3Y36tDMM#=e#tGI($UA5U3KNx<*C>ja}LTPkk +2vSEvOmAmtV*_s;CP(yEWW!w3x9BR2~UxbGv2Fx@x +O&x#t!~fsyrIq3x!~?M?ja}LTPkk Z)t7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e?vTA1;^Q1`ZqBog<<3Rh`#Ze??GPjX}g0{{qN +LK#dEwxUFHJ){RjtgLvL_X>0rou@Knb#Vo5Z*F5{000OCZ*Xa30^9kj9BR2~UxbGv2Fx@xO&x#t!~fsy +rIq3x!~?M?<(0_hdLDIRU(}XWLTZugenOC;Z(5k~zEJnJiX;;E#s3O)a$#@6CZU6=Y2X|?7Ze??G +0rm?cniq>g8B7tjqC|5&qz6Q-tazCB3Um~mr!r)9aRqK~ZewKt00;zcaA{-$+xe;-YPo4&goh&r%rrDj +9e?-3|KIJUmEs-51F&L0S>>o?Kom?q=ULN^A!11b?H{wM>P}NCm0qyW47Umu>uKnWo~p~bZK^F 0000AS7~%^Wpi^-Z*v9$254nzXJ~W)00aqiX>Db5bYX39002k diff --git a/stl/RGBLogic@0.1.0.sty b/stl/RGBLogic@0.1.0.sty index cdd6a868..1ffec788 100644 --- a/stl/RGBLogic@0.1.0.sty +++ b/stl/RGBLogic@0.1.0.sty @@ -1,5 +1,5 @@ {- - Id: stl:LpE2Q!Jf-pKsvjM$-ntKgUld-!zeRRa!-v7l6pzJ-qW2YceY#africa-choice-biology + Id: stl:w3K7P7FD-SQ36YW9-C4zqzxS-9RCkgd$-osrL6RV-gk11t!g#satire-vital-richard Name: RGBLogic Version: 0.1.0 Description: Consensus logic layer for RGB smart contracts @@ -11,7 +11,7 @@ @context typelib RGBLogic -import RGBCommit#tuna-safari-design +import RGBCommit#pretend-carpet-caesar use OpId#picnic-single-gloria import BPCore#totem-holiday-helena @@ -21,6 +21,9 @@ import BPCore#totem-holiday-helena use TapretRightBranch#miracle-patriot-touch use OpretProof#good-village-flex +import RGBCommit#nova-lobby-dialog + use OpId#picnic-single-gloria + import Bitcoin#signal-color-cipher use ScriptBytes#equator-cockpit-gong use TapNodeHash#paprika-amanda-hunter