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

LDC support in predicates #848

Merged
merged 17 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

### Added
- [#848](https://github.com/FuelLabs/fuel-vm/pull/848): Allow usage of the blob opcode `BSIZ`, `BLDD`, and `LDC` with mode `1` in the predicates.
- [#838](https://github.com/FuelLabs/fuel-vm/pull/838): Implemented `AsRef<[u8]>` and `TryFrom<&[u8]>` for DA compression types: ScriptCode, PredicateCode, RegistryKey.
- [#820](https://github.com/FuelLabs/fuel-vm/pull/820): Add fuzzing in CI with ClusterFuzzLite.

### Removed

#### Breaking
- [#848](https://github.com/FuelLabs/fuel-vm/pull/848): All estimation and verification of predicate functionality is reworked and now requires the instance of the storage with predicates.
- [#843](https://github.com/FuelLabs/fuel-vm/pull/843): Remove `serde` feature from the `fuel-tx` crate. It is default behaviour now if you enable `alloc` feature.

### Changed
Expand Down
10 changes: 6 additions & 4 deletions fuel-asm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,9 @@ impl Opcode {
| K256 | S256 | NOOP | FLAG | ADDI | ANDI | DIVI | EXPI | MODI | MULI
| MLDV | ORI | SLLI | SRLI | SUBI | XORI | JNEI | LB | LW | SB | SW
| MCPI | MCLI | GM | MOVI | JNZI | JI | JMP | JNE | JMPF | JMPB | JNZF
| JNZB | JNEF | JNEB | CFEI | CFSI | CFE | CFS | GTF => true,
| JNZB | JNEF | JNEB | CFEI | CFSI | CFE | CFS | GTF | LDC | BSIZ | BLDD => {
true
Comment on lines +704 to +705
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test needs updating (

pub fn is_predicate_allowed(&self) -> bool {
)

}
_ => false,
}
}
Expand Down Expand Up @@ -991,9 +993,9 @@ fn check_predicate_allowed() {
for byte in 0..u8::MAX {
if let Ok(repr) = Opcode::try_from(byte) {
let should_allow = match repr {
BAL | BHEI | BHSH | BURN | CALL | CB | CCP | CROO | CSIZ | LDC | LOG
| LOGD | MINT | RETD | RVRT | SMO | SCWQ | SRW | SRWQ | SWW | SWWQ
| TIME | TR | TRO | ECAL | BSIZ | BLDD => false,
BAL | BHEI | BHSH | BURN | CALL | CB | CCP | CROO | CSIZ | LOG | LOGD
| MINT | RETD | RVRT | SMO | SCWQ | SRW | SRWQ | SWW | SWWQ | TIME
| TR | TRO | ECAL => false,
_ => true,
};
assert_eq!(should_allow, repr.is_predicate_allowed());
Expand Down
6 changes: 3 additions & 3 deletions fuel-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ coins-bip39 = { version = "0.8", default-features = false, features = ["english"
ecdsa = { version = "0.16", default-features = false }
ed25519-dalek = { version = "2.0.0", default-features = false }
fuel-types = { workspace = true, default-features = false }
k256 = { version = "0.13", default-features = false, features = ["digest", "ecdsa"] }
k256 = { version = "0.13", default-features = false, features = ["digest", "ecdsa"] }
lazy_static = { version = "1.4", optional = true }
p256 = { version = "0.13", default-features = false, features = ["digest", "ecdsa"] }
p256 = { version = "0.13", default-features = false, features = ["digest", "ecdsa"] }
rand = { version = "0.8", default-features = false, optional = true }
# `rand-std` is used to further protect the blinders from side-channel attacks and won't compromise
# the deterministic arguments of the signature (key, nonce, message), as defined in the RFC-6979
Expand All @@ -35,7 +35,7 @@ sha2 = "0.10"

[features]
default = ["fuel-types/default", "std"]
alloc = ["rand?/alloc", "secp256k1/alloc", "fuel-types/alloc"]
alloc = ["rand?/alloc", "secp256k1?/alloc", "fuel-types/alloc"]
random = ["fuel-types/random", "rand"]
serde = ["dep:serde", "fuel-types/serde"]
std = ["alloc", "coins-bip32", "secp256k1", "coins-bip39", "fuel-types/std", "lazy_static", "rand?/std_rng", "serde?/default"]
Expand Down
1 change: 1 addition & 0 deletions fuel-tx/src/transaction/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ where
}) if owner == &pk => Some(*witness_index as usize),
_ => None,
})
.sorted()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personal question: what is the reason behind this ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just notice going over the code that we call dedup, but it not we expect=) So I added dedup to have behavior that we want

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, dedup() works on "consecutive identical elements". This bit me many times in the past :)
Good catch.

.dedup()
.collect_vec();

Expand Down
20 changes: 20 additions & 0 deletions fuel-tx/src/transaction/types/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,26 @@ impl Input {
}
}

pub fn set_predicate_gas_used(&mut self, gas: Word) {
match self {
Input::CoinPredicate(CoinPredicate {
predicate_gas_used, ..
})
| Input::MessageCoinPredicate(MessageCoinPredicate {
predicate_gas_used,
..
})
| Input::MessageDataPredicate(MessageDataPredicate {
predicate_gas_used,
..
}) => *predicate_gas_used = gas,
Input::CoinSigned(_)
| Input::MessageCoinSigned(_)
| Input::MessageDataSigned(_)
| Input::Contract(_) => {}
}
}

pub fn message_id(&self) -> Option<MessageId> {
match self {
Self::MessageCoinSigned(message) => Some(message.message_id()),
Expand Down
5 changes: 3 additions & 2 deletions fuel-vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fuel-compression = { workspace = true, default-features = false, optional = true
fuel-crypto = { workspace = true, default-features = false }
fuel-merkle = { workspace = true, default-features = false }
fuel-storage = { workspace = true }
fuel-tx = { workspace = true, default-features = false }
fuel-tx = { workspace = true, default-features = false, features = ["alloc"] }
fuel-types = { workspace = true, default-features = false }
hashbrown = "0.14"
itertools = { version = "0.10", default-features = false }
Expand Down Expand Up @@ -84,7 +84,7 @@ std = [
"fuel-tx/std",
"itertools/use_std",
]
alloc = ["fuel-asm/alloc", "fuel-tx/alloc", "fuel-tx/alloc"]
alloc = ["fuel-asm/alloc", "fuel-tx/alloc", "fuel-crypto/alloc"]
xgreenx marked this conversation as resolved.
Show resolved Hide resolved
profile-gas = ["profile-any"]
profile-coverage = ["profile-any"]
profile-any = ["dyn-clone"] # All profiling features should depend on this
Expand All @@ -97,6 +97,7 @@ serde = [
"fuel-asm/serde",
"fuel-types/serde",
"fuel-merkle/serde",
"fuel-crypto/serde",
"backtrace?/serde",
]
test-helpers = [
Expand Down
Loading
Loading