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 a new mode 2 to the LDC that allows to use the memory as a source for code #849

Merged
merged 27 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
de86a1a
allow ldc in predicates, still need to deal with storage and checked txs
Voxelot Oct 4, 2024
4225346
checkpoint, plumbing storage and refactoring generics
Voxelot Oct 4, 2024
b4c4da3
plumbing of generics happy, now onto all the tests
Voxelot Oct 4, 2024
b0d0302
fix serde error in fuel-crypto
Voxelot Oct 5, 2024
340f401
expose predicate storage module
Voxelot Oct 5, 2024
2da51b1
avoid supertrait
Voxelot Oct 5, 2024
3073daa
removing clone constraint, trying to reason through the async issues
Voxelot Oct 5, 2024
74e7c3f
removed clone, made async happy
Voxelot Oct 5, 2024
0b987e2
more alloc!
Voxelot Oct 5, 2024
bba89e4
disable alloc but keep serde in fuel-crypto
Voxelot Oct 5, 2024
e715fb1
Revert "disable alloc but keep serde in fuel-crypto"
Voxelot Oct 5, 2024
090636c
battle of the feature flags
Voxelot Oct 5, 2024
39eb13e
enable BSIZ and BLDD
Voxelot Oct 5, 2024
156f2a8
Fixed compilation for tests.
xgreenx Oct 5, 2024
4c43718
Removed `StorageUnavailable`
xgreenx Oct 5, 2024
d62ee4d
Updated CHANGELOG.md
xgreenx Oct 5, 2024
6acc4ca
Add a new mode `2` to the LDC that allows to use the memory as a sour…
xgreenx Oct 5, 2024
ce1603a
Added more tests for mode 2
xgreenx Oct 5, 2024
a564f3f
Update fuel-asm/src/lib.rs
xgreenx Oct 5, 2024
2a32a64
Updated CHANGELOG.md
xgreenx Oct 5, 2024
5bbf301
Merge remote-tracking branch 'origin/feature/ldc-mode-2' into feature…
xgreenx Oct 5, 2024
1b01a9d
Added tests that contract LDC is not allowed
xgreenx Oct 5, 2024
4289674
Merge branch 'refs/heads/feature/predicate-ldc' into feature/ldc-mode-2
xgreenx Oct 5, 2024
24e5b21
Merge branch 'refs/heads/master' into feature/ldc-mode-2
xgreenx Oct 5, 2024
d1c6283
Return back removed CHANGELOG.md
xgreenx Oct 5, 2024
4e2d0df
Fix the comment
xgreenx Oct 5, 2024
65c78d3
Apply comments
xgreenx Oct 5, 2024
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

### Added
- [#849](https://github.com/FuelLabs/fuel-vm/pull/849): Add a new mode `2` to the LDC that allows to use the memory as a source for code.
- [#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
14 changes: 8 additions & 6 deletions fuel-asm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ impl_instructions! {
0x30 CSIZ csiz [dst: RegId contract_id_addr: RegId]
"Get current block proposer's address."
0x31 CB cb [dst: RegId]
"Load a contract's code as executable."
0x32 LDC ldc [contract_id_addr: RegId offset: RegId len: RegId mode: Imm06]
"Load code as executable either from contract, blob, or memory."
0x32 LDC ldc [src_addr: RegId offset: RegId len: RegId mode: Imm06]
"Log an event."
0x33 LOG log [a: RegId b: RegId c: RegId d: RegId]
"Log data."
Expand Down 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
}
_ => 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()
.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"]
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