Skip to content

Commit

Permalink
chore: Use v1.7.7 Optimism contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
clabby committed Jul 20, 2024
1 parent dad68e7 commit 7790645
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 53 deletions.
4 changes: 2 additions & 2 deletions crates/fpvm/bindings/bindings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ MIPS_ARTIFACT="$CTB/forge-artifacts/MIPS.sol/MIPS.json"
PREIMAGE_ARTIFACT="$CTB/forge-artifacts/PreimageOracle.sol/PreimageOracle.json"

MIPS_BIN=$(cat $MIPS_ARTIFACT | jq -r '.bytecode.object')
PREIMAGE_DEPLOYED_BIN=$(cat $PREIMAGE_ARTIFACT | jq -r '.deployedBytecode.object')
PREIMAGE_BIN=$(cat $PREIMAGE_ARTIFACT | jq -r '.bytecode.object')

echo "Removing old bindings..."
rm $DIR/*.bin
echo "Old bindings removed."

echo -n "${MIPS_BIN:2}" > $DIR/mips_creation.bin
echo -n "${PREIMAGE_DEPLOYED_BIN:2}" >> $DIR/preimage_oracle_deployed.bin
echo -n "${PREIMAGE_BIN:2}" >> $DIR/preimage_creation.bin

echo "Bindings generated successfully."
2 changes: 1 addition & 1 deletion crates/fpvm/bindings/mips_creation.bin

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions crates/fpvm/bindings/preimage_creation.bin

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion crates/fpvm/bindings/preimage_oracle_deployed.bin

This file was deleted.

Binary file modified crates/fpvm/open_mips_tests/test/bin/oracle.bin
Binary file not shown.
4 changes: 0 additions & 4 deletions crates/fpvm/open_mips_tests/test/oracle.asm
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ $readloop:
addiu $t0, $t0, -1
bnez $t0, $readloop
nop
# reading the pre-image stream at EOF should have no effect
li $a1, 0x31000008
li $v0, 4003
syscall

# length at 0x31000000. We also check that the lower 32 bits are zero
lui $s1, 0x3100
Expand Down
2 changes: 1 addition & 1 deletion crates/fpvm/src/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub fn load_elf(raw: &[u8]) -> Result<State> {
let mut state = State {
pc: elf.ehdr.e_entry as u32,
next_pc: elf.ehdr.e_entry as u32 + 4,
heap: 0x20000000,
heap: 0x05000000,
..Default::default()
};

Expand Down
61 changes: 22 additions & 39 deletions crates/fpvm/src/test_utils/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub const PREIMAGE_ORACLE_ADDR: [u8; 20] = hex!("0000000000000000000000000000000
pub const MIPS_CREATION_CODE: &str = include_str!("../../bindings/mips_creation.bin");
/// The deployed EVM bytecode of the PreimageOracle contract.
pub const PREIMAGE_ORACLE_DEPLOYED_CODE: &str =
include_str!("../../bindings/preimage_oracle_deployed.bin");
include_str!("../../bindings/preimage_creation.bin");

/// A wrapper around a [revm] interpreter with an in-memory backend that has the MIPS & PreimageOracle
/// smart contracts deployed at deterministic addresses. This is used for differential testing the
Expand Down Expand Up @@ -62,10 +62,27 @@ impl<'a> MipsEVM<'a, CacheDB<EmptyDB>> {
);

// Deploy the PreimageOracle contract.
self.deploy_contract(
Address::from_slice(PREIMAGE_ORACLE_ADDR.as_slice()),
Bytes::from(hex::decode(PREIMAGE_ORACLE_DEPLOYED_CODE)?),
)?;
let preimage_creation_heap = hex::decode(PREIMAGE_ORACLE_DEPLOYED_CODE)?
.into_iter()
.chain([0u8; 64])
.collect::<Vec<_>>();
self.fill_tx_env(TransactTo::Create, preimage_creation_heap.into());
if let Ok(ResultAndState {
result:
revm::primitives::ExecutionResult::Success {
reason: _,
gas_used: _,
gas_refunded: _,
logs: _,
output: Output::Create(code, _),
},
state: _,
}) = self.inner.transact()
{
self.deploy_contract(Address::from_slice(PREIMAGE_ORACLE_ADDR.as_slice()), code)?;
} else {
anyhow::bail!("Failed to deploy PreimageOracle contract");
};

// Deploy the MIPS contract prior to deploying it manually. This contract has an immutable
// variable, so we let the creation code fill this in for us, and then deploy it to the
Expand Down Expand Up @@ -229,40 +246,6 @@ mod test {
path::PathBuf,
};

#[test]
fn sanity_evm_execution() {
const SAMPLE: [u8; 2180] = hex!("f8e0cb960000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000000e22306a30adb7e99858491484b0d6627fe00efea43ec78488033a797a499e22ad6000000000000000000000000000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000007000e000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5b4c11951957c6f8f642c4af61cd6b24640fec6dc7fc607ee8206a99e92410d3021ddb9a356815c3fac1026b6dec5df3124afbadb485c9ba5a3e3398a04b7ba85e58769b32a1beaf1ea27375a44095a0d1fb664ce2dd358e7fcbfb78c26a193440eb01ebfc9ed27500cd4dfc979272d1f0913cc9f66540d7e8005811109e1cf2d887c22bd8750d34016ac3c66b5ff102dacdd73f6b014e710b51e8022af9a1968ffd70157e48063fc33c97a050f7f640233bf646cc98d9524c6b92bcf3ab56f839867cc5f7f196b93bae1e27e6320742445d290f2263827498b54fec539f756afcefad4e508c098b9a7e1d8feb19955fb02ba9675585078710969d3440f5054e0f9dc3e7fe016e050eff260334f18a5d4fe391d82092319f5964f2e2eb7c1c3a5f8b13a49e282f609c317a833fb8d976d11517c571d1221a265d25af778ecf8923490c6ceeb450aecdc82e28293031d10c7d73bf85e57bf041a97360aa2c5d99cc1df82d9c4b87413eae2ef048f94b4d3554cea73d92b0f7af96e0271c691e2bb5c67add7c6caf302256adedf7ab114da0acfe870d449a3a489f781d659e8beccda7bce9f4e8618b6bd2f4132ce798cdc7a60e7e1460a7299e3c6342a579626d22733e50f526ec2fa19a22b31e8ed50f23cd1fdf94c9154ed3a7609a2f1ff981fe1d3b5c807b281e4683cc6d6315cf95b9ade8641defcb32372f1c126e398ef7a5a2dce0a8a7f68bb74560f8f71837c2c2ebbcbf7fffb42ae1896f13f7c7479a0b46a28b6f55540f89444f63de0378e3d121be09e06cc9ded1c20e65876d36aa0c65e9645644786b620e2dd2ad648ddfcbf4a7e5b1a3a4ecfe7f64667a3f0b7e2f4418588ed35a2458cffeb39b93d26f18d2ab13bdce6aee58e7b99359ec2dfd95a9c16dc00d6ef18b7933a6f8dc65ccb55667138776f7dea101070dc8796e3774df84f40ae0c8229d0d6069e5c8f39a7c299677a09d367fc7b05e3bc380ee652cdc72595f74c7b1043d0e1ffbab734648c838dfb0527d971b602bc216c9619ef0abf5ac974a1ed57f4050aa510dd9c74f508277b39d7973bb2dfccc5eeb0618db8cd74046ff337f0a7bf2c8e03e10f642c1886798d71806ab1e888d9e5ee87d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000");

let mut mips_evm = MipsEVM::new();
mips_evm.try_init().unwrap();

mips_evm.fill_tx_env(
TransactTo::Call(MIPS_ADDR.into()),
Bytes::from(SAMPLE.to_vec()),
);

let ResultAndState { result, state: _ } = mips_evm.inner.transact().unwrap();

assert!(result.is_success());
let ExecutionResult::Success {
reason: _,
gas_used: _,
gas_refunded: _,
logs: _,
output: Output::Call(output),
} = result
else {
panic!("Expected success, got {:?}", result);
};

assert_eq!(
output,
Bytes::from_static(&hex!(
"03720be420feea4ae4f803f0f630004f8bd2b0256171dd26043e48bf524da332"
))
);
}

#[test]
fn evm() {
let mut mips_evm = MipsEVM::new();
Expand Down
12 changes: 7 additions & 5 deletions crates/fpvm/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ impl Default for StepWitness {

sol! {
/// `PreimageOracle` loadLocalData function.
function loadLocalData(uint256,bytes32,uint256,uint256) external returns (bytes32);
function loadLocalData(uint256,bytes32,bytes32,uint256,uint256) external returns (bytes32);

/// `PreimageOracle` loadKeccak256PreimagePart function.
function loadKeccak256PreimagePart(uint256,bytes) external;

/// `MIPS` step function.
function step(bytes,bytes) external returns (bytes32);
function step(bytes,bytes,bytes32) external returns (bytes32);
}

impl StepWitness {
Expand Down Expand Up @@ -92,9 +92,10 @@ impl StepWitness {

let call = loadLocalDataCall {
_0: B256::from(preimage_key).into(),
_1: B256::from(tmp),
_2: U256::from(preimage_value.len() - 8),
_3: U256::from(self.preimage_offset?),
_1: B256::ZERO, // constant local context
_2: B256::from(tmp),
_3: U256::from(preimage_value.len() - 8),
_4: U256::from(self.preimage_offset?),
};

Some(call.abi_encode().into())
Expand All @@ -118,6 +119,7 @@ impl StepWitness {
let call = stepCall {
_0: self.state.to_vec().into(),
_1: self.mem_proof.to_vec().into(),
_2: B256::ZERO // constant local context
};

call.abi_encode().into()
Expand Down

0 comments on commit 7790645

Please sign in to comment.